Skip to content

Commit

Permalink
[ci] Run CI on merge commit instead of head commit (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahithiacn committed Dec 28, 2022
1 parent a164e5c commit c0155ab
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 28 deletions.
31 changes: 8 additions & 23 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:

jobs:
prepare:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
outputs:
changes-target-branch: ${{ steps.changes.outputs.changes-target-branch }}
changes-base-git-rev: ${{ steps.changes.outputs.changes-base-git-rev }}
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
pattern: 'docker/ci\|scripts/dev_setup.sh'

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

lint:
runs-on: ubuntu-20.04-xl
runs-on: ubuntu-latest
timeout-minutes: 30
needs: prepare
if: ${{ needs.prepare.outputs.any-changes-founds == 'true' }}
Expand All @@ -98,8 +96,6 @@ jobs:
- "${{github.workspace}}:/opt/git/diem"
steps:
- uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/build-setup
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
with:
Expand All @@ -118,7 +114,7 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN}}

unit-test:
runs-on: ubuntu-20.04-xl
runs-on: ubuntu-latest
timeout-minutes: 60
needs: prepare
if: ${{ needs.prepare.outputs.test-rust == 'true' }}
Expand All @@ -128,9 +124,6 @@ jobs:
- "${{github.workspace}}:/opt/git/diem"
steps:
- uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 #get all the history!!!
- uses: ./.github/actions/build-setup
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
with:
Expand Down Expand Up @@ -163,7 +156,7 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN}}

hardhat-tests:
runs-on: ubuntu-20.04-xl
runs-on: ubuntu-latest
timeout-minutes: 20
needs: prepare
if: ${{ needs.prepare.outputs.test-rust == 'true' }}
Expand All @@ -173,8 +166,6 @@ jobs:
- "${{github.workspace}}:/opt/git/diem"
steps:
- uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/build-setup
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
- name: compile and install move-cli
Expand Down Expand Up @@ -202,7 +193,7 @@ jobs:

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

perf-benchmarks:
name: run-perf-benchmarks
runs-on: ubuntu-20.04-xl
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- prepare
Expand All @@ -240,8 +229,6 @@ jobs:
CRITERION_HOME: /tmp/benches
steps:
- uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/cache@v2.1.6
with:
path: "/opt/cargo/git\n/opt/cargo/registry\n/opt/cargo/.package-cache"
Expand Down Expand Up @@ -271,13 +258,11 @@ jobs:

build-move-analyzer-vscode-extension:
name: Build VS Code extension for move-analyzer
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs:
- prepare
steps:
- uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Use Node.js 14
uses: actions/setup-node@v2.4.0
with:
Expand Down
29 changes: 24 additions & 5 deletions devtools/x/src/lint/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@

use x_lint::prelude::*;

static LICENSE_HEADER: &str = "Copyright (c) The Diem Core Contributors\n\
SPDX-License-Identifier: Apache-2.0\n\
";
static ALLOWED_LICENSE_HEADERS: &[&str] = &[
"Copyright (c) The Move Contributors\n\
SPDX-License-Identifier: Apache-2.0\n\
",
"Copyright (c) The Diem Core Contributors\n\
SPDX-License-Identifier: Apache-2.0\n\
",
"Copyright (c) The Move Contributors\n\
Copyright (c) The Diem Core Contributors\n\
SPDX-License-Identifier: Apache-2.0\n\
",
];

fn has_license<'a>(maybe_license: impl Iterator<Item = &'a str>) -> bool {
let maybe = maybe_license.collect::<Vec<_>>();
for allowed in ALLOWED_LICENSE_HEADERS {
if allowed.lines().eq(maybe.clone().into_iter()) {
return true;
}
}
false
}

#[derive(Copy, Clone, Debug)]
pub(super) struct LicenseHeader;
Expand Down Expand Up @@ -50,7 +69,7 @@ impl ContentLinter for LicenseHeader {
.skip_while(|line| line.is_empty())
.take(2)
.map(|s| s.trim_start_matches("// "));
!LICENSE_HEADER.lines().eq(maybe_license)
!has_license(maybe_license)
}
FileType::Shell => {
let maybe_license = content
Expand All @@ -59,7 +78,7 @@ impl ContentLinter for LicenseHeader {
.skip_while(|line| line.is_empty())
.take(2)
.map(|s| s.trim_start_matches("# "));
!LICENSE_HEADER.lines().eq(maybe_license)
!has_license(maybe_license)
}
};

Expand Down
125 changes: 125 additions & 0 deletions scripts/check_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash
# Copyright (c) The Move Contributors
# SPDX-License-Identifier: Apache-2.0
#
# A script to check whether a local commit is ready for a PR.
# This simulates CI checks locally

set -e

BUILD_FLAGS=

BASE=$(git rev-parse --show-toplevel)
echo "*************** [check-pr] Assuming move root at $BASE"

# Run only tests which would also be run on CI
export ENV_TEST_ON_CI=1

while getopts "htcgdea" opt; do
case $opt in
h)
cat <<EOF
Performs CI equivalent checks on a local client
Usage:
check_pr <flags>
Flags:
-h Print this help
-t Run tests
-c Run xclippy, xlint, and xfmt
-g Run the Move git checks script (whitespace check). This works
only for committed clients.
-d Run documentation generation, abi generation, etc. for move-stdlib
and other Move libraries.
-e Run hardhat EVM tests
-a All of the above
With no options script behaves like -tcg is given.
If you want to run tests in release mode, call this script as 'BUILD_FLAGS=-release <script>'.
EOF
exit 1
;;
t)
TEST=1
;;
c)
CHECK=1
;;
d)
GEN_ARTIFACTS=1
;;
g)
GIT_CHECKS=1
;;
e)
HARDHAT_CHECKS=1
;;
a)
TEST=1
CHECK=1
GEN_ARTIFACTS=1
GIT_CHECKS=1
HARDHAT_CHECKS=1
esac
done

if [ "$OPTIND" -eq 1 ]; then
TEST=1
CHECK=1
GIT_CHECKS=1
fi

ARTIFACT_CRATES="\
$BASE/language/move-stdlib\
"

if [ ! -z "$TEST" ]; then
echo "*************** [check-pr] Running tests"
(
cd $BASE
cargo test --workspace $BUILD_FLAGS
)
fi

if [ ! -z "$CHECK" ]; then
echo "*************** [check-pr] Running checks"
(
cd $BASE
cargo xlint
cargo xclippy --workspace --all-targets
cargo xfmt
)
fi

if [ ! -z "$GEN_ARTIFACTS" ]; then
for dir in $ARTIFACT_CRATES; do
echo "*************** [check-pr] Generating artifacts for crate $dir"
(
cd $dir
cargo run $BUILD_FLAGS
)
done
fi

if [ ! -z "$GIT_CHECKS" ]; then
echo "*************** [check-pr] Running git checks"
$BASE/scripts/git-checks.sh
fi

if [ ! -z "$HARDHAT_CHECKS" ]; then
echo "*************** [check-pr] Running hardhat tests (expecting hardhat configured)"
# (
# cd $BASE/language/tools/move-cli
# cargo install --path .
# )
# (
# cd $BASE/language/evm/hardhat-move
# npm install
# npm run build
# )
(
cd $BASE/language/evm/hardhat-examples
# ./setup.sh
npx hardhat test
)
fi

0 comments on commit c0155ab

Please sign in to comment.