From 39ece5fa27bc8bf1cdbd002968467d4807c868fe Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 17:13:32 +0100 Subject: [PATCH 1/7] move lib.sh to common dir --- scripts/{gitlab => common}/lib.sh | 0 scripts/gitlab/check_labels.sh | 4 ++-- 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 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) rename scripts/{gitlab => common}/lib.sh (100%) diff --git a/scripts/gitlab/lib.sh b/scripts/common/lib.sh similarity index 100% rename from scripts/gitlab/lib.sh rename to scripts/common/lib.sh diff --git a/scripts/gitlab/check_labels.sh b/scripts/gitlab/check_labels.sh index c70599912ce4..60299424574e 100755 --- a/scripts/gitlab/check_labels.sh +++ b/scripts/gitlab/check_labels.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" repo='paritytech/polkadot' 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 From c7be3c23ad3f341db2b90244981d3ccc67a4732a Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 17:29:21 +0100 Subject: [PATCH 2/7] make check-labels a github action --- .github/workflows/check-labels.yml | 14 ++++++++++++++ scripts/common/lib.sh | 12 +++++++++--- scripts/{gitlab => github}/check_labels.sh | 5 +++-- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/check-labels.yml rename scripts/{gitlab => github}/check_labels.sh (93%) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml new file mode 100644 index 000000000000..e0b5a2d9622b --- /dev/null +++ b/.github/workflows/check-labels.yml @@ -0,0 +1,14 @@ +name: Check labels + +on: + pull_request: + types: [opened, synchronize] + +jobs: + check-labels: + runs-on: ubuntu-latest + steps: + - name: Check labels + run: bash scripts/github/check_labels.sh + env: + GITHUB_PR: ${{ github.event.pull_request.number }} diff --git a/scripts/common/lib.sh b/scripts/common/lib.sh index 993cab35e340..57783e08a319 100755 --- a/scripts/common/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_ACCESS_TOKEN="$GITHUB_RELEASE_TOKEN" + elif [ -n "$GITHUB_PR_TOKEN" ]; then + GITHUB_ACCESS_TOKEN="$GITHUB_PR_TOKEN" fi + + out=$(curl -H "Authorization: token $GITHUB_ACCESS_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 93% rename from scripts/gitlab/check_labels.sh rename to scripts/github/check_labels.sh index 60299424574e..880253cfa160 100755 --- a/scripts/gitlab/check_labels.sh +++ b/scripts/github/check_labels.sh @@ -3,11 +3,12 @@ #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 From 69b11aca6bb4975fe782f0f5b6d8596570149db7 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 17:32:19 +0100 Subject: [PATCH 3/7] check out the repo --- .github/workflows/check-labels.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index e0b5a2d9622b..0fda81ae74ed 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -8,7 +8,8 @@ jobs: check-labels: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - name: Check labels - run: bash scripts/github/check_labels.sh + run: bash ${{ github.workspace }}/scripts/github/check_labels.sh env: GITHUB_PR: ${{ github.event.pull_request.number }} From 0510ac9b1b8fe2475c33b802e3fb5df80565e470 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 17:37:05 +0100 Subject: [PATCH 4/7] fix secrets --- .github/workflows/check-labels.yml | 1 + scripts/common/lib.sh | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 0fda81ae74ed..7cf4f4745f88 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -13,3 +13,4 @@ jobs: 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/scripts/common/lib.sh b/scripts/common/lib.sh index 57783e08a319..2e40fffe2c84 100755 --- a/scripts/common/lib.sh +++ b/scripts/common/lib.sh @@ -56,12 +56,12 @@ has_label(){ # If the function's called in Github, we should have GITHUB_ACCESS_TOKEN set # already. if [ -n "$GITHUB_RELEASE_TOKEN" ]; then - GITHUB_ACCESS_TOKEN="$GITHUB_RELEASE_TOKEN" + GITHUB_TOKEN="$GITHUB_RELEASE_TOKEN" elif [ -n "$GITHUB_PR_TOKEN" ]; then - GITHUB_ACCESS_TOKEN="$GITHUB_PR_TOKEN" + GITHUB_TOKEN="$GITHUB_PR_TOKEN" fi - out=$(curl -H "Authorization: token $GITHUB_ACCESS_TOKEN" -s "$api_base/$repo/pulls/$pr_id") + 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\")")" ] } From 5c660e4fa3fd7241abcebb4278fdf6f7ec5d0c17 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 17:39:15 +0100 Subject: [PATCH 5/7] add labelled PR type --- .github/workflows/check-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 7cf4f4745f88..4c037089272d 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -2,7 +2,7 @@ name: Check labels on: pull_request: - types: [opened, synchronize] + types: [opened, synchronize, labeled] jobs: check-labels: From 33ed0a7e9aa2f973c9c5c6e01a9a3a8cec822465 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 18:03:57 +0100 Subject: [PATCH 6/7] remove check-labels job from gitlab --- .gitlab-ci.yml | 10 ---------- 1 file changed, 10 deletions(-) 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 From 035fae696426fc2d8d420b82ee8990cbf0a78838 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Wed, 10 Feb 2021 18:34:04 +0100 Subject: [PATCH 7/7] trigger on unlabelling also --- .github/workflows/check-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 4c037089272d..f52b79836276 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -2,7 +2,7 @@ name: Check labels on: pull_request: - types: [opened, synchronize, labeled] + types: [labeled, opened, synchronize, unlabeled] jobs: check-labels: