From 00ca30243f3f4b9030dedc7b7c2a14a1959eb5af Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 18:50:49 +0100 Subject: [PATCH] [CI] Move check_labels to github actions (#2415) * move lib.sh to common dir * make check-labels a github action * check out the repo * fix secrets * add labelled PR type * remove check-labels job from gitlab * trigger on unlabelling also --- .github/workflows/check-labels.yml | 16 ++++++++++++++++ .gitlab-ci.yml | 10 ---------- scripts/{gitlab => common}/lib.sh | 12 +++++++++--- scripts/{gitlab => github}/check_labels.sh | 9 +++++---- scripts/gitlab/check_runtime.sh | 4 ++-- scripts/gitlab/check_runtime_benchmarks.sh | 4 ++-- scripts/gitlab/check_web_wasm.sh | 4 ++-- scripts/gitlab/test_deterministic_wasm.sh | 4 ++-- scripts/gitlab/test_linux_stable.sh | 4 ++-- 9 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/check-labels.yml rename scripts/{gitlab => common}/lib.sh (91%) rename scripts/{gitlab => github}/check_labels.sh (89%) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml new file mode 100644 index 000000000000..f52b79836276 --- /dev/null +++ b/.github/workflows/check-labels.yml @@ -0,0 +1,16 @@ +name: Check labels + +on: + pull_request: + types: [labeled, opened, synchronize, unlabeled] + +jobs: + check-labels: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Check labels + run: bash ${{ github.workspace }}/scripts/github/check_labels.sh + env: + GITHUB_PR: ${{ github.event.pull_request.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 08d7fdd50049..af3e3811a4ed 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -328,13 +328,3 @@ deploy-polkasync-kusama: POLKADOT_CI_COMMIT_REF: "${CI_COMMIT_REF}" allow_failure: true trigger: "parity/infrastructure/parity-testnet" - -#### stage: .post - -check-labels: - stage: .post - image: paritytech/tools:latest - <<: *rules-pr-only - <<: *kubernetes-env - script: - - ./scripts/gitlab/check_labels.sh diff --git a/scripts/gitlab/lib.sh b/scripts/common/lib.sh similarity index 91% rename from scripts/gitlab/lib.sh rename to scripts/common/lib.sh index 993cab35e340..2e40fffe2c84 100755 --- a/scripts/gitlab/lib.sh +++ b/scripts/common/lib.sh @@ -51,11 +51,17 @@ has_label(){ repo="$1" pr_id="$2" label="$3" + + # These will exist if the function is called in Gitlab. + # If the function's called in Github, we should have GITHUB_ACCESS_TOKEN set + # already. if [ -n "$GITHUB_RELEASE_TOKEN" ]; then - out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/pulls/$pr_id") - else - out=$(curl -H "Authorization: token $GITHUB_PR_TOKEN" -s "$api_base/$repo/pulls/$pr_id") + GITHUB_TOKEN="$GITHUB_RELEASE_TOKEN" + elif [ -n "$GITHUB_PR_TOKEN" ]; then + GITHUB_TOKEN="$GITHUB_PR_TOKEN" fi + + out=$(curl -H "Authorization: token $GITHUB_TOKEN" -s "$api_base/$repo/pulls/$pr_id") [ -n "$(echo "$out" | tr -d '\r\n' | jq ".labels | .[] | select(.name==\"$label\")")" ] } diff --git a/scripts/gitlab/check_labels.sh b/scripts/github/check_labels.sh similarity index 89% rename from scripts/gitlab/check_labels.sh rename to scripts/github/check_labels.sh index c70599912ce4..880253cfa160 100755 --- a/scripts/gitlab/check_labels.sh +++ b/scripts/github/check_labels.sh @@ -1,13 +1,14 @@ #!/usr/bin/env bash -#shellcheck source=lib.sh -source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" +#shellcheck source=../common/lib.sh +source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" -repo='paritytech/polkadot' +repo="$GITHUB_REPOSITORY" +pr="$GITHUB_PR" ensure_labels() { for label in "$@"; do - if has_label "$repo" "$CI_COMMIT_BRANCH" "$label"; then + if has_label "$repo" "$pr" "$label"; then return 0 fi done diff --git a/scripts/gitlab/check_runtime.sh b/scripts/gitlab/check_runtime.sh index 21dfc74be923..520b7c1c026a 100755 --- a/scripts/gitlab/check_runtime.sh +++ b/scripts/gitlab/check_runtime.sh @@ -16,8 +16,8 @@ set -e # fail on any error #Include the common functions library -#shellcheck source=lib.sh -. "$(dirname "${0}")/lib.sh" +#shellcheck source=../common/lib.sh +. "$(dirname "${0}")/../common/lib.sh" SUBSTRATE_REPO="https://github.com/paritytech/substrate" SUBSTRATE_REPO_CARGO="git\+${SUBSTRATE_REPO}" diff --git a/scripts/gitlab/check_runtime_benchmarks.sh b/scripts/gitlab/check_runtime_benchmarks.sh index d215106ef25d..9e6a26d2a4ef 100755 --- a/scripts/gitlab/check_runtime_benchmarks.sh +++ b/scripts/gitlab/check_runtime_benchmarks.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -#shellcheck source=lib.sh -source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" +#shellcheck source=../common/lib.sh +source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" time cargo check --features runtime-benchmarks diff --git a/scripts/gitlab/check_web_wasm.sh b/scripts/gitlab/check_web_wasm.sh index 0b9494713875..a79bbc063a97 100755 --- a/scripts/gitlab/check_web_wasm.sh +++ b/scripts/gitlab/check_web_wasm.sh @@ -2,7 +2,7 @@ set -e -#shellcheck source=lib.sh -source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" +#shellcheck source=../common/lib.sh +source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" time cargo build --locked --target=wasm32-unknown-unknown --manifest-path cli/Cargo.toml --no-default-features --features browser diff --git a/scripts/gitlab/test_deterministic_wasm.sh b/scripts/gitlab/test_deterministic_wasm.sh index 998d924d4563..b42923769421 100755 --- a/scripts/gitlab/test_deterministic_wasm.sh +++ b/scripts/gitlab/test_deterministic_wasm.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -#shellcheck source=lib.sh -source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" +#shellcheck source=../common/lib.sh +source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" # build runtime WASM_BUILD_NO_COLOR=1 cargo build --verbose --release -p kusama-runtime -p polkadot-runtime -p westend-runtime diff --git a/scripts/gitlab/test_linux_stable.sh b/scripts/gitlab/test_linux_stable.sh index b841d8abecf4..05e20226765e 100755 --- a/scripts/gitlab/test_linux_stable.sh +++ b/scripts/gitlab/test_linux_stable.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -e -#shellcheck source=lib.sh -source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" +#shellcheck source=../common/lib.sh +source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" time cargo test --all --release --verbose --locked --features=runtime-benchmarks --features=real-overseer