Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/polkadot-companion-labels.yml

This file was deleted.

65 changes: 52 additions & 13 deletions .maintain/common/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ last_github_release(){
i=0
# Iterate over releases until we find the last release that's not just a draft
while [ $i -lt 29 ]; do
out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$1/releases" | jq ".[$i]")
out=$(curl -H "Authorization: token $(github_token)" -s "$api_base/$1/releases" | jq ".[$i]")
echo "$out"
# Ugh when echoing to jq, we need to translate newlines into spaces :/
if [ "$(echo "$out" | tr '\r\n' ' ' | jq '.draft')" = "false" ]; then
Expand All @@ -41,13 +41,13 @@ last_github_release(){
check_tag () {
repo=$1
tagver=$2
tag_out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/git/refs/tags/$tagver")
tag_out=$(curl -H "Authorization: token $(github_token)" -s "$api_base/$repo/git/refs/tags/$tagver")
tag_sha=$(echo "$tag_out" | jq -r .object.sha)
object_url=$(echo "$tag_out" | jq -r .object.url)
if [ "$tag_sha" = "null" ]; then
return 2
fi
verified_str=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$object_url" | jq -r .verification.verified)
verified_str=$(curl -H "Authorization: token $(github_token)" -s "$object_url" | jq -r .verification.verified)
if [ "$verified_str" = "true" ]; then
# Verified, everything is good
return 0
Expand All @@ -67,16 +67,7 @@ has_label(){
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
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")
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\")")" ]
}

Expand Down Expand Up @@ -115,3 +106,51 @@ has_runtime_changes() {
return 1
fi
}

# Add a label to a PR in a given repo. Doesn't error if label already present
# repo: paritytech/substrate
# label: A7-needspolkadotpr
# PR: 1234
add_label() {
repo=$1
pr=$2
label=$3
curl -X POST \
--data "[\"$label\"]" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $(github_token)" \
-s "$api_base/$repo/issues/$pr/labels"
}

# Remove a label from a PR in a given repo. Doesn't error if label already absent
# repo: paritytech/substrate
# label: A7-needspolkadotpr
# PR: 1234
remove_label() {
repo=$1
pr=$2
# Escape the labels... we use emojis quite often, so this is required
# to not break things.
# Source below: (with od instead of xxd since it's in IEEE Std 1003.1-2008)
# https://stackoverflow.com/questions/12735450/delete-using-curl-with-encoded-url
label=$(printf '%s' "$3" | od -A n -w1000 -t x1 | tr -d ' ' | sed 's/\(..\)/%\1/g')

curl -X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $(github_token)" \
-s "$api_base/$repo/issues/$pr/labels/$label"
}

# Useful shim for getting the right GITHUB_TOKEN, depending on whether we're
# in Github or Gitlab CI
github_token() {
# These will exist if the function is called in Gitlab.
# If the function's called in Github, we should have GITHUB_ACCESS_TOKEN set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this token then be used by the curl calls? otherwise setting it from another else block would help.

# already.
if [ -n "$GITHUB_RELEASE_TOKEN" ]; then
GITHUB_TOKEN="$GITHUB_RELEASE_TOKEN"
elif [ -n "$GITHUB_PR_TOKEN" ]; then
GITHUB_TOKEN="$GITHUB_PR_TOKEN"
fi
printf '%s' "$GITHUB_TOKEN"
}
22 changes: 17 additions & 5 deletions .maintain/gitlab/check_polkadot_companion_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

set -e

#shellcheck source=../common/lib.sh
. "$(dirname "${0}")/../common/lib.sh"

github_api_substrate_pull_url="https://api.github.com/repos/paritytech/substrate/pulls"
# use github api v3 in order to access the data without authentication
github_header="Authorization: token ${GITHUB_PR_TOKEN}"

boldprint () { printf "|\n| \033[1m${@}\033[0m\n|\n" ; }
boldcat () { printf "|\n"; while read l; do printf "| \033[1m${l}\033[0m\n"; done; printf "|\n" ; }
boldprint () { printf "|\n| \033[1m%s\033[0m\n|\n" "{@}"; }
boldcat () { printf "|\n"; while read -r l; do printf "| \033[1m%s\033[0m\n" "${l}"; done; printf "|\n" ; }



Expand Down Expand Up @@ -55,6 +58,7 @@ cd polkadot

# either it's a pull request then check for a companion otherwise use
# polkadot:master
# shellcheck disable=2003
if expr match "${CI_COMMIT_REF_NAME}" '^[0-9]\+$' >/dev/null
then
boldprint "this is pull request no ${CI_COMMIT_REF_NAME}"
Expand All @@ -74,8 +78,8 @@ then
if [ "${pr_companion}" ]
then
boldprint "companion pr specified/detected: #${pr_companion}"
git fetch origin refs/pull/${pr_companion}/head:pr/${pr_companion}
git checkout pr/${pr_companion}
git fetch origin "refs/pull/${pr_companion}/head:pr/${pr_companion}"
git checkout "pr/${pr_companion}"
git merge origin/master
else
boldprint "no companion branch found - building polkadot:master"
Expand All @@ -89,4 +93,12 @@ fi
diener patch --crates-to-patch ../ --substrate --path Cargo.toml

# Test Polkadot pr or master branch with this Substrate commit.
time cargo test --all --release --verbose
# If it fails, it requires a companion PR. Label thusly. Otherwise remove the
# label. These operations are idempotent.
if time cargo test --all --release --verbose ; then
remove_label 'paritytech/substrate' "${CI_COMMIT_REF_NAME}" 'A7-needspolkadotpr'
exit 0
else
add_label 'paritytech/substrate' "${CI_COMMIT_REF_NAME}" 'A7-needspolkadotpr'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about the error handling here if this is running from a pr? i used to use a helper job for this like here: https://gitlab.parity.io/parity/infrastructure/github-api/-/blob/master/.gitlab-ci.yml

exit 1
fi