Skip to content

Commit c0155ab

Browse files
committed
[ci] Run CI on merge commit instead of head commit (#22)
1 parent a164e5c commit c0155ab

3 files changed

Lines changed: 157 additions & 28 deletions

File tree

.github/workflows/ci-test.yml

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616

1717
jobs:
1818
prepare:
19-
runs-on: ubuntu-20.04
19+
runs-on: ubuntu-latest
2020
outputs:
2121
changes-target-branch: ${{ steps.changes.outputs.changes-target-branch }}
2222
changes-base-git-rev: ${{ steps.changes.outputs.changes-base-git-rev }}
@@ -67,7 +67,7 @@ jobs:
6767
pattern: 'docker/ci\|scripts/dev_setup.sh'
6868

6969
dev-setup-sh-test:
70-
runs-on: ubuntu-20.04-xl
70+
runs-on: ubuntu-latest
7171
timeout-minutes: 30
7272
needs: prepare
7373
if: ${{ needs.prepare.outputs.test-dev-setup == 'true' }}
@@ -77,8 +77,6 @@ jobs:
7777
target_os: [github]
7878
steps:
7979
- uses: actions/checkout@v2.4.0
80-
with:
81-
ref: ${{ github.event.pull_request.head.sha }}
8280
- name: build image with dev-setup.sh
8381
run: docker build -f docker/ci/${{ matrix.target_os }}/Dockerfile -t diem/build_environment:test .
8482
- name: Early terminate workflow
@@ -88,7 +86,7 @@ jobs:
8886
github-token: ${{secrets.GITHUB_TOKEN}}
8987

9088
lint:
91-
runs-on: ubuntu-20.04-xl
89+
runs-on: ubuntu-latest
9290
timeout-minutes: 30
9391
needs: prepare
9492
if: ${{ needs.prepare.outputs.any-changes-founds == 'true' }}
@@ -98,8 +96,6 @@ jobs:
9896
- "${{github.workspace}}:/opt/git/diem"
9997
steps:
10098
- uses: actions/checkout@v2.4.0
101-
with:
102-
ref: ${{ github.event.pull_request.head.sha }}
10399
- uses: ./.github/actions/build-setup
104100
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
105101
with:
@@ -118,7 +114,7 @@ jobs:
118114
github-token: ${{secrets.GITHUB_TOKEN}}
119115

120116
unit-test:
121-
runs-on: ubuntu-20.04-xl
117+
runs-on: ubuntu-latest
122118
timeout-minutes: 60
123119
needs: prepare
124120
if: ${{ needs.prepare.outputs.test-rust == 'true' }}
@@ -128,9 +124,6 @@ jobs:
128124
- "${{github.workspace}}:/opt/git/diem"
129125
steps:
130126
- uses: actions/checkout@v2.4.0
131-
with:
132-
ref: ${{ github.event.pull_request.head.sha }}
133-
fetch-depth: 0 #get all the history!!!
134127
- uses: ./.github/actions/build-setup
135128
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
136129
with:
@@ -163,7 +156,7 @@ jobs:
163156
github-token: ${{secrets.GITHUB_TOKEN}}
164157

165158
hardhat-tests:
166-
runs-on: ubuntu-20.04-xl
159+
runs-on: ubuntu-latest
167160
timeout-minutes: 20
168161
needs: prepare
169162
if: ${{ needs.prepare.outputs.test-rust == 'true' }}
@@ -173,8 +166,6 @@ jobs:
173166
- "${{github.workspace}}:/opt/git/diem"
174167
steps:
175168
- uses: actions/checkout@v2.4.0
176-
with:
177-
ref: ${{ github.event.pull_request.head.sha }}
178169
- uses: ./.github/actions/build-setup
179170
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
180171
- name: compile and install move-cli
@@ -202,7 +193,7 @@ jobs:
202193

203194
# Compile (but don't run) the benchmarks, to insulate against bit rot
204195
build-benchmarks:
205-
runs-on: ubuntu-20.04-xl
196+
runs-on: ubuntu-latest
206197
timeout-minutes: 30
207198
needs: prepare
208199
if: ${{ needs.prepare.outputs.test-rust == 'true' }}
@@ -212,8 +203,6 @@ jobs:
212203
- "${{github.workspace}}:/opt/git/diem"
213204
steps:
214205
- uses: actions/checkout@v2.4.0
215-
with:
216-
ref: ${{ github.event.pull_request.head.sha }}
217206
- uses: ./.github/actions/build-setup
218207
- uses: actions/cache@v2.1.6
219208
with:
@@ -231,7 +220,7 @@ jobs:
231220

232221
perf-benchmarks:
233222
name: run-perf-benchmarks
234-
runs-on: ubuntu-20.04-xl
223+
runs-on: ubuntu-latest
235224
timeout-minutes: 30
236225
needs:
237226
- prepare
@@ -240,8 +229,6 @@ jobs:
240229
CRITERION_HOME: /tmp/benches
241230
steps:
242231
- uses: actions/checkout@v2.4.0
243-
with:
244-
ref: ${{ github.event.pull_request.head.sha }}
245232
- uses: actions/cache@v2.1.6
246233
with:
247234
path: "/opt/cargo/git\n/opt/cargo/registry\n/opt/cargo/.package-cache"
@@ -271,13 +258,11 @@ jobs:
271258

272259
build-move-analyzer-vscode-extension:
273260
name: Build VS Code extension for move-analyzer
274-
runs-on: ubuntu-20.04
261+
runs-on: ubuntu-latest
275262
needs:
276263
- prepare
277264
steps:
278265
- uses: actions/checkout@v2.4.0
279-
with:
280-
ref: ${{ github.event.pull_request.head.sha }}
281266
- name: Use Node.js 14
282267
uses: actions/setup-node@v2.4.0
283268
with:

devtools/x/src/lint/license.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@
33

44
use x_lint::prelude::*;
55

6-
static LICENSE_HEADER: &str = "Copyright (c) The Diem Core Contributors\n\
7-
SPDX-License-Identifier: Apache-2.0\n\
8-
";
6+
static ALLOWED_LICENSE_HEADERS: &[&str] = &[
7+
"Copyright (c) The Move Contributors\n\
8+
SPDX-License-Identifier: Apache-2.0\n\
9+
",
10+
"Copyright (c) The Diem Core Contributors\n\
11+
SPDX-License-Identifier: Apache-2.0\n\
12+
",
13+
"Copyright (c) The Move Contributors\n\
14+
Copyright (c) The Diem Core Contributors\n\
15+
SPDX-License-Identifier: Apache-2.0\n\
16+
",
17+
];
18+
19+
fn has_license<'a>(maybe_license: impl Iterator<Item = &'a str>) -> bool {
20+
let maybe = maybe_license.collect::<Vec<_>>();
21+
for allowed in ALLOWED_LICENSE_HEADERS {
22+
if allowed.lines().eq(maybe.clone().into_iter()) {
23+
return true;
24+
}
25+
}
26+
false
27+
}
928

1029
#[derive(Copy, Clone, Debug)]
1130
pub(super) struct LicenseHeader;
@@ -50,7 +69,7 @@ impl ContentLinter for LicenseHeader {
5069
.skip_while(|line| line.is_empty())
5170
.take(2)
5271
.map(|s| s.trim_start_matches("// "));
53-
!LICENSE_HEADER.lines().eq(maybe_license)
72+
!has_license(maybe_license)
5473
}
5574
FileType::Shell => {
5675
let maybe_license = content
@@ -59,7 +78,7 @@ impl ContentLinter for LicenseHeader {
5978
.skip_while(|line| line.is_empty())
6079
.take(2)
6180
.map(|s| s.trim_start_matches("# "));
62-
!LICENSE_HEADER.lines().eq(maybe_license)
81+
!has_license(maybe_license)
6382
}
6483
};
6584

scripts/check_pr.sh

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
# Copyright (c) The Move Contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# A script to check whether a local commit is ready for a PR.
6+
# This simulates CI checks locally
7+
8+
set -e
9+
10+
BUILD_FLAGS=
11+
12+
BASE=$(git rev-parse --show-toplevel)
13+
echo "*************** [check-pr] Assuming move root at $BASE"
14+
15+
# Run only tests which would also be run on CI
16+
export ENV_TEST_ON_CI=1
17+
18+
while getopts "htcgdea" opt; do
19+
case $opt in
20+
h)
21+
cat <<EOF
22+
Performs CI equivalent checks on a local client
23+
Usage:
24+
check_pr <flags>
25+
Flags:
26+
-h Print this help
27+
-t Run tests
28+
-c Run xclippy, xlint, and xfmt
29+
-g Run the Move git checks script (whitespace check). This works
30+
only for committed clients.
31+
-d Run documentation generation, abi generation, etc. for move-stdlib
32+
and other Move libraries.
33+
-e Run hardhat EVM tests
34+
-a All of the above
35+
With no options script behaves like -tcg is given.
36+
If you want to run tests in release mode, call this script as 'BUILD_FLAGS=-release <script>'.
37+
38+
39+
EOF
40+
exit 1
41+
;;
42+
t)
43+
TEST=1
44+
;;
45+
c)
46+
CHECK=1
47+
;;
48+
d)
49+
GEN_ARTIFACTS=1
50+
;;
51+
g)
52+
GIT_CHECKS=1
53+
;;
54+
e)
55+
HARDHAT_CHECKS=1
56+
;;
57+
a)
58+
TEST=1
59+
CHECK=1
60+
GEN_ARTIFACTS=1
61+
GIT_CHECKS=1
62+
HARDHAT_CHECKS=1
63+
esac
64+
done
65+
66+
if [ "$OPTIND" -eq 1 ]; then
67+
TEST=1
68+
CHECK=1
69+
GIT_CHECKS=1
70+
fi
71+
72+
ARTIFACT_CRATES="\
73+
$BASE/language/move-stdlib\
74+
"
75+
76+
if [ ! -z "$TEST" ]; then
77+
echo "*************** [check-pr] Running tests"
78+
(
79+
cd $BASE
80+
cargo test --workspace $BUILD_FLAGS
81+
)
82+
fi
83+
84+
if [ ! -z "$CHECK" ]; then
85+
echo "*************** [check-pr] Running checks"
86+
(
87+
cd $BASE
88+
cargo xlint
89+
cargo xclippy --workspace --all-targets
90+
cargo xfmt
91+
)
92+
fi
93+
94+
if [ ! -z "$GEN_ARTIFACTS" ]; then
95+
for dir in $ARTIFACT_CRATES; do
96+
echo "*************** [check-pr] Generating artifacts for crate $dir"
97+
(
98+
cd $dir
99+
cargo run $BUILD_FLAGS
100+
)
101+
done
102+
fi
103+
104+
if [ ! -z "$GIT_CHECKS" ]; then
105+
echo "*************** [check-pr] Running git checks"
106+
$BASE/scripts/git-checks.sh
107+
fi
108+
109+
if [ ! -z "$HARDHAT_CHECKS" ]; then
110+
echo "*************** [check-pr] Running hardhat tests (expecting hardhat configured)"
111+
# (
112+
# cd $BASE/language/tools/move-cli
113+
# cargo install --path .
114+
# )
115+
# (
116+
# cd $BASE/language/evm/hardhat-move
117+
# npm install
118+
# npm run build
119+
# )
120+
(
121+
cd $BASE/language/evm/hardhat-examples
122+
# ./setup.sh
123+
npx hardhat test
124+
)
125+
fi

0 commit comments

Comments
 (0)