[CI] add check_tags CI job (#1072)

* add check_tags CI job

* fix typo in gitlab-ci.yml

* add more useful CI output

* Make presence of github token optional
This commit is contained in:
s3krit
2020-05-08 17:31:23 +02:00
committed by GitHub
parent a62382269d
commit b2655b5220
3 changed files with 42 additions and 2 deletions
+9
View File
@@ -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
+23
View File
@@ -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
+10 -2
View File
@@ -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\")")" ]
}