diff --git a/polkadot/.gitlab-ci.yml b/polkadot/.gitlab-ci.yml index 2c7e1127e2..c1f760130b 100644 --- a/polkadot/.gitlab-ci.yml +++ b/polkadot/.gitlab-ci.yml @@ -73,7 +73,16 @@ variables: - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - /^[0-9]+$/ +#### stage: .pre +check-labels: + stage: .pre + image: parity/tools:latest + <<: *kubernetes-env + only: + - /^[0-9]+$/ + script: + - ./scripts/gitlab/check_tags.sh #### stage: test diff --git a/polkadot/scripts/gitlab/check_tags.sh b/polkadot/scripts/gitlab/check_tags.sh new file mode 100755 index 0000000000..f8f3df941f --- /dev/null +++ b/polkadot/scripts/gitlab/check_tags.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +#shellcheck source=lib.sh +source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" + +# Must have one of the following labels +labels=( + 'B1-releasenotes' + 'B1-runtimeworthy' + 'B1-silent' +) + +echo "[+] Checking labels for $CI_COMMIT_BRANCH" + +for label in "${labels[@]}"; do + if has_label 'paritytech/polkadot' "$CI_COMMIT_BRANCH" "$label"; then + echo "[+] Label $label detected, test passed" + exit 0 + fi +done + +echo "[!] PR does not have one of the required labels! Please add one of: ${labels[*]}" +exit 1 diff --git a/polkadot/scripts/gitlab/lib.sh b/polkadot/scripts/gitlab/lib.sh index 7fae82f189..3d7897a21b 100755 --- a/polkadot/scripts/gitlab/lib.sh +++ b/polkadot/scripts/gitlab/lib.sh @@ -21,7 +21,11 @@ sanitised_git_logs(){ check_tag () { repo=$1 tagver=$2 - tag_out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/git/refs/tags/$tagver") + if [ -n "$GITHUB_RELEASE_TOKEN" ]; then + tag_out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/git/refs/tags/$tagver") + else + tag_out=$(curl -s "$api_base/$repo/git/refs/tags/$tagver") + fi tag_sha=$(echo "$tag_out" | jq -r .object.sha) object_url=$(echo "$tag_out" | jq -r .object.url) if [ "$tag_sha" = "null" ]; then @@ -46,7 +50,11 @@ has_label(){ repo="$1" pr_id="$2" label="$3" - out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/pulls/$pr_id") + if [ -n "$GITHUB_RELEASE_TOKEN" ]; then + out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/pulls/$pr_id") + else + out=$(curl -s "$api_base/$repo/pulls/$pr_id") + fi [ -n "$(echo "$out" | tr -d '\r\n' | jq ".labels | .[] | select(.name==\"$label\")")" ] }