diff --git a/polkadot/.github/workflows/check-labels.yml b/polkadot/.github/workflows/check-labels.yml new file mode 100644 index 0000000000..f52b798362 --- /dev/null +++ b/polkadot/.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/polkadot/.gitlab-ci.yml b/polkadot/.gitlab-ci.yml index 08d7fdd500..af3e3811a4 100644 --- a/polkadot/.gitlab-ci.yml +++ b/polkadot/.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/polkadot/scripts/gitlab/lib.sh b/polkadot/scripts/common/lib.sh similarity index 91% rename from polkadot/scripts/gitlab/lib.sh rename to polkadot/scripts/common/lib.sh index 993cab35e3..2e40fffe2c 100755 --- a/polkadot/scripts/gitlab/lib.sh +++ b/polkadot/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/polkadot/scripts/gitlab/check_labels.sh b/polkadot/scripts/github/check_labels.sh similarity index 89% rename from polkadot/scripts/gitlab/check_labels.sh rename to polkadot/scripts/github/check_labels.sh index c70599912c..880253cfa1 100755 --- a/polkadot/scripts/gitlab/check_labels.sh +++ b/polkadot/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/polkadot/scripts/gitlab/check_runtime.sh b/polkadot/scripts/gitlab/check_runtime.sh index 21dfc74be9..520b7c1c02 100755 --- a/polkadot/scripts/gitlab/check_runtime.sh +++ b/polkadot/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/polkadot/scripts/gitlab/check_runtime_benchmarks.sh b/polkadot/scripts/gitlab/check_runtime_benchmarks.sh index d215106ef2..9e6a26d2a4 100755 --- a/polkadot/scripts/gitlab/check_runtime_benchmarks.sh +++ b/polkadot/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/polkadot/scripts/gitlab/check_web_wasm.sh b/polkadot/scripts/gitlab/check_web_wasm.sh index 0b94947138..a79bbc063a 100755 --- a/polkadot/scripts/gitlab/check_web_wasm.sh +++ b/polkadot/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/polkadot/scripts/gitlab/test_deterministic_wasm.sh b/polkadot/scripts/gitlab/test_deterministic_wasm.sh index 998d924d45..b429237694 100755 --- a/polkadot/scripts/gitlab/test_deterministic_wasm.sh +++ b/polkadot/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/polkadot/scripts/gitlab/test_linux_stable.sh b/polkadot/scripts/gitlab/test_linux_stable.sh index b841d8abec..05e2022676 100755 --- a/polkadot/scripts/gitlab/test_linux_stable.sh +++ b/polkadot/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