From b38b63378ecc66737bc4ac1a8e584bfd4b0653ea Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 1 Dec 2022 03:48:59 -0300 Subject: [PATCH 001/109] include publish-crates script --- publish-crates | 570 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 570 insertions(+) create mode 100755 publish-crates diff --git a/publish-crates b/publish-crates new file mode 100755 index 00000000..05085f72 --- /dev/null +++ b/publish-crates @@ -0,0 +1,570 @@ +#!/usr/bin/env bash + +## A script for publishing workspace crates to a target crates.io instance. +## This script requires: +## - A working PostgreSQL v13 database +## - Some environment variables to be set up in advance (see how the check-publish-crates job is set +## up on CI for reference) + +echo " +publish-crates +======================== + +This script publishes all workspace crates to the target crates.io instance of choice. It can either +publish them to a local crates.io instance (which is set up by this script) or the official +crates.io registry. +" + +set -Eeu -o pipefail +shopt -s inherit_errexit + +root="$PWD" +tmp="$root/.tmp" +cratesio_dir="$tmp/crates.io" +cargo_target_dir="$tmp/cargo" +yj="$tmp/yj" + +on_exit() { + local exit_code=$? + rm -rf "$tmp" + pkill -P "$$" || : + exit $exit_code +} +trap on_exit EXIT + +die() { + local exit_code=$? + + local kill_group + if [ "${2:-}" ]; then + case "$1" in + all) + kill_group="$(ps -o pgid= $$ | tr -d " ")" + ;; + "") ;; + *) + log "Invalid operation $1; ignoring" + ;; + esac + shift + fi + + if [ "${1:-}" ]; then + >&2 log "$1" + fi + + if [ "${kill_group:-}" ]; then + kill -- "-$kill_group" + else + pkill -P "$$" || : + fi + + if [ "$exit_code" -ne 0 ]; then + exit "$exit_code" + else + exit 1 + fi +} + +set -xv + +setup_local_cratesio() { + load_workspace_crates + + git clone --branch releng https://github.com/paritytech/crates.io "$cratesio_dir" + + >/dev/null pushd "$cratesio_dir" + + mkdir local_uploads tmp + + local cratesio_token_prefix="--$$--" + + diesel migration run --locked-schema + + script/init-local-index.sh + + local pipe="$tmp/pipe" + mkfifo "$pipe" + + export GIT_REPO_URL="file://$PWD/tmp/index-bare" + export GH_CLIENT_ID= + export GH_CLIENT_SECRET= + export WEB_ALLOWED_ORIGINS=http://localhost:8888,http://localhost:4200 + export SESSION_KEY=badkeyabcdefghijklmnopqrstuvwxyzabcdef + export CRATESIO_TOKEN_PREFIX="$cratesio_token_prefix" + export WEB_NEW_PKG_RATE_LIMIT_BURST=10248 + export CRATESIO_LOCAL_CRATES="${workspace_crates[*]}" + cargo run --quiet --bin server | while IFS= read -r line; do + case "$line" in + "$cratesio_token_prefix="*) + echo "${line:$(( ${#cratesio_token_prefix} + 1 ))}" > "$pipe" + ;; + *) + log "$line" + ;; + esac + done || die all "Crates.io server failed" & + + log "Waiting for token from crates.io server..." + local token + token="$(cat "$pipe")" + log "Got token from crates.io server: $token" + + local crate_committed_msg_prefix="Commit and push finished for \"Updating crate \`" + export SPUB_CRATES_COMMITTED_FILE="$tmp/crates-committed" + touch "$SPUB_CRATES_COMMITTED_FILE" + + # need set TMPDIR to disk because crates.io index is too big for tmpfs on RAM + local old_tmpdir="${TMPDIR:-}" + mkdir -p tmp/worker-tmp + export TMPDIR="$PWD/tmp/worker-tmp" + cargo run --quiet --bin background-worker | while IFS= read -r line; do + log "$line" + case "$line" in + "Runner booted, running jobs") + echo "$line" > "$pipe" + ;; + # example line: Commit and push finished for "Updating crate `foo#0.1.0`" + "$crate_committed_msg_prefix"*) + line_remainder="${line:${#crate_committed_msg_prefix}}" + if [[ "$line_remainder" =~ ^([^#]+)# ]]; then + echo "${BASH_REMATCH[1]}" >> "$SPUB_CRATES_COMMITTED_FILE" + else + die all "background-worker line had unexpected format: $line" + fi + ;; + esac + done || die all "Crates.io background-worker failed" & + if [ "$old_tmpdir" ]; then + export TMPDIR="$old_tmpdir" + else + unset TMPDIR + export -n TMPDIR + fi + unset old_tmpdir + + log "Waiting for the workers to be ready..." + read -r < "$pipe" + log "Workers are ready" + + >/dev/null popd + + export SPUB_REGISTRY=local + export SPUB_CRATES_API=http://localhost:8888/api/v1 + export CARGO_REGISTRIES_LOCAL_INDEX=file://"$cratesio_dir"/tmp/index-bare + export SPUB_REGISTRY_TOKEN="$token" +} + +setup_subpub() { + local old_cargo_target_dir="${CARGO_TARGET_DIR:-}" + export CARGO_TARGET_DIR="$cargo_target_dir" + + cargo install --quiet --git https://github.com/paritytech/subpub --branch releng + subpub --version + + if [ "$old_cargo_target_dir" ]; then + export CARGO_TARGET_DIR="$old_cargo_target_dir" + else + unset CARGO_TARGET_DIR + export -n CARGO_TARGET_DIR + fi +} + +setup_diesel() { + local old_cargo_target_dir="${CARGO_TARGET_DIR:-}" + export CARGO_TARGET_DIR="$cargo_target_dir" + + cargo install --quiet diesel_cli \ + --version 1.4.1 \ + --no-default-features \ + --features postgres + diesel --version + + if [ "$old_cargo_target_dir" ]; then + export CARGO_TARGET_DIR="$old_cargo_target_dir" + else + unset CARGO_TARGET_DIR + export -n CARGO_TARGET_DIR + fi +} + +setup_postgres() { + apt install -qq --assume-yes --no-install-recommends postgresql-11 libpq-dev sudo + pg_ctlcluster 11 main start + + local db_user=pg + local db_password=pg + local db_name=crates_io + export DATABASE_URL="postgres://$db_user:$db_password@localhost:5432/$db_name" + + log "Attempting to connect to the database @ $DATABASE_URL" + local is_db_ready + for ((i=0; i < 8; i++)); do + if pg_isready -d "$DATABASE_URL"; then + is_db_ready=true + break + else + sleep 8 + fi + done + if [ ! "${is_db_ready:-}" ]; then + die "Timed out on database connection" + fi + + sudo -u postgres createuser -s -i -d -r -l -w "$db_user" + sudo -u postgres createdb --owner "$db_user" "$db_name" + sudo -u postgres psql -c "ALTER USER $db_user WITH ENCRYPTED PASSWORD '$db_password';" +} + +load_workspace_crates() { + if [ "${workspace_crates:-}" ]; then + return + fi + readarray -t workspace_crates < <( + cargo tree --quiet --workspace --depth 0 --manifest-path "$root/Cargo.toml" | + awk '{ if (length($1) == 0 || substr($1, 1, 1) == "[") { skip } else { print $1 } }' | + sort | + uniq + ) + log "workspace crates: ${workspace_crates[*]}" + if [ ${#workspace_crates[*]} -lt 1 ]; then + die "No workspace crates detected for $root" + fi +} + +setup_yj() { + if [ -e "$yj" ]; then + return + fi + + curl -sSLf -o "$yj" https://github.com/sclevine/yj/releases/download/v5.1.0/yj-linux-amd64 + + local expected_checksum="8ce43e40fda9a28221dabc0d7228e2325d1e959cd770487240deb47e02660986 $yj" + + local actual_checksum + actual_checksum="$(sha256sum "$yj")" + + if [ "$expected_checksum" != "$actual_checksum" ]; then + die "File had invalid checksum: $yj +Expected: $expected_checksum +Actual: $actual_checksum" + fi + + chmod +x "$yj" +} + +check_cratesio_crate() { + local crate="$1" + local cratesio_api="$2" + local crate_manifest="$3" + local expected_owner="$4" + + log "Checking if the crate $crate is compliant with crates.io" + + local owners_url="$cratesio_api/v1/crates/$crate/owners" + + local owners_response exit_code + owners_response="$(curl -sSLf "$owners_url")" || exit_code=$? + case "$exit_code" in + 22) # 404 response, which means that the crate doesn't exist on crates.io + >&2 echo "Crate $crate does not yet exist on crates.io, as per $owners_url. Please contact release-engineering to reserve the name in advance." + return 1 + ;; + 0) ;; + *) + >&2 echo "Request to $owners_url failed with exit code $exit_code" + return 1 + ;; + esac + + local owners_logins + owners_logins="$(echo -n "$owners_response" | jq -r '.users[] | .login')" + + local found_owner + while IFS= read -r owner_login; do + if [ "$owner_login" == "$expected_owner" ]; then + found_owner=true + break + fi + done < <(echo "$owners_logins") + + if [ ! "${found_owner:-}" ]; then + >&2 echo "crates.io ownership for crate $crate (from $crate_manifest) is not set up as expected. + +The current owners were recognized from $owners_url: +$owners_logins + +Failed to find $expected_owner among the above owners. + +The current owners were extracted from the following response: +$owners_response +" + return 1 + fi +} + +check_repository() { + local cratesio_api="$1" + local cratesio_crates_owner="$2" + local gh_api="$3" + local this_branch="$4" + + local selected_crates=() + + # if the branch belongs to a pull request, then check only the changed files + # otherwise, assume to be running on master and take all crates into account + if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + local pr_number="$this_branch" + + changed_pr_files=() + set +x + while IFS= read -r diff_line; do + if ! [[ "$diff_line" =~ ^\+\+\+[[:space:]]+b/(.+)$ ]]; then + continue + fi + set -x + local changed_file="${BASH_REMATCH[1]}" + changed_pr_files+=("$changed_file") + case "$changed_file" in + */Cargo.toml) + setup_yj + local manifest_json + manifest_json="$("$yj" -tj < "$changed_file")" + + local publish + publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" + case "$publish" in + null|true) + local crate + crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" + selected_crates+=("$crate" "$changed_file") + ;; + false) ;; + *) + die "Unexpected value for .package.publish of $changed_file: $publish" + ;; + esac + ;; + esac + done < <( + curl -sSLf \ + -H "Accept: application/vnd.github.v3.diff" \ + -H "Authorization: token $GITHUB_PR_TOKEN" \ + "$gh_api/repos/$REPO_OWNER/$REPO/pulls/$pr_number" \ + || die all "Failed to get diff for PR $pr_number" + ) + set -x + else + load_workspace_crates + selected_crates=("${workspace_crates[@]}") + fi + + # TODO: go further after squatted crates are dealt with (paritytech/release-engineering#132) + return + + local exit_code + + for ((i=0; i < ${#selected_crates[*]}; i+=2)); do + local crate="${selected_crates[$i]}" + local crate_manifest="${selected_crates[$((i+1))]}" + if ! check_cratesio_crate \ + "$crate" \ + "$cratesio_api" \ + "$crate_manifest" \ + "$cratesio_crates_owner" + then + exit_code=1 + fi + done + + if [ "${exit_code:-}" ]; then + exit "$exit_code" + fi +} + +setup_environment() { + mkdir -p "$tmp" + export PATH="$tmp:$PATH" + mkdir -p "$cargo_target_dir" + export PATH="$cargo_target_dir/release:$PATH" +} + +setup_repository() { + echo "/.tmp"$'\n'"/$(dirname "${BASH_SOURCE[0]}")" > "$tmp/.gitignore" + git config core.excludesFile "$tmp/.gitignore" +} + +main() { + local this_branch="$CI_COMMIT_REF_NAME" + if [[ + (! "$this_branch" =~ ^[[:digit:]]+$) && + "$CI_COMMIT_REF_NAME" != "$CI_DEFAULT_BRANCH" + ]]; then + echo "This check only runs for pull requests or $CI_DEFAULT_BRANCH" + exit 0 + fi + + # shellcheck disable=SC2153 # lowercase counterpart + local cratesio_target_instance="$CRATESIO_TARGET_INSTANCE" + # shellcheck disable=SC2153 # lowercase counterpart + local cratesio_crates_owner="$CRATESIO_CRATES_OWNER" + # shellcheck disable=SC2153 # lowercase counterpart + local gh_api="$GH_API" + # shellcheck disable=SC2153 # lowercase counterpart + local cratesio_api="$CRATESIO_API" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_start_from="${SPUB_START_FROM:-}" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_publish="${SPUB_PUBLISH:-}" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_verify_from="${SPUB_VERIFY_FROM:-}" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_after_publish_delay="${SPUB_AFTER_PUBLISH_DELAY:-}" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_exclude="${SPUB_EXCLUDE:-}" + + setup_environment + + if [[ $- =~ x ]]; then + # when -x is set up the logged messages will be printed during execution, so there's no need to + # also echo them; create a no-op executable for this purpose + touch "$tmp/log" + chmod +x "$tmp/log" + else + ln -s "$(which echo)" "$tmp/log" + fi + + setup_repository + + check_repository \ + "$cratesio_api" \ + "$cratesio_crates_owner" \ + "$gh_api" \ + "$this_branch" + + local subpub_args=(publish --post-check --root "$PWD") + + local crates_to_publish=() + + while IFS= read -r crate; do + if [ ! "$crate" ]; then + continue + fi + if [[ "$crate" =~ [^[:space:]]+ ]]; then + crates_to_publish+=("${BASH_REMATCH[0]}") + else + die "Crate name had unexpected format: $crate" + fi + done < <(echo "$spub_publish") + + if [ ${#crates_to_publish[*]} -eq 0 ] && [ "${changed_pr_files:-}" ]; then + for file in "${changed_pr_files[@]}"; do + local current="$file" + while true; do + current="$(dirname "$current")" + if [ "$current" == . ]; then + break + fi + + local manifest_path="$root/$current/Cargo.toml" + if [ -e "$manifest_path" ]; then + setup_yj + local manifest_json + manifest_json="$("$yj" -tj < "$manifest_path")" + + local publish + publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" + case "$publish" in + null|true) + local crate + crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" + + local crate_already_inserted + for prev_crate_to_check in "${crates_to_publish[@]}"; do + if [ "$prev_crate_to_check" == "$crate" ]; then + crate_already_inserted=true + break + fi + done + + if [ "${crate_already_inserted:-}" ]; then + unset crate_already_inserted + else + crates_to_publish+=("$crate") + fi + ;; + false) ;; + *) + die "Unexpected value for .package.publish of $manifest_path: $publish" + ;; + esac + fi + done + done + if [ ${#crates_to_publish[*]} -gt 0 ]; then + subpub_args+=(--include-crates-dependents) + else + log "No crate changes were detected for this PR" + exit + fi + fi + + case "$cratesio_target_instance" in + local) + git config --global user.name "CI" + git config --global user.email "<>" + + apt update -qq + setup_postgres + setup_diesel + setup_local_cratesio + ;; + default) + # TODO: enable it after local instance publishing works for a while on CI + echo "Publishing to crates.io is temporarily disabled"; exit 0 + export SPUB_CRATES_API=http://crates.io/api/v1 + ;; + *) + die "Invalid target: $cratesio_target_instance" + ;; + esac + + for crate_to_publish in "${crates_to_publish[@]}"; do + subpub_args+=(-c "$crate_to_publish") + done + + if [ "$spub_start_from" ]; then + subpub_args+=(--start-from "$spub_start_from") + fi + + if [ "$spub_verify_from" ]; then + subpub_args+=(-v "$spub_verify_from") + fi + + if [ "$spub_after_publish_delay" ]; then + subpub_args+=(--after-publish-delay "$spub_after_publish_delay") + fi + + while IFS= read -r crate; do + if [ ! "$crate" ]; then + continue + fi + if [[ "$crate" =~ [^[:space:]]+ ]]; then + subpub_args+=(-e "${BASH_REMATCH[0]}") + else + die "Crate name had unexpected format: $crate" + fi + done < <(echo "$spub_exclude") + + if [ "${SPUB_TMP:-}" ]; then + if [ "${SPUB_TMP:: 1}" != '/' ]; then + export SPUB_TMP="$PWD/$SPUB_TMP" + fi + mkdir -p "$SPUB_TMP" + fi + + setup_subpub + subpub "${subpub_args[@]}" +} + +main "$@" From d4b55ce3df1fbf8e0ca6a413cbec64d60da457e2 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 1 Dec 2022 07:08:47 -0300 Subject: [PATCH 002/109] remove branch naming limitation --- publish-crates | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/publish-crates b/publish-crates index 05085f72..6c00e387 100755 --- a/publish-crates +++ b/publish-crates @@ -395,15 +395,6 @@ setup_repository() { } main() { - local this_branch="$CI_COMMIT_REF_NAME" - if [[ - (! "$this_branch" =~ ^[[:digit:]]+$) && - "$CI_COMMIT_REF_NAME" != "$CI_DEFAULT_BRANCH" - ]]; then - echo "This check only runs for pull requests or $CI_DEFAULT_BRANCH" - exit 0 - fi - # shellcheck disable=SC2153 # lowercase counterpart local cratesio_target_instance="$CRATESIO_TARGET_INSTANCE" # shellcheck disable=SC2153 # lowercase counterpart @@ -422,6 +413,7 @@ main() { local spub_after_publish_delay="${SPUB_AFTER_PUBLISH_DELAY:-}" # shellcheck disable=SC2153 # lowercase counterpart local spub_exclude="${SPUB_EXCLUDE:-}" + local this_branch="$CI_COMMIT_REF_NAME" setup_environment From ad2e0631d0ca666683ff6e829c78984411f449ec Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 1 Dec 2022 09:03:13 -0300 Subject: [PATCH 003/109] handle PR with no changed files --- publish-crates | 98 ++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/publish-crates b/publish-crates index 6c00e387..240aa4df 100755 --- a/publish-crates +++ b/publish-crates @@ -449,54 +449,59 @@ main() { fi done < <(echo "$spub_publish") - if [ ${#crates_to_publish[*]} -eq 0 ] && [ "${changed_pr_files:-}" ]; then - for file in "${changed_pr_files[@]}"; do - local current="$file" - while true; do - current="$(dirname "$current")" - if [ "$current" == . ]; then - break - fi - - local manifest_path="$root/$current/Cargo.toml" - if [ -e "$manifest_path" ]; then - setup_yj - local manifest_json - manifest_json="$("$yj" -tj < "$manifest_path")" - - local publish - publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" - case "$publish" in - null|true) - local crate - crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" - - local crate_already_inserted - for prev_crate_to_check in "${crates_to_publish[@]}"; do - if [ "$prev_crate_to_check" == "$crate" ]; then - crate_already_inserted=true - break + if [ ${#crates_to_publish[*]} -eq 0 ]; then + if [ "${changed_pr_files:-}" ]; then + for file in "${changed_pr_files[@]}"; do + local current="$file" + while true; do + current="$(dirname "$current")" + if [ "$current" == . ]; then + break + fi + + local manifest_path="$root/$current/Cargo.toml" + if [ -e "$manifest_path" ]; then + setup_yj + local manifest_json + manifest_json="$("$yj" -tj < "$manifest_path")" + + local publish + publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" + case "$publish" in + null|true) + local crate + crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" + + local crate_already_inserted + for prev_crate_to_check in "${crates_to_publish[@]}"; do + if [ "$prev_crate_to_check" == "$crate" ]; then + crate_already_inserted=true + break + fi + done + + if [ "${crate_already_inserted:-}" ]; then + unset crate_already_inserted + else + crates_to_publish+=("$crate") fi - done - - if [ "${crate_already_inserted:-}" ]; then - unset crate_already_inserted - else - crates_to_publish+=("$crate") - fi - ;; - false) ;; - *) - die "Unexpected value for .package.publish of $manifest_path: $publish" - ;; - esac - fi + ;; + false) ;; + *) + die "Unexpected value for .package.publish of $manifest_path: $publish" + ;; + esac + fi + done done - done - if [ ${#crates_to_publish[*]} -gt 0 ]; then - subpub_args+=(--include-crates-dependents) - else - log "No crate changes were detected for this PR" + if [ ${#crates_to_publish[*]} -gt 0 ]; then + subpub_args+=(--include-crates-dependents) + else + log "No crate changes were detected for this PR" + exit + fi + elif [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + log "No file changes were detected for this PR" exit fi fi @@ -505,7 +510,6 @@ main() { local) git config --global user.name "CI" git config --global user.email "<>" - apt update -qq setup_postgres setup_diesel From f7559d8fea4d0106c550f7bdac60e318590d4b85 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 2 Dec 2022 04:39:32 -0300 Subject: [PATCH 004/109] re-enable set -x before read -r diff_line --- publish-crates | 1 + 1 file changed, 1 insertion(+) diff --git a/publish-crates b/publish-crates index 240aa4df..74506fee 100755 --- a/publish-crates +++ b/publish-crates @@ -346,6 +346,7 @@ check_repository() { esac ;; esac + set +x done < <( curl -sSLf \ -H "Accept: application/vnd.github.v3.diff" \ From 2e7692b19bd9ebc52169ecd88c5440c897fe11ed Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 2 Dec 2022 05:43:03 -0300 Subject: [PATCH 005/109] change error message --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 74506fee..43c8afec 100755 --- a/publish-crates +++ b/publish-crates @@ -267,7 +267,7 @@ check_cratesio_crate() { owners_response="$(curl -sSLf "$owners_url")" || exit_code=$? case "$exit_code" in 22) # 404 response, which means that the crate doesn't exist on crates.io - >&2 echo "Crate $crate does not yet exist on crates.io, as per $owners_url. Please contact release-engineering to reserve the name in advance." + >&2 echo "Crate $crate does not yet exist on crates.io, as per $owners_url. Please request for the crate name to be reserved in advance." return 1 ;; 0) ;; From 9846a5a0ea2e1e6fb0348560543b5016c6f24851 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 2 Dec 2022 05:43:11 -0300 Subject: [PATCH 006/109] s/echo/log --- publish-crates | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/publish-crates b/publish-crates index 43c8afec..369a4e29 100755 --- a/publish-crates +++ b/publish-crates @@ -267,12 +267,12 @@ check_cratesio_crate() { owners_response="$(curl -sSLf "$owners_url")" || exit_code=$? case "$exit_code" in 22) # 404 response, which means that the crate doesn't exist on crates.io - >&2 echo "Crate $crate does not yet exist on crates.io, as per $owners_url. Please request for the crate name to be reserved in advance." + >&2 log "Crate $crate does not yet exist on crates.io, as per $owners_url. Please request for the crate name to be reserved in advance." return 1 ;; 0) ;; *) - >&2 echo "Request to $owners_url failed with exit code $exit_code" + >&2 log "Request to $owners_url failed with exit code $exit_code" return 1 ;; esac @@ -289,7 +289,7 @@ check_cratesio_crate() { done < <(echo "$owners_logins") if [ ! "${found_owner:-}" ]; then - >&2 echo "crates.io ownership for crate $crate (from $crate_manifest) is not set up as expected. + >&2 log "crates.io ownership for crate $crate (from $crate_manifest) is not set up as expected. The current owners were recognized from $owners_url: $owners_logins From 39925c73eca7b8fab4763af5099157184e379e95 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 2 Dec 2022 05:52:37 -0300 Subject: [PATCH 007/109] augment comment --- publish-crates | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/publish-crates b/publish-crates index 369a4e29..7386fe7b 100755 --- a/publish-crates +++ b/publish-crates @@ -10,9 +10,12 @@ echo " publish-crates ======================== -This script publishes all workspace crates to the target crates.io instance of choice. It can either -publish them to a local crates.io instance (which is set up by this script) or the official -crates.io registry. +This script publishes all workspace crates to the target crates.io instance of +choice. It can either publish them to a local crates.io instance (which is set +up by this script) or the official crates.io registry. + +This script is intended to be used from GitLab CI. Consider running subpub +directly if you're interested in running it somewhere else. " set -Eeu -o pipefail From 72cfacd7f20dd5c45ead14ef0992ecf75d0244c6 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 2 Dec 2022 06:13:23 -0300 Subject: [PATCH 008/109] organize variables --- publish-crates | 3 +++ 1 file changed, 3 insertions(+) diff --git a/publish-crates b/publish-crates index 7386fe7b..6eaed3f5 100755 --- a/publish-crates +++ b/publish-crates @@ -399,6 +399,7 @@ setup_repository() { } main() { + # Script-specific variables # shellcheck disable=SC2153 # lowercase counterpart local cratesio_target_instance="$CRATESIO_TARGET_INSTANCE" # shellcheck disable=SC2153 # lowercase counterpart @@ -417,6 +418,8 @@ main() { local spub_after_publish_delay="${SPUB_AFTER_PUBLISH_DELAY:-}" # shellcheck disable=SC2153 # lowercase counterpart local spub_exclude="${SPUB_EXCLUDE:-}" + + # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" setup_environment From 9a87c88f51f3e0a27db866981edec0a3c5536b80 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 2 Dec 2022 07:37:28 -0300 Subject: [PATCH 009/109] fix gitignore --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 6eaed3f5..f1ed8216 100755 --- a/publish-crates +++ b/publish-crates @@ -394,7 +394,7 @@ setup_environment() { } setup_repository() { - echo "/.tmp"$'\n'"/$(dirname "${BASH_SOURCE[0]}")" > "$tmp/.gitignore" + echo "/.tmp"$'\n'"/$(basename "$(dirname "${BASH_SOURCE[0]}")")" > "$tmp/.gitignore" git config core.excludesFile "$tmp/.gitignore" } From 8221ed4e14dad5dce178cdce480a4485036b6cf5 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sat, 3 Dec 2022 01:19:06 -0300 Subject: [PATCH 010/109] stop on first manifest found --- publish-crates | 2 ++ 1 file changed, 2 insertions(+) diff --git a/publish-crates b/publish-crates index f1ed8216..b1e18aac 100755 --- a/publish-crates +++ b/publish-crates @@ -498,6 +498,8 @@ main() { die "Unexpected value for .package.publish of $manifest_path: $publish" ;; esac + + break fi done done From 02389568fc4ae27e7566612ab74ca5aebde0baba Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 05:10:22 -0300 Subject: [PATCH 011/109] only verify crates which changed for PRs --- publish-crates | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/publish-crates b/publish-crates index b1e18aac..9d09c66b 100755 --- a/publish-crates +++ b/publish-crates @@ -504,7 +504,9 @@ main() { done done if [ ${#crates_to_publish[*]} -gt 0 ]; then - subpub_args+=(--include-crates-dependents) + for crate in "${crates_to_publish[@]}"; do + subpub_args+=(--verify-crate "$crate_to_publish") + done else log "No crate changes were detected for this PR" exit @@ -535,7 +537,7 @@ main() { esac for crate_to_publish in "${crates_to_publish[@]}"; do - subpub_args+=(-c "$crate_to_publish") + subpub_args+=(--crate "$crate_to_publish") done if [ "$spub_start_from" ]; then @@ -543,7 +545,7 @@ main() { fi if [ "$spub_verify_from" ]; then - subpub_args+=(-v "$spub_verify_from") + subpub_args+=(--verify-from "$spub_verify_from") fi if [ "$spub_after_publish_delay" ]; then From a430533b0e429403767ad179773761da2e16d988 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 05:11:50 -0300 Subject: [PATCH 012/109] wip: disable filtering for changed pr files --- publish-crates | 120 ++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/publish-crates b/publish-crates index 9d09c66b..fd825565 100755 --- a/publish-crates +++ b/publish-crates @@ -456,66 +456,66 @@ main() { fi done < <(echo "$spub_publish") - if [ ${#crates_to_publish[*]} -eq 0 ]; then - if [ "${changed_pr_files:-}" ]; then - for file in "${changed_pr_files[@]}"; do - local current="$file" - while true; do - current="$(dirname "$current")" - if [ "$current" == . ]; then - break - fi - - local manifest_path="$root/$current/Cargo.toml" - if [ -e "$manifest_path" ]; then - setup_yj - local manifest_json - manifest_json="$("$yj" -tj < "$manifest_path")" - - local publish - publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" - case "$publish" in - null|true) - local crate - crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" - - local crate_already_inserted - for prev_crate_to_check in "${crates_to_publish[@]}"; do - if [ "$prev_crate_to_check" == "$crate" ]; then - crate_already_inserted=true - break - fi - done - - if [ "${crate_already_inserted:-}" ]; then - unset crate_already_inserted - else - crates_to_publish+=("$crate") - fi - ;; - false) ;; - *) - die "Unexpected value for .package.publish of $manifest_path: $publish" - ;; - esac - - break - fi - done - done - if [ ${#crates_to_publish[*]} -gt 0 ]; then - for crate in "${crates_to_publish[@]}"; do - subpub_args+=(--verify-crate "$crate_to_publish") - done - else - log "No crate changes were detected for this PR" - exit - fi - elif [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then - log "No file changes were detected for this PR" - exit - fi - fi + # if [ ${#crates_to_publish[*]} -eq 0 ]; then + # if [ "${changed_pr_files:-}" ]; then + # for file in "${changed_pr_files[@]}"; do + # local current="$file" + # while true; do + # current="$(dirname "$current")" + # if [ "$current" == . ]; then + # break + # fi + # + # local manifest_path="$root/$current/Cargo.toml" + # if [ -e "$manifest_path" ]; then + # setup_yj + # local manifest_json + # manifest_json="$("$yj" -tj < "$manifest_path")" + # + # local publish + # publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" + # case "$publish" in + # null|true) + # local crate + # crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" + # + # local crate_already_inserted + # for prev_crate_to_check in "${crates_to_publish[@]}"; do + # if [ "$prev_crate_to_check" == "$crate" ]; then + # crate_already_inserted=true + # break + # fi + # done + # + # if [ "${crate_already_inserted:-}" ]; then + # unset crate_already_inserted + # else + # crates_to_publish+=("$crate") + # fi + # ;; + # false) ;; + # *) + # die "Unexpected value for .package.publish of $manifest_path: $publish" + # ;; + # esac + # + # break + # fi + # done + # done + # if [ ${#crates_to_publish[*]} -gt 0 ]; then + # for crate in "${crates_to_publish[@]}"; do + # subpub_args+=(--verify-crate "$crate_to_publish") + # done + # else + # log "No crate changes were detected for this PR" + # exit + # fi + # elif [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + # log "No file changes were detected for this PR" + # exit + # fi + # fi case "$cratesio_target_instance" in local) From c358def65cf1f72109fe6f445e7c124b3f873015 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 05:38:05 -0300 Subject: [PATCH 013/109] update subpub cli option usage --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index fd825565..440fb247 100755 --- a/publish-crates +++ b/publish-crates @@ -537,7 +537,7 @@ main() { esac for crate_to_publish in "${crates_to_publish[@]}"; do - subpub_args+=(--crate "$crate_to_publish") + subpub_args+=(--publish-only "$crate_to_publish") done if [ "$spub_start_from" ]; then From 4aa1c78086ffc881d7c979489ade9a4ef7933b09 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 06:36:58 -0300 Subject: [PATCH 014/109] revert a430533b0e429403767ad179773761da2e16d988 --- publish-crates | 120 ++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/publish-crates b/publish-crates index 440fb247..7c998525 100755 --- a/publish-crates +++ b/publish-crates @@ -456,66 +456,66 @@ main() { fi done < <(echo "$spub_publish") - # if [ ${#crates_to_publish[*]} -eq 0 ]; then - # if [ "${changed_pr_files:-}" ]; then - # for file in "${changed_pr_files[@]}"; do - # local current="$file" - # while true; do - # current="$(dirname "$current")" - # if [ "$current" == . ]; then - # break - # fi - # - # local manifest_path="$root/$current/Cargo.toml" - # if [ -e "$manifest_path" ]; then - # setup_yj - # local manifest_json - # manifest_json="$("$yj" -tj < "$manifest_path")" - # - # local publish - # publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" - # case "$publish" in - # null|true) - # local crate - # crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" - # - # local crate_already_inserted - # for prev_crate_to_check in "${crates_to_publish[@]}"; do - # if [ "$prev_crate_to_check" == "$crate" ]; then - # crate_already_inserted=true - # break - # fi - # done - # - # if [ "${crate_already_inserted:-}" ]; then - # unset crate_already_inserted - # else - # crates_to_publish+=("$crate") - # fi - # ;; - # false) ;; - # *) - # die "Unexpected value for .package.publish of $manifest_path: $publish" - # ;; - # esac - # - # break - # fi - # done - # done - # if [ ${#crates_to_publish[*]} -gt 0 ]; then - # for crate in "${crates_to_publish[@]}"; do - # subpub_args+=(--verify-crate "$crate_to_publish") - # done - # else - # log "No crate changes were detected for this PR" - # exit - # fi - # elif [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then - # log "No file changes were detected for this PR" - # exit - # fi - # fi + if [ ${#crates_to_publish[*]} -eq 0 ]; then + if [ "${changed_pr_files:-}" ]; then + for file in "${changed_pr_files[@]}"; do + local current="$file" + while true; do + current="$(dirname "$current")" + if [ "$current" == . ]; then + break + fi + + local manifest_path="$root/$current/Cargo.toml" + if [ -e "$manifest_path" ]; then + setup_yj + local manifest_json + manifest_json="$("$yj" -tj < "$manifest_path")" + + local publish + publish="$(echo -n "$manifest_json" | jq -r '.package.publish')" + case "$publish" in + null|true) + local crate + crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" + + local crate_already_inserted + for prev_crate_to_check in "${crates_to_publish[@]}"; do + if [ "$prev_crate_to_check" == "$crate" ]; then + crate_already_inserted=true + break + fi + done + + if [ "${crate_already_inserted:-}" ]; then + unset crate_already_inserted + else + crates_to_publish+=("$crate") + fi + ;; + false) ;; + *) + die "Unexpected value for .package.publish of $manifest_path: $publish" + ;; + esac + + break + fi + done + done + if [ ${#crates_to_publish[*]} -gt 0 ]; then + for crate in "${crates_to_publish[@]}"; do + subpub_args+=(--verify-crate "$crate_to_publish") + done + else + log "No crate changes were detected for this PR" + exit + fi + elif [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + log "No file changes were detected for this PR" + exit + fi + fi case "$cratesio_target_instance" in local) From 4d99e8e8f048ab08cbbfe0c6cb496033e02e2624 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 06:59:56 -0300 Subject: [PATCH 015/109] fix variable name --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 7c998525..22af42ef 100755 --- a/publish-crates +++ b/publish-crates @@ -505,7 +505,7 @@ main() { done if [ ${#crates_to_publish[*]} -gt 0 ]; then for crate in "${crates_to_publish[@]}"; do - subpub_args+=(--verify-crate "$crate_to_publish") + subpub_args+=(--verify-crate "$crate") done else log "No crate changes were detected for this PR" From 0ea17b4c73d97525e970a57553c79d3631ef7344 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 07:00:39 -0300 Subject: [PATCH 016/109] fix CLI option --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 22af42ef..ae4ac93c 100755 --- a/publish-crates +++ b/publish-crates @@ -505,7 +505,7 @@ main() { done if [ ${#crates_to_publish[*]} -gt 0 ]; then for crate in "${crates_to_publish[@]}"; do - subpub_args+=(--verify-crate "$crate") + subpub_args+=(--verify-only "$crate") done else log "No crate changes were detected for this PR" From c4cab1f0a4a70ebe68452febe9d0333580a4479b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 07:56:12 -0300 Subject: [PATCH 017/109] enable crates.io compliance check --- publish-crates | 3 --- 1 file changed, 3 deletions(-) diff --git a/publish-crates b/publish-crates index ae4ac93c..6bdaf5d8 100755 --- a/publish-crates +++ b/publish-crates @@ -363,9 +363,6 @@ check_repository() { selected_crates=("${workspace_crates[@]}") fi - # TODO: go further after squatted crates are dealt with (paritytech/release-engineering#132) - return - local exit_code for ((i=0; i < ${#selected_crates[*]}; i+=2)); do From cd24e9064e3abecdb952ff955d9e651f18288c02 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 08:05:18 -0300 Subject: [PATCH 018/109] fix crates.io check --- publish-crates | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/publish-crates b/publish-crates index 6bdaf5d8..bf2d435b 100755 --- a/publish-crates +++ b/publish-crates @@ -259,8 +259,7 @@ Actual: $actual_checksum" check_cratesio_crate() { local crate="$1" local cratesio_api="$2" - local crate_manifest="$3" - local expected_owner="$4" + local expected_owner="$3" log "Checking if the crate $crate is compliant with crates.io" @@ -292,7 +291,7 @@ check_cratesio_crate() { done < <(echo "$owners_logins") if [ ! "${found_owner:-}" ]; then - >&2 log "crates.io ownership for crate $crate (from $crate_manifest) is not set up as expected. + >&2 log "crates.io ownership for crate $crate is not set up as expected. The current owners were recognized from $owners_url: $owners_logins @@ -340,7 +339,7 @@ check_repository() { null|true) local crate crate="$(echo -n "$manifest_json" | jq -e -r '.package.name')" - selected_crates+=("$crate" "$changed_file") + selected_crates+=("$crate") ;; false) ;; *) @@ -365,13 +364,10 @@ check_repository() { local exit_code - for ((i=0; i < ${#selected_crates[*]}; i+=2)); do - local crate="${selected_crates[$i]}" - local crate_manifest="${selected_crates[$((i+1))]}" + for crate in "${selected_crates[@]}"; do if ! check_cratesio_crate \ "$crate" \ "$cratesio_api" \ - "$crate_manifest" \ "$cratesio_crates_owner" then exit_code=1 From ed7bc096ad9b58003653e0c13186a81fd56c461f Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 08:13:32 -0300 Subject: [PATCH 019/109] fix crates.io compliance check --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index bf2d435b..fcfc994d 100755 --- a/publish-crates +++ b/publish-crates @@ -267,12 +267,12 @@ check_cratesio_crate() { local owners_response exit_code owners_response="$(curl -sSLf "$owners_url")" || exit_code=$? - case "$exit_code" in + case "${exit_code:-}" in 22) # 404 response, which means that the crate doesn't exist on crates.io >&2 log "Crate $crate does not yet exist on crates.io, as per $owners_url. Please request for the crate name to be reserved in advance." return 1 ;; - 0) ;; + 0|"") ;; *) >&2 log "Request to $owners_url failed with exit code $exit_code" return 1 From cac2ddab19a7a69ec00e6f3566eba4821e075f14 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Sun, 4 Dec 2022 08:22:35 -0300 Subject: [PATCH 020/109] disable crates.io compliance check --- publish-crates | 3 +++ 1 file changed, 3 insertions(+) diff --git a/publish-crates b/publish-crates index fcfc994d..0d7da05f 100755 --- a/publish-crates +++ b/publish-crates @@ -362,6 +362,9 @@ check_repository() { selected_crates=("${workspace_crates[@]}") fi + # TODO: go further after squatted crates are dealt with (paritytech/release-engineering#132) + return + local exit_code for crate in "${selected_crates[@]}"; do From cbdc198458b4f0fe6d6fa0d96784d3a844b5852e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 6 Dec 2022 07:03:41 -0300 Subject: [PATCH 021/109] wip: debug CI --- publish-crates | 1 + 1 file changed, 1 insertion(+) diff --git a/publish-crates b/publish-crates index 0d7da05f..8c1cdd3f 100755 --- a/publish-crates +++ b/publish-crates @@ -181,6 +181,7 @@ setup_diesel() { --version 1.4.1 \ --no-default-features \ --features postgres + ls "$cargo_target_dir/release" diesel --version if [ "$old_cargo_target_dir" ]; then From 5f9c594f43d39dba341b0d8eaa0172b719cdd09b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 6 Dec 2022 07:34:56 -0300 Subject: [PATCH 022/109] set target dir explictly --- publish-crates | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/publish-crates b/publish-crates index 8c1cdd3f..ebcf655b 100755 --- a/publish-crates +++ b/publish-crates @@ -159,37 +159,20 @@ setup_local_cratesio() { } setup_subpub() { - local old_cargo_target_dir="${CARGO_TARGET_DIR:-}" - export CARGO_TARGET_DIR="$cargo_target_dir" - - cargo install --quiet --git https://github.com/paritytech/subpub --branch releng + cargo install --quiet \ + --git https://github.com/paritytech/subpub \ + --branch releng \ + --target-dir "$cargo_target_dir" subpub --version - - if [ "$old_cargo_target_dir" ]; then - export CARGO_TARGET_DIR="$old_cargo_target_dir" - else - unset CARGO_TARGET_DIR - export -n CARGO_TARGET_DIR - fi } setup_diesel() { - local old_cargo_target_dir="${CARGO_TARGET_DIR:-}" - export CARGO_TARGET_DIR="$cargo_target_dir" - cargo install --quiet diesel_cli \ --version 1.4.1 \ --no-default-features \ - --features postgres - ls "$cargo_target_dir/release" + --features postgres \ + --target-dir "$cargo_target_dir" diesel --version - - if [ "$old_cargo_target_dir" ]; then - export CARGO_TARGET_DIR="$old_cargo_target_dir" - else - unset CARGO_TARGET_DIR - export -n CARGO_TARGET_DIR - fi } setup_postgres() { From 65d7ddffc55f2da01943e631fca6dd947b0db395 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 6 Dec 2022 07:36:31 -0300 Subject: [PATCH 023/109] wip: debug CI --- publish-crates | 2 ++ 1 file changed, 2 insertions(+) diff --git a/publish-crates b/publish-crates index ebcf655b..98f4707a 100755 --- a/publish-crates +++ b/publish-crates @@ -172,6 +172,8 @@ setup_diesel() { --no-default-features \ --features postgres \ --target-dir "$cargo_target_dir" + ls "$cargo_target_dir" + echo "$PATH" diesel --version } From fc5de0f6118a83df1d6478cf98bbd22bdf5150ba Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 6 Dec 2022 07:37:44 -0300 Subject: [PATCH 024/109] move diesel setup to before postgres setup --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 98f4707a..048d217e 100755 --- a/publish-crates +++ b/publish-crates @@ -503,9 +503,9 @@ main() { local) git config --global user.name "CI" git config --global user.email "<>" + setup_diesel apt update -qq setup_postgres - setup_diesel setup_local_cratesio ;; default) From 13835951e76f35ba3946f8aba46120d209f13fb5 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 6 Dec 2022 07:41:01 -0300 Subject: [PATCH 025/109] fix cargo_root_dir usage --- publish-crates | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/publish-crates b/publish-crates index 048d217e..a90d6596 100755 --- a/publish-crates +++ b/publish-crates @@ -24,7 +24,7 @@ shopt -s inherit_errexit root="$PWD" tmp="$root/.tmp" cratesio_dir="$tmp/crates.io" -cargo_target_dir="$tmp/cargo" +cargo_root_dir="$tmp/cargo" yj="$tmp/yj" on_exit() { @@ -162,7 +162,7 @@ setup_subpub() { cargo install --quiet \ --git https://github.com/paritytech/subpub \ --branch releng \ - --target-dir "$cargo_target_dir" + --root "$cargo_root_dir" subpub --version } @@ -171,9 +171,7 @@ setup_diesel() { --version 1.4.1 \ --no-default-features \ --features postgres \ - --target-dir "$cargo_target_dir" - ls "$cargo_target_dir" - echo "$PATH" + --root "$cargo_root_dir" diesel --version } @@ -371,8 +369,8 @@ check_repository() { setup_environment() { mkdir -p "$tmp" export PATH="$tmp:$PATH" - mkdir -p "$cargo_target_dir" - export PATH="$cargo_target_dir/release:$PATH" + mkdir -p "$cargo_root_dir" + export PATH="$cargo_root_dir/bin:$PATH" } setup_repository() { From d30390917dde8786399c287af6146d642ccffaf1 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 6 Dec 2022 07:43:28 -0300 Subject: [PATCH 026/109] reorder setup_diesel --- publish-crates | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index a90d6596..39ed6f5e 100755 --- a/publish-crates +++ b/publish-crates @@ -501,9 +501,10 @@ main() { local) git config --global user.name "CI" git config --global user.email "<>" - setup_diesel apt update -qq setup_postgres + # diesel setup should be after setup_progress because it depends on libpq + setup_diesel setup_local_cratesio ;; default) From 0a66db1e104aa45b05ae36acab6762e442d1cafd Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 04:32:40 -0300 Subject: [PATCH 027/109] clear the registry's cache after a crate is committed --- publish-crates | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 39ed6f5e..f52725c6 100755 --- a/publish-crates +++ b/publish-crates @@ -130,8 +130,18 @@ setup_local_cratesio() { # example line: Commit and push finished for "Updating crate `foo#0.1.0`" "$crate_committed_msg_prefix"*) line_remainder="${line:${#crate_committed_msg_prefix}}" - if [[ "$line_remainder" =~ ^([^#]+)# ]]; then - echo "${BASH_REMATCH[1]}" >> "$SPUB_CRATES_COMMITTED_FILE" + if [[ "$line_remainder" =~ ^([^#]+)#([[:digit:].]+) ]]; then + crate_and_version="${BASH_REMATCH[0]}" + crate="${BASH_REMATCH[1]}" + + # Clear the registry's cache after a crate is committed to the remote + # registry in order to force its redownload + find "$CARGO_HOME" \ + -type d -path "**/$crate_and_version" \ + -prune \ + -exec rm -rf {} \; + + echo "$crate" >> "$SPUB_CRATES_COMMITTED_FILE" else die all "background-worker line had unexpected format: $line" fi From 8742b796508ea22ff12d2c193d1b7bb868364f5e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 04:53:51 -0300 Subject: [PATCH 028/109] wip: debug CI --- publish-crates | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index f52725c6..22be9038 100755 --- a/publish-crates +++ b/publish-crates @@ -136,8 +136,9 @@ setup_local_cratesio() { # Clear the registry's cache after a crate is committed to the remote # registry in order to force its redownload - find "$CARGO_HOME" \ + find "${CARGO_HOME:-$HOME/.cargo}" \ -type d -path "**/$crate_and_version" \ + -print \ -prune \ -exec rm -rf {} \; From 761c57b72912b20330cf2cbdcde5985a05f7d2cc Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 05:09:29 -0300 Subject: [PATCH 029/109] fix crate registry path --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 22be9038..a0bbefbb 100755 --- a/publish-crates +++ b/publish-crates @@ -131,13 +131,13 @@ setup_local_cratesio() { "$crate_committed_msg_prefix"*) line_remainder="${line:${#crate_committed_msg_prefix}}" if [[ "$line_remainder" =~ ^([^#]+)#([[:digit:].]+) ]]; then - crate_and_version="${BASH_REMATCH[0]}" crate="${BASH_REMATCH[1]}" + crate_version="${BASH_REMATCH[2]}" # Clear the registry's cache after a crate is committed to the remote # registry in order to force its redownload find "${CARGO_HOME:-$HOME/.cargo}" \ - -type d -path "**/$crate_and_version" \ + -type d -path "**/$crate-$crate_version" \ -print \ -prune \ -exec rm -rf {} \; From d38dc20a9fda99bb1028f0310a903d5d086938f4 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 05:32:30 -0300 Subject: [PATCH 030/109] also clear the downloaded crate's cache --- publish-crates | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/publish-crates b/publish-crates index a0bbefbb..74ee1277 100755 --- a/publish-crates +++ b/publish-crates @@ -141,6 +141,10 @@ setup_local_cratesio() { -print \ -prune \ -exec rm -rf {} \; + find "${CARGO_HOME:-$HOME/.cargo}" \ + -type f -path "**/$crate-$crate_version.crate" \ + -print \ + -exec rm -f {} \; echo "$crate" >> "$SPUB_CRATES_COMMITTED_FILE" else From 20531d8b4155b28d752f66dcc9788dfaa8c63b70 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 05:48:52 -0300 Subject: [PATCH 031/109] DRY $cargo_home --- publish-crates | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 74ee1277..756a8d67 100755 --- a/publish-crates +++ b/publish-crates @@ -136,12 +136,13 @@ setup_local_cratesio() { # Clear the registry's cache after a crate is committed to the remote # registry in order to force its redownload - find "${CARGO_HOME:-$HOME/.cargo}" \ + cargo_home="${CARGO_HOME:-$HOME/.cargo}" + find "$cargo_home" \ -type d -path "**/$crate-$crate_version" \ -print \ -prune \ -exec rm -rf {} \; - find "${CARGO_HOME:-$HOME/.cargo}" \ + find "$cargo_home" \ -type f -path "**/$crate-$crate_version.crate" \ -print \ -exec rm -f {} \; From 5a467afe6863b18bbced6c26507fbb4ad9b8cf03 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 09:29:36 -0300 Subject: [PATCH 032/109] better variable names --- publish-crates | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/publish-crates b/publish-crates index 756a8d67..70e964e2 100755 --- a/publish-crates +++ b/publish-crates @@ -23,8 +23,8 @@ shopt -s inherit_errexit root="$PWD" tmp="$root/.tmp" -cratesio_dir="$tmp/crates.io" -cargo_root_dir="$tmp/cargo" +cratesio_repo="$tmp/crates.io" +tmp_cargo_root="$tmp/cargo" yj="$tmp/yj" on_exit() { @@ -74,9 +74,9 @@ set -xv setup_local_cratesio() { load_workspace_crates - git clone --branch releng https://github.com/paritytech/crates.io "$cratesio_dir" + git clone --branch releng https://github.com/paritytech/crates.io "$cratesio_repo" - >/dev/null pushd "$cratesio_dir" + >/dev/null pushd "$cratesio_repo" mkdir local_uploads tmp @@ -170,7 +170,7 @@ setup_local_cratesio() { export SPUB_REGISTRY=local export SPUB_CRATES_API=http://localhost:8888/api/v1 - export CARGO_REGISTRIES_LOCAL_INDEX=file://"$cratesio_dir"/tmp/index-bare + export CARGO_REGISTRIES_LOCAL_INDEX=file://"$cratesio_repo"/tmp/index-bare export SPUB_REGISTRY_TOKEN="$token" } @@ -178,7 +178,7 @@ setup_subpub() { cargo install --quiet \ --git https://github.com/paritytech/subpub \ --branch releng \ - --root "$cargo_root_dir" + --root "$tmp_cargo_root" subpub --version } @@ -187,7 +187,7 @@ setup_diesel() { --version 1.4.1 \ --no-default-features \ --features postgres \ - --root "$cargo_root_dir" + --root "$tmp_cargo_root" diesel --version } @@ -330,6 +330,7 @@ check_repository() { case "$changed_file" in */Cargo.toml) setup_yj + local manifest_json manifest_json="$("$yj" -tj < "$changed_file")" @@ -385,8 +386,8 @@ check_repository() { setup_environment() { mkdir -p "$tmp" export PATH="$tmp:$PATH" - mkdir -p "$cargo_root_dir" - export PATH="$cargo_root_dir/bin:$PATH" + mkdir -p "$tmp_cargo_root" + export PATH="$tmp_cargo_root/bin:$PATH" } setup_repository() { @@ -465,6 +466,7 @@ main() { local manifest_path="$root/$current/Cargo.toml" if [ -e "$manifest_path" ]; then setup_yj + local manifest_json manifest_json="$("$yj" -tj < "$manifest_path")" From e66887916f6123c10342404f05b1d35699dd4d0c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 09:32:33 -0300 Subject: [PATCH 033/109] update comment --- publish-crates | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index 70e964e2..ba8ffc56 100755 --- a/publish-crates +++ b/publish-crates @@ -1,10 +1,7 @@ #!/usr/bin/env bash ## A script for publishing workspace crates to a target crates.io instance. -## This script requires: -## - A working PostgreSQL v13 database -## - Some environment variables to be set up in advance (see how the check-publish-crates job is set -## up on CI for reference) +## You'll need to set up some environment variables in advance (see `main`). echo " publish-crates From 32e2cda0bdd5d91a6b53af49676c36fd8bebaa6d Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 09:38:00 -0300 Subject: [PATCH 034/109] get dirname through bash --- publish-crates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index ba8ffc56..f8abe99e 100755 --- a/publish-crates +++ b/publish-crates @@ -388,7 +388,10 @@ setup_environment() { } setup_repository() { - echo "/.tmp"$'\n'"/$(basename "$(dirname "${BASH_SOURCE[0]}")")" > "$tmp/.gitignore" + local this_file="${BASH_SOURCE[0]}" + local this_file_dir="${this_file%/*}" + local this_file_dirname="${this_file_dir##*/}" + echo "/.tmp"$'\n'"/$this_file_dirname" > "$tmp/.gitignore" git config core.excludesFile "$tmp/.gitignore" } From 9732003ffd3eadcf6e46a0960b17644ba4975fbc Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 17:12:53 -0300 Subject: [PATCH 035/109] enable crates.io compliance check --- publish-crates | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index f8abe99e..c7ce2ec7 100755 --- a/publish-crates +++ b/publish-crates @@ -266,7 +266,7 @@ check_cratesio_crate() { owners_response="$(curl -sSLf "$owners_url")" || exit_code=$? case "${exit_code:-}" in 22) # 404 response, which means that the crate doesn't exist on crates.io - >&2 log "Crate $crate does not yet exist on crates.io, as per $owners_url. Please request for the crate name to be reserved in advance." + >&2 log "Crate $crate does not yet exist on crates.io according to $owners_url. Please follow the instructions of https://github.com/paritytech/releng-scripts#reserving-crates to reserve the crate." return 1 ;; 0|"") ;; @@ -360,9 +360,6 @@ check_repository() { selected_crates=("${workspace_crates[@]}") fi - # TODO: go further after squatted crates are dealt with (paritytech/release-engineering#132) - return - local exit_code for crate in "${selected_crates[@]}"; do From 7dbb8da0ac62b332bce293d37cf2558224dff4fb Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 17:50:35 -0300 Subject: [PATCH 036/109] filter by publishable workspace crates on master --- publish-crates | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index c7ce2ec7..265ddf18 100755 --- a/publish-crates +++ b/publish-crates @@ -232,6 +232,38 @@ load_workspace_crates() { fi } +load_publishable_workspace_crates() { + if [ "${publishable_workspace_crates:-}" ]; then + return + fi + readarray -t publishable_workspace_crates < <( + cargo metadata --quiet --format-version=1 --manifest-path "$root/Cargo.toml" | + jq -r ' + . as $in | + paths | select( + (. | length == 3) and # .package, [N], .source + .[0]=="packages" and + .[2]=="source" and + . as $path | $in | getpath($path)==null # .source == null for workspace crates + ) as $crate_path | + del($crate_path[-1]) as $crate_path | + $in | + if + getpath($crate_path + ["publish"]) == null or + getpath($crate_path + ["publish"]) == true + then + [getpath($crate_path + ["name"])] + else + [] + end + | .[] + ' + ) + if [ ${#publishable_workspace_crates[*]} -lt 1 ]; then + die "No publishable workspace crates detected for the workspace of $root" + fi +} + setup_yj() { if [ -e "$yj" ]; then return @@ -356,8 +388,8 @@ check_repository() { ) set -x else - load_workspace_crates - selected_crates=("${workspace_crates[@]}") + load_publishable_workspace_crates + selected_crates=("${publishable_workspace_crates[@]}") fi local exit_code From ab6a304dd7681411b944262da9638a2fe073ff93 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 18:01:01 -0300 Subject: [PATCH 037/109] only perform post-check on master branch --- publish-crates | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index 265ddf18..54283b87 100755 --- a/publish-crates +++ b/publish-crates @@ -339,12 +339,13 @@ check_repository() { local cratesio_crates_owner="$2" local gh_api="$3" local this_branch="$4" + local is_pr_branch="$5" local selected_crates=() # if the branch belongs to a pull request, then check only the changed files # otherwise, assume to be running on master and take all crates into account - if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + if [ "$is_pr_branch" ]; then local pr_number="$this_branch" changed_pr_files=() @@ -448,6 +449,11 @@ main() { # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" + local is_pr_branch + if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + is_pr_branch=true + fi + setup_environment if [[ $- =~ x ]]; then @@ -465,9 +471,14 @@ main() { "$cratesio_api" \ "$cratesio_crates_owner" \ "$gh_api" \ - "$this_branch" + "$this_branch" \ + "${is_pr_branch:-}" + + local subpub_args=(publish --root "$PWD") - local subpub_args=(publish --post-check --root "$PWD") + if ! [ "${is_pr_branch:-}" ]; then + subpub_args+=(--post-check) + fi local crates_to_publish=() @@ -538,7 +549,7 @@ main() { log "No crate changes were detected for this PR" exit fi - elif [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then + elif [ "${is_pr_branch:-}" ]; then log "No file changes were detected for this PR" exit fi From fcac41f5cc009bb96901e8e123da44f55ea5faf3 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 18:06:16 -0300 Subject: [PATCH 038/109] display which crates failed the crates.io compliance check --- publish-crates | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index 54283b87..f1df9971 100755 --- a/publish-crates +++ b/publish-crates @@ -393,7 +393,7 @@ check_repository() { selected_crates=("${publishable_workspace_crates[@]}") fi - local exit_code + local failed_crates=() for crate in "${selected_crates[@]}"; do if ! check_cratesio_crate \ @@ -401,12 +401,13 @@ check_repository() { "$cratesio_api" \ "$cratesio_crates_owner" then - exit_code=1 + failed_crates+=("$crate") fi done - if [ "${exit_code:-}" ]; then - exit "$exit_code" + if [ ${#failed_crates[*]} -gt 0 ]; then + >&2 echo "The following crates failed the crates.io compliance check: ${failed_crates[*]}" + exit 1 fi } From 89cb953c7869bea3f92a9ef22c63ecebb27c5cbc Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 18:12:04 -0300 Subject: [PATCH 039/109] better variable names --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index f1df9971..fb3b023e 100755 --- a/publish-crates +++ b/publish-crates @@ -245,8 +245,8 @@ load_publishable_workspace_crates() { .[0]=="packages" and .[2]=="source" and . as $path | $in | getpath($path)==null # .source == null for workspace crates - ) as $crate_path | - del($crate_path[-1]) as $crate_path | + ) as $crate_source_path | + del($crate_source_path[-1]) as $crate_path | $in | if getpath($crate_path + ["publish"]) == null or From af210a0648df5075249075e9a1ca3bd0e1ce2e02 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 18:23:29 -0300 Subject: [PATCH 040/109] better comment --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index fb3b023e..485c6114 100755 --- a/publish-crates +++ b/publish-crates @@ -344,7 +344,7 @@ check_repository() { local selected_crates=() # if the branch belongs to a pull request, then check only the changed files - # otherwise, assume to be running on master and take all crates into account + # changed within the pull request; otherwise, take all crates into account if [ "$is_pr_branch" ]; then local pr_number="$this_branch" From 03a6f13ec80909086466bea4823157f8a7c5d787 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 7 Dec 2022 18:47:01 -0300 Subject: [PATCH 041/109] simplify exit_code check --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 485c6114..2217fcdd 100755 --- a/publish-crates +++ b/publish-crates @@ -296,12 +296,12 @@ check_cratesio_crate() { local owners_response exit_code owners_response="$(curl -sSLf "$owners_url")" || exit_code=$? - case "${exit_code:-}" in + case "${exit_code:-$?}" in 22) # 404 response, which means that the crate doesn't exist on crates.io >&2 log "Crate $crate does not yet exist on crates.io according to $owners_url. Please follow the instructions of https://github.com/paritytech/releng-scripts#reserving-crates to reserve the crate." return 1 ;; - 0|"") ;; + 0) ;; *) >&2 log "Request to $owners_url failed with exit code $exit_code" return 1 From dbfbdcb809535c19727ef85745342635e868f7bc Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 8 Dec 2022 10:51:55 -0300 Subject: [PATCH 042/109] wip: temporarily allow subpub to fail --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 2217fcdd..6efa5811 100755 --- a/publish-crates +++ b/publish-crates @@ -611,7 +611,7 @@ main() { fi setup_subpub - subpub "${subpub_args[@]}" + subpub "${subpub_args[@]}" || : } main "$@" From dd54b406bd57a080faf1ac06297d6cd4b021a0ce Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 8 Dec 2022 10:52:39 -0300 Subject: [PATCH 043/109] wip: temporarily allow subpub to fail --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 6efa5811..68a84abd 100755 --- a/publish-crates +++ b/publish-crates @@ -611,7 +611,7 @@ main() { fi setup_subpub - subpub "${subpub_args[@]}" || : + subpub "${subpub_args[@]}" } -main "$@" +main "$@" || : From 8a8c433551379ce26c9360655b264676e5f238c0 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 8 Dec 2022 10:57:07 -0300 Subject: [PATCH 044/109] wip: temporarily allow subpub to fail --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 68a84abd..6efa5811 100755 --- a/publish-crates +++ b/publish-crates @@ -611,7 +611,7 @@ main() { fi setup_subpub - subpub "${subpub_args[@]}" + subpub "${subpub_args[@]}" || : } -main "$@" || : +main "$@" From 76e6526ddd35acb74fbdaa2ff8129b764ef00f94 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 8 Dec 2022 10:59:36 -0300 Subject: [PATCH 045/109] use more distinctive error message for temporary errors --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 6efa5811..3b11e733 100755 --- a/publish-crates +++ b/publish-crates @@ -611,7 +611,7 @@ main() { fi setup_subpub - subpub "${subpub_args[@]}" || : + subpub "${subpub_args[@]}" || log "::SUBPUB FAILED" } main "$@" From d552ae51d02e445bfb010814f67af56653cd8eb3 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 8 Dec 2022 15:47:44 -0300 Subject: [PATCH 046/109] accept branch customization for subpub --- publish-crates | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 3b11e733..582232d3 100755 --- a/publish-crates +++ b/publish-crates @@ -172,9 +172,10 @@ setup_local_cratesio() { } setup_subpub() { + local branch="$1" cargo install --quiet \ --git https://github.com/paritytech/subpub \ - --branch releng \ + --branch "$branch" \ --root "$tmp_cargo_root" subpub --version } @@ -446,6 +447,8 @@ main() { local spub_after_publish_delay="${SPUB_AFTER_PUBLISH_DELAY:-}" # shellcheck disable=SC2153 # lowercase counterpart local spub_exclude="${SPUB_EXCLUDE:-}" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_branch="${SPUB_BRANCH:-releng}" # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" @@ -610,7 +613,7 @@ main() { mkdir -p "$SPUB_TMP" fi - setup_subpub + setup_subpub "$spub_branch" subpub "${subpub_args[@]}" || log "::SUBPUB FAILED" } From 3ff2a88cd8c4fcb2cc8a0b21b48cca50922e2abb Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 8 Dec 2022 16:18:33 -0300 Subject: [PATCH 047/109] force publishing all crates with $spub_publish_all --- publish-crates | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 582232d3..2c9ca588 100755 --- a/publish-crates +++ b/publish-crates @@ -449,6 +449,8 @@ main() { local spub_exclude="${SPUB_EXCLUDE:-}" # shellcheck disable=SC2153 # lowercase counterpart local spub_branch="${SPUB_BRANCH:-releng}" + # shellcheck disable=SC2153 # lowercase counterpart + local spub_publish_all="${SPUB_PUBLISH_ALL:-}" # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" @@ -498,7 +500,9 @@ main() { done < <(echo "$spub_publish") if [ ${#crates_to_publish[*]} -eq 0 ]; then - if [ "${changed_pr_files:-}" ]; then + if [ "$spub_publish_all" ]; then + : + elif [ "${changed_pr_files:-}" ]; then for file in "${changed_pr_files[@]}"; do local current="$file" while true; do From 5890796b0e5fa2384bb769112d973d7723e23389 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 02:03:15 -0300 Subject: [PATCH 048/109] wip: try clearing the whole cache --- publish-crates | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 2c9ca588..1208c85d 100755 --- a/publish-crates +++ b/publish-crates @@ -73,6 +73,17 @@ setup_local_cratesio() { git clone --branch releng https://github.com/paritytech/crates.io "$cratesio_repo" + local cargo_home="${CARGO_HOME:-$HOME/.cargo}" + + # clear the local registry's cache before going forward since the local + # registry will be recreated for this job + if [ -e "$cargo_home/registry" ]; then + find "$cargo_home"/registry -maxdepth 2 -type d -name "-*" -prune -exec rm -rf {} \; + fi + if [ -e "$cargo_home/git" ]; then + find "$cargo_home"/git -maxdepth 2 -type d -name "-*" -prune -exec rm -rf {} \; + fi + >/dev/null pushd "$cratesio_repo" mkdir local_uploads tmp @@ -133,7 +144,6 @@ setup_local_cratesio() { # Clear the registry's cache after a crate is committed to the remote # registry in order to force its redownload - cargo_home="${CARGO_HOME:-$HOME/.cargo}" find "$cargo_home" \ -type d -path "**/$crate-$crate_version" \ -print \ From f81489ca4c5e51fac88a772a8c69dff5a6ac3283 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 02:07:54 -0300 Subject: [PATCH 049/109] revert clearing the whole registry --- publish-crates | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/publish-crates b/publish-crates index 1208c85d..2c9ca588 100755 --- a/publish-crates +++ b/publish-crates @@ -73,17 +73,6 @@ setup_local_cratesio() { git clone --branch releng https://github.com/paritytech/crates.io "$cratesio_repo" - local cargo_home="${CARGO_HOME:-$HOME/.cargo}" - - # clear the local registry's cache before going forward since the local - # registry will be recreated for this job - if [ -e "$cargo_home/registry" ]; then - find "$cargo_home"/registry -maxdepth 2 -type d -name "-*" -prune -exec rm -rf {} \; - fi - if [ -e "$cargo_home/git" ]; then - find "$cargo_home"/git -maxdepth 2 -type d -name "-*" -prune -exec rm -rf {} \; - fi - >/dev/null pushd "$cratesio_repo" mkdir local_uploads tmp @@ -144,6 +133,7 @@ setup_local_cratesio() { # Clear the registry's cache after a crate is committed to the remote # registry in order to force its redownload + cargo_home="${CARGO_HOME:-$HOME/.cargo}" find "$cargo_home" \ -type d -path "**/$crate-$crate_version" \ -print \ From f6288de2d14e713a2c7dc4801baa5c7962c54f12 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 02:20:23 -0300 Subject: [PATCH 050/109] run cargo clean after publishing crate --- publish-crates | 1 + 1 file changed, 1 insertion(+) diff --git a/publish-crates b/publish-crates index 2c9ca588..636c9856 100755 --- a/publish-crates +++ b/publish-crates @@ -143,6 +143,7 @@ setup_local_cratesio() { -type f -path "**/$crate-$crate_version.crate" \ -print \ -exec rm -f {} \; + cargo clean -vv --manifest-path "$root/Cargo.toml" -p "$crate" echo "$crate" >> "$SPUB_CRATES_COMMITTED_FILE" else From b60b3eb9f7f6674b05b0003e241c79d6884af2b2 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 02:32:03 -0300 Subject: [PATCH 051/109] reorder CARGO_REGISTRIES_LOCAL_INDEX --- publish-crates | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 636c9856..5683d23b 100755 --- a/publish-crates +++ b/publish-crates @@ -86,6 +86,10 @@ setup_local_cratesio() { local pipe="$tmp/pipe" mkfifo "$pipe" + # CARGO_REGISTRIES_LOCAL_INDEX needs to be exported before the + # background-worker is launched since `cargo clean` relies on this variable + export CARGO_REGISTRIES_LOCAL_INDEX=file://"$cratesio_repo"/tmp/index-bare + export GIT_REPO_URL="file://$PWD/tmp/index-bare" export GH_CLIENT_ID= export GH_CLIENT_SECRET= @@ -94,6 +98,7 @@ setup_local_cratesio() { export CRATESIO_TOKEN_PREFIX="$cratesio_token_prefix" export WEB_NEW_PKG_RATE_LIMIT_BURST=10248 export CRATESIO_LOCAL_CRATES="${workspace_crates[*]}" + cargo run --quiet --bin server | while IFS= read -r line; do case "$line" in "$cratesio_token_prefix="*) @@ -168,7 +173,6 @@ setup_local_cratesio() { export SPUB_REGISTRY=local export SPUB_CRATES_API=http://localhost:8888/api/v1 - export CARGO_REGISTRIES_LOCAL_INDEX=file://"$cratesio_repo"/tmp/index-bare export SPUB_REGISTRY_TOKEN="$token" } From a0f879135f52e52b524cdc5fcf7b77504ea95647 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 02:33:32 -0300 Subject: [PATCH 052/109] exit if the crate's cache can't be cleared --- publish-crates | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 5683d23b..1391ba96 100755 --- a/publish-crates +++ b/publish-crates @@ -148,7 +148,8 @@ setup_local_cratesio() { -type f -path "**/$crate-$crate_version.crate" \ -print \ -exec rm -f {} \; - cargo clean -vv --manifest-path "$root/Cargo.toml" -p "$crate" + cargo clean -vv --manifest-path "$root/Cargo.toml" -p "$crate" \ + || die all "Failed to clear build cache for crate $crate" echo "$crate" >> "$SPUB_CRATES_COMMITTED_FILE" else From b6a1ec85b0bce7e05bbbb24c22c10b37a4daf82e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 03:05:39 -0300 Subject: [PATCH 053/109] re-enable subpub checks --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 1391ba96..d54bd331 100755 --- a/publish-crates +++ b/publish-crates @@ -624,7 +624,7 @@ main() { fi setup_subpub "$spub_branch" - subpub "${subpub_args[@]}" || log "::SUBPUB FAILED" + subpub "${subpub_args[@]}" } main "$@" From 01a39d8aef67cd173c1495bde1d60a450e3a77bc Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 9 Dec 2022 03:20:06 -0300 Subject: [PATCH 054/109] improve comments --- publish-crates | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index d54bd331..84eca4e0 100755 --- a/publish-crates +++ b/publish-crates @@ -137,7 +137,7 @@ setup_local_cratesio() { crate_version="${BASH_REMATCH[2]}" # Clear the registry's cache after a crate is committed to the remote - # registry in order to force its redownload + # registry to force its redownload cargo_home="${CARGO_HOME:-$HOME/.cargo}" find "$cargo_home" \ -type d -path "**/$crate-$crate_version" \ @@ -148,6 +148,8 @@ setup_local_cratesio() { -type f -path "**/$crate-$crate_version.crate" \ -print \ -exec rm -f {} \; + + # Clear the build cache to force the crate to be recompiled cargo clean -vv --manifest-path "$root/Cargo.toml" -p "$crate" \ || die all "Failed to clear build cache for crate $crate" From d722664c47749d119c16f16681c562ad357769a8 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Mon, 12 Dec 2022 05:40:41 -0300 Subject: [PATCH 055/109] show a diff after publishing crates --- publish-crates | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/publish-crates b/publish-crates index 84eca4e0..494cb2eb 100755 --- a/publish-crates +++ b/publish-crates @@ -462,6 +462,7 @@ main() { # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" + local initial_commit_sha="$CI_COMMIT_SHA" local is_pr_branch if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then @@ -571,10 +572,11 @@ main() { fi fi + git config --global user.name "CI" + git config --global user.email "<>" + case "$cratesio_target_instance" in local) - git config --global user.name "CI" - git config --global user.email "<>" apt update -qq setup_postgres # diesel setup should be after setup_progress because it depends on libpq @@ -626,7 +628,13 @@ main() { fi setup_subpub "$spub_branch" - subpub "${subpub_args[@]}" + + local exit_code=0 + subpub "${subpub_args[@]}" || exit_code=$? + + git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" || : + + exit "$exit_code" } main "$@" From 702cf9b60c30f444b5ca6feac9aebc23071d1014 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Mon, 12 Dec 2022 06:43:12 -0300 Subject: [PATCH 056/109] produce git diff selectively --- publish-crates | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 494cb2eb..e1f190a3 100755 --- a/publish-crates +++ b/publish-crates @@ -575,6 +575,8 @@ main() { git config --global user.name "CI" git config --global user.email "<>" + local produce_git_diff + case "$cratesio_target_instance" in local) apt update -qq @@ -586,6 +588,7 @@ main() { default) # TODO: enable it after local instance publishing works for a while on CI echo "Publishing to crates.io is temporarily disabled"; exit 0 + produce_git_diff=true export SPUB_CRATES_API=http://crates.io/api/v1 ;; *) @@ -632,7 +635,9 @@ main() { local exit_code=0 subpub "${subpub_args[@]}" || exit_code=$? - git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" || : + if [ "${produce_git_diff:-}" ]; then + git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" || : + fi exit "$exit_code" } From 49e03dbf29fdf8acda1fa014ade3aa247f8cac8e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Mon, 12 Dec 2022 14:43:30 -0300 Subject: [PATCH 057/109] quieten `cargo clean` --- publish-crates | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index e1f190a3..c6c34cf0 100755 --- a/publish-crates +++ b/publish-crates @@ -150,7 +150,9 @@ setup_local_cratesio() { -exec rm -f {} \; # Clear the build cache to force the crate to be recompiled - cargo clean -vv --manifest-path "$root/Cargo.toml" -p "$crate" \ + cargo clean --quiet \ + --manifest-path "$root/Cargo.toml" \ + -p "$crate" \ || die all "Failed to clear build cache for crate $crate" echo "$crate" >> "$SPUB_CRATES_COMMITTED_FILE" From 945cbfd0e43bfa9b50bdcb1f82223e1f8a9fe7cb Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 09:55:11 -0300 Subject: [PATCH 058/109] minor adjustments --- publish-crates | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index c6c34cf0..89447620 100755 --- a/publish-crates +++ b/publish-crates @@ -471,6 +471,9 @@ main() { is_pr_branch=true fi + git config --global user.name "CI" + git config --global user.email "<>" + setup_environment if [[ $- =~ x ]]; then @@ -574,9 +577,6 @@ main() { fi fi - git config --global user.name "CI" - git config --global user.email "<>" - local produce_git_diff case "$cratesio_target_instance" in @@ -637,7 +637,7 @@ main() { local exit_code=0 subpub "${subpub_args[@]}" || exit_code=$? - if [ "${produce_git_diff:-}" ]; then + if [ "${SPUB_TMP:-}" ] && [ "${produce_git_diff:-}" ]; then git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" || : fi From fd4742c69d12888c133db93fb088b96eca82d1b4 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 11:23:45 -0300 Subject: [PATCH 059/109] misc improvements --- publish-crates | 96 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 16 deletions(-) diff --git a/publish-crates b/publish-crates index 89447620..d7489e39 100755 --- a/publish-crates +++ b/publish-crates @@ -350,7 +350,9 @@ check_repository() { local cratesio_crates_owner="$2" local gh_api="$3" local this_branch="$4" - local is_pr_branch="$5" + local repo_owner="$5" + local repo="$6" + local is_pr_branch="$7" local selected_crates=() @@ -395,7 +397,7 @@ check_repository() { curl -sSLf \ -H "Accept: application/vnd.github.v3.diff" \ -H "Authorization: token $GITHUB_PR_TOKEN" \ - "$gh_api/repos/$REPO_OWNER/$REPO/pulls/$pr_number" \ + "$gh_api/repos/$repo_owner/$repo/pulls/$pr_number" \ || die all "Failed to get diff for PR $pr_number" ) set -x @@ -448,23 +450,22 @@ main() { # shellcheck disable=SC2153 # lowercase counterpart local cratesio_api="$CRATESIO_API" # shellcheck disable=SC2153 # lowercase counterpart - local spub_start_from="${SPUB_START_FROM:-}" + local repo_owner="$REPO_OWNER" # shellcheck disable=SC2153 # lowercase counterpart + local repo="$REPO" + local spub_start_from="${SPUB_START_FROM:-}" local spub_publish="${SPUB_PUBLISH:-}" - # shellcheck disable=SC2153 # lowercase counterpart local spub_verify_from="${SPUB_VERIFY_FROM:-}" - # shellcheck disable=SC2153 # lowercase counterpart local spub_after_publish_delay="${SPUB_AFTER_PUBLISH_DELAY:-}" - # shellcheck disable=SC2153 # lowercase counterpart local spub_exclude="${SPUB_EXCLUDE:-}" - # shellcheck disable=SC2153 # lowercase counterpart local spub_branch="${SPUB_BRANCH:-releng}" - # shellcheck disable=SC2153 # lowercase counterpart local spub_publish_all="${SPUB_PUBLISH_ALL:-}" + local github_token="${GITHUB_TOKEN:-}" # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" local initial_commit_sha="$CI_COMMIT_SHA" + local was_triggered_manually="${CI_JOB_MANUAL:-}" local is_pr_branch if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then @@ -492,6 +493,8 @@ main() { "$cratesio_crates_owner" \ "$gh_api" \ "$this_branch" \ + "$repo_owner" \ + "$repo" \ "${is_pr_branch:-}" local subpub_args=(publish --root "$PWD") @@ -577,7 +580,7 @@ main() { fi fi - local produce_git_diff + local submit_pr_base case "$cratesio_target_instance" in local) @@ -588,9 +591,14 @@ main() { setup_local_cratesio ;; default) - # TODO: enable it after local instance publishing works for a while on CI - echo "Publishing to crates.io is temporarily disabled"; exit 0 - produce_git_diff=true + if [ ! "${was_triggered_manually:-}" ]; then + # TODO: enable it after local instance publishing works for a while on CI + echo "Publishing to crates.io is temporarily disabled"; exit 0 + fi + if [ ! "$github_token" ]; then + die "\$github_token is required" + fi + submit_pr_base="$this_branch" export SPUB_CRATES_API=http://crates.io/api/v1 ;; *) @@ -634,13 +642,69 @@ main() { setup_subpub "$spub_branch" - local exit_code=0 - subpub "${subpub_args[@]}" || exit_code=$? + subpub "${subpub_args[@]}" - if [ "${SPUB_TMP:-}" ] && [ "${produce_git_diff:-}" ]; then - git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" || : + if [ "${submit_pr_base:-}" ]; then + local has_diff + if [ "${SPUB_TMP:-}" ]; then + git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" + if [ "$(wc -c < "$SPUB_TMP/after-publish.diff")" -gt 0 ]; then + has_diff=true + fi + elif [ "$(git diff "$initial_commit_sha" | wc -c)" -gt 0 ]; then + has_diff=true + fi + + if [ "${has_diff:-}" ]; then + git reset "$initial_commit_sha" + git add . + git commit -m "update dependencies after publish" + + local target_branch="publish-crates/update" + local target_remote="https://token:${github_token}@github.com/repos/$repo_owner/$repo.git" + if git remote get-url target >/dev/null; then + git remote set-url target "$target_remote" + else + git remote add target "$target_remote" + fi + git push --force target HEAD:"$target_branch" + git remote remove target + + local target_branch_filter + target_branch_filter="$(echo -n "$repo_owner:$target_branch" | jq -sRr @uri)" + local open_pr_count + open_pr_count="$(curl -sSLf \ + -H "Authorization: token $github_token" \ + "$gh_api/repos/$repo_owner/$repo/pulls?state=open&head=$target_branch_filter" | + jq -e -r '. | length' + )" + + if [ "$open_pr_count" -eq 0 ]; then + local title="Update dependencies after publish" + local body="# :exclamation: This PR is generated automatically by CI. DO NOT push commits to this PR!" + local payload + payload="$(jq -n \ + --arg title "$title" \ + --arg body "$body" \ + --arg base "$submit_pr_base" \ + --arg head "$target_branch" \ + '{ + title: $title, + body: $body, + head: $head, + base: $base + }' + )" + curl -sSLf \ + -H "Authorization: token $github_token" \ + -X POST \ + -d "$payload" \ + "$gh_api/$repo_owner/$repo/pulls" + fi + fi fi + exit "$exit_code" } From d17547f47397e4278d45cdd4279a05bf05d46a31 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 11:26:44 -0300 Subject: [PATCH 060/109] newline --- publish-crates | 1 - 1 file changed, 1 deletion(-) diff --git a/publish-crates b/publish-crates index d7489e39..5d009573 100755 --- a/publish-crates +++ b/publish-crates @@ -704,7 +704,6 @@ main() { fi fi - exit "$exit_code" } From 93b67aeed4afcbadaabb4bc60b2e7ababf6df86a Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 11:27:01 -0300 Subject: [PATCH 061/109] rm extraneous exit --- publish-crates | 2 -- 1 file changed, 2 deletions(-) diff --git a/publish-crates b/publish-crates index 5d009573..bd62fac7 100755 --- a/publish-crates +++ b/publish-crates @@ -703,8 +703,6 @@ main() { fi fi fi - - exit "$exit_code" } main "$@" From a532d7dbfb40dacff91cf395a9953bd8f17168b7 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 11:50:42 -0300 Subject: [PATCH 062/109] more strictness --- publish-crates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index bd62fac7..428f9450 100755 --- a/publish-crates +++ b/publish-crates @@ -465,7 +465,10 @@ main() { # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" local initial_commit_sha="$CI_COMMIT_SHA" - local was_triggered_manually="${CI_JOB_MANUAL:-}" + local was_triggered_manually + if [ "${CI_JOB_MANUAL:-}" == true ]; then + was_triggered_manually=true + fi local is_pr_branch if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then From 2950d5e09df9085677657d6d9cf4a2d9b61a9860 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 12:55:45 -0300 Subject: [PATCH 063/109] misc improvements --- publish-crates | 100 +++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/publish-crates b/publish-crates index 428f9450..3b161778 100755 --- a/publish-crates +++ b/publish-crates @@ -583,7 +583,7 @@ main() { fi fi - local submit_pr_base + local should_submit_pr case "$cratesio_target_instance" in local) @@ -601,7 +601,7 @@ main() { if [ ! "$github_token" ]; then die "\$github_token is required" fi - submit_pr_base="$this_branch" + should_submit_pr=true export SPUB_CRATES_API=http://crates.io/api/v1 ;; *) @@ -645,9 +645,11 @@ main() { setup_subpub "$spub_branch" - subpub "${subpub_args[@]}" + local subpub_exit_code=0 + subpub "${subpub_args[@]}" || subpub_exit_code=$? - if [ "${submit_pr_base:-}" ]; then + local has_diff + if [ ! "${is_pr_branch:-}" ]; then local has_diff if [ "${SPUB_TMP:-}" ]; then git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" @@ -657,55 +659,57 @@ main() { elif [ "$(git diff "$initial_commit_sha" | wc -c)" -gt 0 ]; then has_diff=true fi + fi - if [ "${has_diff:-}" ]; then - git reset "$initial_commit_sha" - git add . - git commit -m "update dependencies after publish" - - local target_branch="publish-crates/update" - local target_remote="https://token:${github_token}@github.com/repos/$repo_owner/$repo.git" - if git remote get-url target >/dev/null; then - git remote set-url target "$target_remote" - else - git remote add target "$target_remote" - fi - git push --force target HEAD:"$target_branch" - git remote remove target + if [ "${should_submit_pr:-}" ] && [ "${has_diff:-}" ] && [ "$subpub_exit_code" -eq 0 ]; then + git reset "$initial_commit_sha" + git add . + git commit -m "update dependencies after publish" - local target_branch_filter - target_branch_filter="$(echo -n "$repo_owner:$target_branch" | jq -sRr @uri)" - local open_pr_count - open_pr_count="$(curl -sSLf \ - -H "Authorization: token $github_token" \ - "$gh_api/repos/$repo_owner/$repo/pulls?state=open&head=$target_branch_filter" | - jq -e -r '. | length' + local target_branch="publish-crates/update" + local target_remote="https://token:$github_token@github.com/repos/$repo_owner/$repo.git" + if git remote get-url target >/dev/null; then + git remote set-url target "$target_remote" + else + git remote add target "$target_remote" + fi + git push --force target HEAD:"$target_branch" + git remote remove target + + local target_branch_filter + target_branch_filter="$(echo -n "$repo_owner:$target_branch" | jq -sRr @uri)" + local open_pr_count + open_pr_count="$(curl -sSLf \ + -H "Authorization: token $github_token" \ + "$gh_api/repos/$repo_owner/$repo/pulls?state=open&head=$target_branch_filter" | + jq -e -r '. | length' + )" + + if [ "$open_pr_count" -eq 0 ]; then + local title="Update dependencies after publish" + local body="# :exclamation: This PR is generated automatically by CI. DO NOT push commits to this PR!" + local payload + payload="$(jq -n \ + --arg title "$title" \ + --arg body "$body" \ + --arg base "$this_branch" \ + --arg head "$target_branch" \ + '{ + title: $title, + body: $body, + head: $head, + base: $base + }' )" - - if [ "$open_pr_count" -eq 0 ]; then - local title="Update dependencies after publish" - local body="# :exclamation: This PR is generated automatically by CI. DO NOT push commits to this PR!" - local payload - payload="$(jq -n \ - --arg title "$title" \ - --arg body "$body" \ - --arg base "$submit_pr_base" \ - --arg head "$target_branch" \ - '{ - title: $title, - body: $body, - head: $head, - base: $base - }' - )" - curl -sSLf \ - -H "Authorization: token $github_token" \ - -X POST \ - -d "$payload" \ - "$gh_api/$repo_owner/$repo/pulls" - fi + curl -sSLf \ + -H "Authorization: token $github_token" \ + -X POST \ + -d "$payload" \ + "$gh_api/$repo_owner/$repo/pulls" fi fi + + exit "$subpub_exit_code" } main "$@" From 668084f96266c325a419cdd9d8219af30dcc136b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 14:13:22 -0300 Subject: [PATCH 064/109] enable new flag of subpub --- publish-crates | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/publish-crates b/publish-crates index 3b161778..4248c45e 100755 --- a/publish-crates +++ b/publish-crates @@ -609,6 +609,10 @@ main() { ;; esac + if [ "${should_submit_pr:-}" ]; then + subpub_args+=(--for-pull-request) + fi + for crate_to_publish in "${crates_to_publish[@]}"; do subpub_args+=(--publish-only "$crate_to_publish") done From 8aa1bb1c3f1ae9af3c092105cd214b843caefd89 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 13 Dec 2022 14:16:57 -0300 Subject: [PATCH 065/109] s/echo/log --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 4248c45e..d8abfc25 100755 --- a/publish-crates +++ b/publish-crates @@ -419,7 +419,7 @@ check_repository() { done if [ ${#failed_crates[*]} -gt 0 ]; then - >&2 echo "The following crates failed the crates.io compliance check: ${failed_crates[*]}" + >&2 log "The following crates failed the crates.io compliance check: ${failed_crates[*]}" exit 1 fi } From 469e9c999873b65be0cf85eaad4a15eb166dfd83 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 07:40:03 -0300 Subject: [PATCH 066/109] change emphasis --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index d8abfc25..d8ae461e 100755 --- a/publish-crates +++ b/publish-crates @@ -691,7 +691,7 @@ main() { if [ "$open_pr_count" -eq 0 ]; then local title="Update dependencies after publish" - local body="# :exclamation: This PR is generated automatically by CI. DO NOT push commits to this PR!" + local body="# :exclamation: DO NOT push commits to this PR! This PR is generated automatically by CI" local payload payload="$(jq -n \ --arg title "$title" \ From 57b8859dbc7c37799601e1a6370dedd92be0e52c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 07:58:21 -0300 Subject: [PATCH 067/109] clearer PR title --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index d8ae461e..8ef57bf1 100755 --- a/publish-crates +++ b/publish-crates @@ -690,7 +690,7 @@ main() { )" if [ "$open_pr_count" -eq 0 ]; then - local title="Update dependencies after publish" + local title="[AUTOMATED] Update dependencies after publish" local body="# :exclamation: DO NOT push commits to this PR! This PR is generated automatically by CI" local payload payload="$(jq -n \ From b9350e5e945c11a2859687b176180b19633c0990 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 08:13:51 -0300 Subject: [PATCH 068/109] leverage CRATESIO_PUBLISH_TOKEN --- publish-crates | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 8ef57bf1..3be392f4 100755 --- a/publish-crates +++ b/publish-crates @@ -461,6 +461,7 @@ main() { local spub_branch="${SPUB_BRANCH:-releng}" local spub_publish_all="${SPUB_PUBLISH_ALL:-}" local github_token="${GITHUB_TOKEN:-}" + local cratesio_token="${CRATESIO_PUBLISH_TOKEN:-}" # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" @@ -598,9 +599,17 @@ main() { # TODO: enable it after local instance publishing works for a while on CI echo "Publishing to crates.io is temporarily disabled"; exit 0 fi + if [ ! "$github_token" ]; then - die "\$github_token is required" + die "\$github_token is empty" fi + + if [ "$cratesio_token" ]; then + export CARGO_REGISTRY_TOKEN="$cratesio_token" + else + die "\$cratesio_token is empty" + fi + should_submit_pr=true export SPUB_CRATES_API=http://crates.io/api/v1 ;; From a5b302128ee2057192d5b8cc983b2376016b2b26 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 08:30:07 -0300 Subject: [PATCH 069/109] misc improvements --- publish-crates | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/publish-crates b/publish-crates index 3be392f4..88c7a7d1 100755 --- a/publish-crates +++ b/publish-crates @@ -424,13 +424,6 @@ check_repository() { fi } -setup_environment() { - mkdir -p "$tmp" - export PATH="$tmp:$PATH" - mkdir -p "$tmp_cargo_root" - export PATH="$tmp_cargo_root/bin:$PATH" -} - setup_repository() { local this_file="${BASH_SOURCE[0]}" local this_file_dir="${this_file%/*}" @@ -478,8 +471,11 @@ main() { git config --global user.name "CI" git config --global user.email "<>" - - setup_environment + rm -rf "$tmp" + mkdir -p "$tmp" + export PATH="$tmp:$PATH" + mkdir -p "$tmp_cargo_root" + export PATH="$tmp_cargo_root/bin:$PATH" if [[ $- =~ x ]]; then # when -x is set up the logged messages will be printed during execution, so there's no need to @@ -584,7 +580,7 @@ main() { fi fi - local should_submit_pr + local should_submit_pr use_clean_environment case "$cratesio_target_instance" in local) @@ -610,8 +606,10 @@ main() { die "\$cratesio_token is empty" fi - should_submit_pr=true export SPUB_CRATES_API=http://crates.io/api/v1 + + should_submit_pr=true + use_clean_environment=true ;; *) die "Invalid target: $cratesio_target_instance" @@ -658,6 +656,13 @@ main() { setup_subpub "$spub_branch" + if [ "${use_clean_environment:-}" ]; then + export CARGO_TARGET_DIR="$tmp/target" + mkdir -p "$CARGO_TARGET_DIR" + export CARGO_HOME="$tmp/cargo" + mkdir -p "$CARGO_HOME" + fi + local subpub_exit_code=0 subpub "${subpub_args[@]}" || subpub_exit_code=$? From 389c04fe9eb7d036873b71a7dbea8e6cde272c90 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 08:34:58 -0300 Subject: [PATCH 070/109] s/echo/log --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 88c7a7d1..17870a6e 100755 --- a/publish-crates +++ b/publish-crates @@ -593,7 +593,7 @@ main() { default) if [ ! "${was_triggered_manually:-}" ]; then # TODO: enable it after local instance publishing works for a while on CI - echo "Publishing to crates.io is temporarily disabled"; exit 0 + log "Publishing to crates.io is temporarily disabled"; exit 0 fi if [ ! "$github_token" ]; then From dee13da04b4d61240f54b9a6346e63645df37ee9 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 09:03:20 -0300 Subject: [PATCH 071/109] wip: use commit for testing --- publish-crates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 17870a6e..03231d2f 100755 --- a/publish-crates +++ b/publish-crates @@ -591,7 +591,10 @@ main() { setup_local_cratesio ;; default) - if [ ! "${was_triggered_manually:-}" ]; then + if + [ ! "${was_triggered_manually:-}" ] && + [ "$initial_commit_sha" != "2e21c35f879e904101d8305eef7a203d95dd6cd6" ] + then # TODO: enable it after local instance publishing works for a while on CI log "Publishing to crates.io is temporarily disabled"; exit 0 fi From 5de4e08098445d1791c871a6bba6630e1a5e745c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 10:54:12 -0300 Subject: [PATCH 072/109] leverage --index-url --- publish-crates | 1 + 1 file changed, 1 insertion(+) diff --git a/publish-crates b/publish-crates index 03231d2f..439ce851 100755 --- a/publish-crates +++ b/publish-crates @@ -610,6 +610,7 @@ main() { fi export SPUB_CRATES_API=http://crates.io/api/v1 + subpub_args+=(--index-url "https://github.com/rust-lang/crates.io-index") should_submit_pr=true use_clean_environment=true From 43d455d5952551461826d87e9c842d80be924965 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 11:02:20 -0300 Subject: [PATCH 073/109] update index-url --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 439ce851..73744374 100755 --- a/publish-crates +++ b/publish-crates @@ -610,7 +610,7 @@ main() { fi export SPUB_CRATES_API=http://crates.io/api/v1 - subpub_args+=(--index-url "https://github.com/rust-lang/crates.io-index") + subpub_args+=(--index-url "https://raw.githubusercontent.com/rust-lang/crates.io-index") should_submit_pr=true use_clean_environment=true From b5a0169edc7d122e441850c82d1bedece6df600c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 11:48:18 -0300 Subject: [PATCH 074/109] enable crates.io compliance check selectively --- publish-crates | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/publish-crates b/publish-crates index 73744374..38cc4044 100755 --- a/publish-crates +++ b/publish-crates @@ -352,7 +352,8 @@ check_repository() { local this_branch="$4" local repo_owner="$5" local repo="$6" - local is_pr_branch="$7" + local has_crate_compliance_check="$7" + local is_pr_branch="$8" local selected_crates=() @@ -406,21 +407,23 @@ check_repository() { selected_crates=("${publishable_workspace_crates[@]}") fi - local failed_crates=() + if [ "$has_crate_compliance_check" ]; then + local failed_crates=() - for crate in "${selected_crates[@]}"; do - if ! check_cratesio_crate \ - "$crate" \ - "$cratesio_api" \ - "$cratesio_crates_owner" - then - failed_crates+=("$crate") - fi - done + for crate in "${selected_crates[@]}"; do + if ! check_cratesio_crate \ + "$crate" \ + "$cratesio_api" \ + "$cratesio_crates_owner" + then + failed_crates+=("$crate") + fi + done - if [ ${#failed_crates[*]} -gt 0 ]; then - >&2 log "The following crates failed the crates.io compliance check: ${failed_crates[*]}" - exit 1 + if [ ${#failed_crates[*]} -gt 0 ]; then + >&2 log "The following crates failed the crates.io compliance check: ${failed_crates[*]}" + exit 1 + fi fi } @@ -488,6 +491,17 @@ main() { setup_repository + local has_crate_compliance_check + case "$cratesio_target_instance" in + local) + has_crate_compliance_check=true + ;; + default) ;; + *) + die "Invalid target: $cratesio_target_instance" + ;; + esac + check_repository \ "$cratesio_api" \ "$cratesio_crates_owner" \ @@ -495,6 +509,7 @@ main() { "$this_branch" \ "$repo_owner" \ "$repo" \ + "${has_crate_compliance_check:-}" \ "${is_pr_branch:-}" local subpub_args=(publish --root "$PWD") From 30d0ab9f09cab5eb6233d516bb100ff3bc952b46 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 11:49:06 -0300 Subject: [PATCH 075/109] better variable name --- publish-crates | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/publish-crates b/publish-crates index 38cc4044..999b2ea3 100755 --- a/publish-crates +++ b/publish-crates @@ -352,7 +352,7 @@ check_repository() { local this_branch="$4" local repo_owner="$5" local repo="$6" - local has_crate_compliance_check="$7" + local check_for_crate_compliance="$7" local is_pr_branch="$8" local selected_crates=() @@ -407,7 +407,7 @@ check_repository() { selected_crates=("${publishable_workspace_crates[@]}") fi - if [ "$has_crate_compliance_check" ]; then + if [ "$check_for_crate_compliance" ]; then local failed_crates=() for crate in "${selected_crates[@]}"; do @@ -491,10 +491,10 @@ main() { setup_repository - local has_crate_compliance_check + local check_for_crate_compliance case "$cratesio_target_instance" in local) - has_crate_compliance_check=true + check_for_crate_compliance=true ;; default) ;; *) @@ -509,7 +509,7 @@ main() { "$this_branch" \ "$repo_owner" \ "$repo" \ - "${has_crate_compliance_check:-}" \ + "${check_for_crate_compliance:-}" \ "${is_pr_branch:-}" local subpub_args=(publish --root "$PWD") From cc36e94927e36d61c7e35d62da006f7e98e77d27 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 12:17:04 -0300 Subject: [PATCH 076/109] leverage --index-api --- publish-crates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 999b2ea3..552f986f 100755 --- a/publish-crates +++ b/publish-crates @@ -625,7 +625,10 @@ main() { fi export SPUB_CRATES_API=http://crates.io/api/v1 - subpub_args+=(--index-url "https://raw.githubusercontent.com/rust-lang/crates.io-index") + subpub_args+=( + --index-api "$gh_api/rust-lang/crates.io-index" + --index-api-token "$github_token" + ) should_submit_pr=true use_clean_environment=true From 5766df9637735d29ec97190db60a1642046d2c6b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 12:34:31 -0300 Subject: [PATCH 077/109] tweak subpub args --- publish-crates | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 552f986f..f671bdcd 100755 --- a/publish-crates +++ b/publish-crates @@ -627,7 +627,8 @@ main() { export SPUB_CRATES_API=http://crates.io/api/v1 subpub_args+=( --index-api "$gh_api/rust-lang/crates.io-index" - --index-api-token "$github_token" + --index-api-auth-header "token $github_token" + --index-api-accept-header "application/vnd.github.v3.raw" ) should_submit_pr=true From 982ba2db4b5da8b72bca16fe70ef5d42f8eda9a0 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 13:19:28 -0300 Subject: [PATCH 078/109] leverage --index-url and --index-repository --- publish-crates | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/publish-crates b/publish-crates index f671bdcd..2dbc8feb 100755 --- a/publish-crates +++ b/publish-crates @@ -626,9 +626,8 @@ main() { export SPUB_CRATES_API=http://crates.io/api/v1 subpub_args+=( - --index-api "$gh_api/rust-lang/crates.io-index" - --index-api-auth-header "token $github_token" - --index-api-accept-header "application/vnd.github.v3.raw" + --index-url "https://raw.githubusercontent.com/rust-lang/crates.io-index" + --index-repository "https://github.com/rust-lang/crates.io-index" ) should_submit_pr=true From 291d8f620b1af2e93f3c1ff4c47c63bbbc5d7f9f Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 13:36:00 -0300 Subject: [PATCH 079/109] leverage --clear-cargo-home --- publish-crates | 1 + 1 file changed, 1 insertion(+) diff --git a/publish-crates b/publish-crates index 2dbc8feb..64e32811 100755 --- a/publish-crates +++ b/publish-crates @@ -683,6 +683,7 @@ main() { mkdir -p "$CARGO_TARGET_DIR" export CARGO_HOME="$tmp/cargo" mkdir -p "$CARGO_HOME" + subpub_args+=(--clear-cargo-home "$CARGO_HOME") fi local subpub_exit_code=0 From ba350266d4f8060065eb7a4c12eee93bec8e3711 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 13:40:07 -0300 Subject: [PATCH 080/109] comment --- publish-crates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 64e32811..382db84d 100755 --- a/publish-crates +++ b/publish-crates @@ -496,7 +496,10 @@ main() { local) check_for_crate_compliance=true ;; - default) ;; + default) + # compliance is not checked for this target because we assume it has + # already been checked for the local target test + ;; *) die "Invalid target: $cratesio_target_instance" ;; From 5be272dded5fa3e9b6c7cd55db6bc910cd66d925 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 13:46:25 -0300 Subject: [PATCH 081/109] comment --- publish-crates | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 382db84d..27b87ffd 100755 --- a/publish-crates +++ b/publish-crates @@ -686,7 +686,11 @@ main() { mkdir -p "$CARGO_TARGET_DIR" export CARGO_HOME="$tmp/cargo" mkdir -p "$CARGO_HOME" - subpub_args+=(--clear-cargo-home "$CARGO_HOME") + subpub_args+=( + # clearing $CARGO_HOME is useful to force cargo to redownload the + # crates.io index after crates are published + --clear-cargo-home "$CARGO_HOME" + ) fi local subpub_exit_code=0 From be698c6594eee065fc207b5c53953a2e663faa78 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 20:35:29 -0300 Subject: [PATCH 082/109] fix --- publish-crates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 27b87ffd..da6a1a75 100755 --- a/publish-crates +++ b/publish-crates @@ -701,7 +701,10 @@ main() { local has_diff if [ "${SPUB_TMP:-}" ]; then git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" - if [ "$(wc -c < "$SPUB_TMP/after-publish.diff")" -gt 0 ]; then + if + [ -e "$SPUB_TMP/after-publish.diff" ] && + [ "$(wc -c < "$SPUB_TMP/after-publish.diff")" -gt 0 ] + then has_diff=true fi elif [ "$(git diff "$initial_commit_sha" | wc -c)" -gt 0 ]; then From d9947ce40bedf294b30cb98b48e77636b75c3c85 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 21:51:59 -0300 Subject: [PATCH 083/109] post-check only for local target --- publish-crates | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index da6a1a75..dff33ec5 100755 --- a/publish-crates +++ b/publish-crates @@ -517,10 +517,6 @@ main() { local subpub_args=(publish --root "$PWD") - if ! [ "${is_pr_branch:-}" ]; then - subpub_args+=(--post-check) - fi - local crates_to_publish=() while IFS= read -r crate; do @@ -602,6 +598,10 @@ main() { case "$cratesio_target_instance" in local) + if [ ! "${is_pr_branch:-}" ]; then + subpub_args+=(--post-check) + fi + apt update -qq setup_postgres # diesel setup should be after setup_progress because it depends on libpq From 38ed1a7a4d55c83cdf8f8be2d8b2a14597c12150 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 21:56:01 -0300 Subject: [PATCH 084/109] refactor diff handling --- publish-crates | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/publish-crates b/publish-crates index dff33ec5..c267c67e 100755 --- a/publish-crates +++ b/publish-crates @@ -697,17 +697,16 @@ main() { subpub "${subpub_args[@]}" || subpub_exit_code=$? local has_diff + if [ ! "${is_pr_branch:-}" ]; then - local has_diff + local diff + diff="$(git diff "$initial_commit_sha")" + if [ "${SPUB_TMP:-}" ]; then - git diff "$initial_commit_sha" > "$SPUB_TMP/after-publish.diff" - if - [ -e "$SPUB_TMP/after-publish.diff" ] && - [ "$(wc -c < "$SPUB_TMP/after-publish.diff")" -gt 0 ] - then - has_diff=true - fi - elif [ "$(git diff "$initial_commit_sha" | wc -c)" -gt 0 ]; then + echo "$diff" > "$SPUB_TMP/after-publish.diff" + fi + + if [ ${#diff} -gt 0 ]; then has_diff=true fi fi From 516a152196bc13e50c9a1359c9d3b56fec16e5e2 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 22:08:34 -0300 Subject: [PATCH 085/109] fix usage of $SPUB_TMP --- publish-crates | 1 + 1 file changed, 1 insertion(+) diff --git a/publish-crates b/publish-crates index c267c67e..ed085af0 100755 --- a/publish-crates +++ b/publish-crates @@ -703,6 +703,7 @@ main() { diff="$(git diff "$initial_commit_sha")" if [ "${SPUB_TMP:-}" ]; then + mkdir -p "$SPUB_TMP" echo "$diff" > "$SPUB_TMP/after-publish.diff" fi From e1d0c9a16f93167695c99aa9c1a06013b8c6c74c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 22:21:45 -0300 Subject: [PATCH 086/109] fix remote url --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index ed085af0..1eeed46a 100755 --- a/publish-crates +++ b/publish-crates @@ -718,7 +718,7 @@ main() { git commit -m "update dependencies after publish" local target_branch="publish-crates/update" - local target_remote="https://token:$github_token@github.com/repos/$repo_owner/$repo.git" + local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" if git remote get-url target >/dev/null; then git remote set-url target "$target_remote" else From d279f4281a2c1a42f597af365c24cf569b243e3c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 14 Dec 2022 22:32:43 -0300 Subject: [PATCH 087/109] quieten git commands --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 1eeed46a..7bd1194c 100755 --- a/publish-crates +++ b/publish-crates @@ -713,9 +713,9 @@ main() { fi if [ "${should_submit_pr:-}" ] && [ "${has_diff:-}" ] && [ "$subpub_exit_code" -eq 0 ]; then - git reset "$initial_commit_sha" + git reset -q "$initial_commit_sha" git add . - git commit -m "update dependencies after publish" + git commit -q -m "update dependencies after publish" local target_branch="publish-crates/update" local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" From 5d1865586cdf75fc8e67ea3f5904a84b82b7d257 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 10:11:22 -0300 Subject: [PATCH 088/109] better variable name --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 7bd1194c..e776f5d1 100755 --- a/publish-crates +++ b/publish-crates @@ -450,7 +450,7 @@ main() { # shellcheck disable=SC2153 # lowercase counterpart local repo="$REPO" local spub_start_from="${SPUB_START_FROM:-}" - local spub_publish="${SPUB_PUBLISH:-}" + local spub_publish_only="${SPUB_PUBLISH_ONLY:-}" local spub_verify_from="${SPUB_VERIFY_FROM:-}" local spub_after_publish_delay="${SPUB_AFTER_PUBLISH_DELAY:-}" local spub_exclude="${SPUB_EXCLUDE:-}" @@ -528,7 +528,7 @@ main() { else die "Crate name had unexpected format: $crate" fi - done < <(echo "$spub_publish") + done < <(echo "$spub_publish_only") if [ ${#crates_to_publish[*]} -eq 0 ]; then if [ "$spub_publish_all" ]; then From b346fd6692f3d1ed4ca72cb4358b4165bd11718e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 11:21:53 -0300 Subject: [PATCH 089/109] revert hardcoded commit --- publish-crates | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/publish-crates b/publish-crates index e776f5d1..c6e2da65 100755 --- a/publish-crates +++ b/publish-crates @@ -609,10 +609,7 @@ main() { setup_local_cratesio ;; default) - if - [ ! "${was_triggered_manually:-}" ] && - [ "$initial_commit_sha" != "2e21c35f879e904101d8305eef7a203d95dd6cd6" ] - then + if [ ! "${was_triggered_manually:-}" ]; then # TODO: enable it after local instance publishing works for a while on CI log "Publishing to crates.io is temporarily disabled"; exit 0 fi From fdd1defb32195ed4bf4931c20183ca5bc08a12be Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 15:37:55 -0300 Subject: [PATCH 090/109] disable -x before exiting the script --- publish-crates | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index c6e2da65..90917af4 100755 --- a/publish-crates +++ b/publish-crates @@ -26,8 +26,12 @@ yj="$tmp/yj" on_exit() { local exit_code=$? + + set +x + rm -rf "$tmp" pkill -P "$$" || : + exit $exit_code } trap on_exit EXIT @@ -35,6 +39,8 @@ trap on_exit EXIT die() { local exit_code=$? + set +x + local kill_group if [ "${2:-}" ]; then case "$1" in @@ -50,7 +56,7 @@ die() { fi if [ "${1:-}" ]; then - >&2 log "$1" + >&2 echo "$1" fi if [ "${kill_group:-}" ]; then From a80bb160faff25f3dd7e25f251b4ca03554001ee Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 16:44:06 -0300 Subject: [PATCH 091/109] set the branch name --- publish-crates | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 90917af4..5b209b2f 100755 --- a/publish-crates +++ b/publish-crates @@ -721,13 +721,15 @@ main() { git commit -q -m "update dependencies after publish" local target_branch="publish-crates/update" + git branch -m "target_branch" + local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" if git remote get-url target >/dev/null; then git remote set-url target "$target_remote" else git remote add target "$target_remote" fi - git push --force target HEAD:"$target_branch" + git push --force target HEAD git remote remove target local target_branch_filter From d5a3c547bca8569c07091c6fc408d0e682daae01 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:07:50 -0300 Subject: [PATCH 092/109] fix typo --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 5b209b2f..be4a512c 100755 --- a/publish-crates +++ b/publish-crates @@ -721,7 +721,7 @@ main() { git commit -q -m "update dependencies after publish" local target_branch="publish-crates/update" - git branch -m "target_branch" + git branch -m "$target_branch" local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" if git remote get-url target >/dev/null; then From da1c722353bca4023c6e3b1b0470553ca47d8ecd Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:09:52 -0300 Subject: [PATCH 093/109] add $SPUB_TMP to ignored files --- publish-crates | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index be4a512c..8edd689e 100755 --- a/publish-crates +++ b/publish-crates @@ -437,7 +437,13 @@ setup_repository() { local this_file="${BASH_SOURCE[0]}" local this_file_dir="${this_file%/*}" local this_file_dirname="${this_file_dir##*/}" - echo "/.tmp"$'\n'"/$this_file_dirname" > "$tmp/.gitignore" + + local ignores="/.tmp"$'\n'"/$this_file_dirname" + if [ "${SPUB_TMP:-}" ]; then + ignores+=$'\n'"$SPUB_TMP" + fi + echo "$ignores" > "$tmp/.gitignore" + git config core.excludesFile "$tmp/.gitignore" } From bc2394ffcecb996ba7d9ea16039e388f6d47773d Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:24:09 -0300 Subject: [PATCH 094/109] fix push command --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index 8edd689e..6ef70078 100755 --- a/publish-crates +++ b/publish-crates @@ -726,7 +726,7 @@ main() { git add . git commit -q -m "update dependencies after publish" - local target_branch="publish-crates/update" + local target_branch="ci-crates-publishing-update" git branch -m "$target_branch" local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" @@ -735,7 +735,7 @@ main() { else git remote add target "$target_remote" fi - git push --force target HEAD + git push --force target "$target_branch" git remote remove target local target_branch_filter From 0fd98f774d7ab8c9db7ced77edfb85ddaf17646b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:29:07 -0300 Subject: [PATCH 095/109] clear SPUB_TMP before starting --- publish-crates | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 6ef70078..bd7e6435 100755 --- a/publish-crates +++ b/publish-crates @@ -440,7 +440,7 @@ setup_repository() { local ignores="/.tmp"$'\n'"/$this_file_dirname" if [ "${SPUB_TMP:-}" ]; then - ignores+=$'\n'"$SPUB_TMP" + ignores+=$'\n'"/$SPUB_TMP" fi echo "$ignores" > "$tmp/.gitignore" @@ -685,6 +685,7 @@ main() { if [ "${SPUB_TMP:: 1}" != '/' ]; then export SPUB_TMP="$PWD/$SPUB_TMP" fi + rm -rf "$SPUB_TMP" mkdir -p "$SPUB_TMP" fi From dcbd2887d1d2e38360e771eb7f938e0dc46109ad Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:34:50 -0300 Subject: [PATCH 096/109] update title and body --- publish-crates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index bd7e6435..4c08631b 100755 --- a/publish-crates +++ b/publish-crates @@ -749,8 +749,8 @@ main() { )" if [ "$open_pr_count" -eq 0 ]; then - local title="[AUTOMATED] Update dependencies after publish" - local body="# :exclamation: DO NOT push commits to this PR! This PR is generated automatically by CI" + local title="[AUTOMATED] Update crate versions after publish" + local body="# :exclamation: DO NOT push commits to this PR! This PR is generated automatically through CI" local payload payload="$(jq -n \ --arg title "$title" \ From aa4b4c0d955367d62b27839381310728455f0091 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:35:57 -0300 Subject: [PATCH 097/109] update checkout command --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 4c08631b..2de1f72b 100755 --- a/publish-crates +++ b/publish-crates @@ -728,7 +728,7 @@ main() { git commit -q -m "update dependencies after publish" local target_branch="ci-crates-publishing-update" - git branch -m "$target_branch" + git checkout -b "$target_branch" local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" if git remote get-url target >/dev/null; then From adb331ba1c6f70a4b29021a6525d4e5cb47e225e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:57:14 -0300 Subject: [PATCH 098/109] fix PR API url --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 2de1f72b..15084532 100755 --- a/publish-crates +++ b/publish-crates @@ -768,7 +768,7 @@ main() { -H "Authorization: token $github_token" \ -X POST \ -d "$payload" \ - "$gh_api/$repo_owner/$repo/pulls" + "$gh_api/repos/$repo_owner/$repo/pulls" fi fi From d35f3a76d0bb496fc49e5f3ed6130182e36d1d81 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 17:57:58 -0300 Subject: [PATCH 099/109] enable it for all master pushes --- publish-crates | 9 --------- 1 file changed, 9 deletions(-) diff --git a/publish-crates b/publish-crates index 15084532..515a537b 100755 --- a/publish-crates +++ b/publish-crates @@ -474,10 +474,6 @@ main() { # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" local initial_commit_sha="$CI_COMMIT_SHA" - local was_triggered_manually - if [ "${CI_JOB_MANUAL:-}" == true ]; then - was_triggered_manually=true - fi local is_pr_branch if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then @@ -621,11 +617,6 @@ main() { setup_local_cratesio ;; default) - if [ ! "${was_triggered_manually:-}" ]; then - # TODO: enable it after local instance publishing works for a while on CI - log "Publishing to crates.io is temporarily disabled"; exit 0 - fi - if [ ! "$github_token" ]; then die "\$github_token is empty" fi From 67405de75821e988c1a1302816bc9a42c7f16584 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:00:32 -0300 Subject: [PATCH 100/109] attach generation source to commit message --- publish-crates | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 515a537b..dd204e8f 100755 --- a/publish-crates +++ b/publish-crates @@ -474,6 +474,8 @@ main() { # Variables inherited from GitLab CI local this_branch="$CI_COMMIT_REF_NAME" local initial_commit_sha="$CI_COMMIT_SHA" + # shellcheck disable=SC2153 # lowercase counterpart + local ci_job_url="$CI_JOB_URL" local is_pr_branch if [[ "$this_branch" =~ ^[[:digit:]]+$ ]]; then @@ -716,7 +718,7 @@ main() { if [ "${should_submit_pr:-}" ] && [ "${has_diff:-}" ] && [ "$subpub_exit_code" -eq 0 ]; then git reset -q "$initial_commit_sha" git add . - git commit -q -m "update dependencies after publish" + git commit -q -m "update dependencies after publish" -m "generated from $ci_job_url" local target_branch="ci-crates-publishing-update" git checkout -b "$target_branch" From dcb1057fac0c9fe99d5c3456af38c9dab9c0d544 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:16:14 -0300 Subject: [PATCH 101/109] exclude crate-docs --- publish-crates | 2 ++ 1 file changed, 2 insertions(+) diff --git a/publish-crates b/publish-crates index dd204e8f..d951b455 100755 --- a/publish-crates +++ b/publish-crates @@ -717,6 +717,8 @@ main() { if [ "${should_submit_pr:-}" ] && [ "${has_diff:-}" ] && [ "$subpub_exit_code" -eq 0 ]; then git reset -q "$initial_commit_sha" + # some other job is saving artifacts to crate-docs ?? + rm -rf crate-docs git add . git commit -q -m "update dependencies after publish" -m "generated from $ci_job_url" From 12acd8a1be344a9f281dedf0091c0c92bf9a01ef Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:17:39 -0300 Subject: [PATCH 102/109] disable automatic publishing --- publish-crates | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/publish-crates b/publish-crates index d951b455..5200cd48 100755 --- a/publish-crates +++ b/publish-crates @@ -619,6 +619,10 @@ main() { setup_local_cratesio ;; default) + if [ "${CI_JOB_MANUAL:-}" != true ]; then + log "Automatic publishing is temporarily disabled"; exit 0 + fi + if [ ! "$github_token" ]; then die "\$github_token is empty" fi From 9b5de2042f1176028e939fe0c142bcd3a880c165 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:30:27 -0300 Subject: [PATCH 103/109] remove $target_branch if it exists --- publish-crates | 3 +++ 1 file changed, 3 insertions(+) diff --git a/publish-crates b/publish-crates index 5200cd48..26d2c5eb 100755 --- a/publish-crates +++ b/publish-crates @@ -727,6 +727,9 @@ main() { git commit -q -m "update dependencies after publish" -m "generated from $ci_job_url" local target_branch="ci-crates-publishing-update" + if git rev-parse --verify "$target_branch" >/dev/null; then + git branch -D "$target_branch" + fi git checkout -b "$target_branch" local target_remote="https://token:$github_token@github.com/$repo_owner/$repo.git" From d8874fcbe915de656fefb962f8246c5150ce2bfa Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:31:21 -0300 Subject: [PATCH 104/109] remove stale artifacts workaround --- publish-crates | 2 -- 1 file changed, 2 deletions(-) diff --git a/publish-crates b/publish-crates index 26d2c5eb..2b19f917 100755 --- a/publish-crates +++ b/publish-crates @@ -721,8 +721,6 @@ main() { if [ "${should_submit_pr:-}" ] && [ "${has_diff:-}" ] && [ "$subpub_exit_code" -eq 0 ]; then git reset -q "$initial_commit_sha" - # some other job is saving artifacts to crate-docs ?? - rm -rf crate-docs git add . git commit -q -m "update dependencies after publish" -m "generated from $ci_job_url" From ec198682487ff25711a78eb39047c89d7d24631b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:46:42 -0300 Subject: [PATCH 105/109] re-enable automatic publishing for master --- publish-crates | 4 ---- 1 file changed, 4 deletions(-) diff --git a/publish-crates b/publish-crates index 2b19f917..c5d97309 100755 --- a/publish-crates +++ b/publish-crates @@ -619,10 +619,6 @@ main() { setup_local_cratesio ;; default) - if [ "${CI_JOB_MANUAL:-}" != true ]; then - log "Automatic publishing is temporarily disabled"; exit 0 - fi - if [ ! "$github_token" ]; then die "\$github_token is empty" fi From 5e5f8a6d86d66661443525165066d0198eaf832e Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Thu, 15 Dec 2022 18:54:21 -0300 Subject: [PATCH 106/109] comment on --clear-cargo-home --- publish-crates | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/publish-crates b/publish-crates index c5d97309..608f1674 100755 --- a/publish-crates +++ b/publish-crates @@ -690,8 +690,11 @@ main() { export CARGO_HOME="$tmp/cargo" mkdir -p "$CARGO_HOME" subpub_args+=( - # clearing $CARGO_HOME is useful to force cargo to redownload the - # crates.io index after crates are published + # Clearing $CARGO_HOME is needed to force cargo to redownload the + # crates.io index after crates are published. + # TODO: doing this introduces a lot of delay since the crates.io index has + # to be redownloaded after each crate is published. We should find a + # sensible workaround which isn't about nuking the registry cache. --clear-cargo-home "$CARGO_HOME" ) fi From 368f393e4d98a56cc30f35b838233bd125aa545b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 16 Dec 2022 08:48:00 -0300 Subject: [PATCH 107/109] better PR description --- publish-crates | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 608f1674..422043a9 100755 --- a/publish-crates +++ b/publish-crates @@ -749,7 +749,15 @@ main() { if [ "$open_pr_count" -eq 0 ]; then local title="[AUTOMATED] Update crate versions after publish" - local body="# :exclamation: DO NOT push commits to this PR! This PR is generated automatically through CI" + local body=" +# :exclamation: DO NOT push commits to this PR! This PR was created automatically through CI + +This PR includes crate version updates after they were published to crates.io by the publishing automation. + +After the publishing works on \`master\` this PR's branch will automatically be **forced pushed to** with the version updates on top of the latest \`master\` commit. **You should not push commits to this PR** since they'll be overwritten by the force push. If you need to fix anything, instead branch off this PR's branch and create a new PR. + +For additional context see https://github.com/paritytech/releng-scripts/wiki/Crates-publishing-automation#toc. +" local payload payload="$(jq -n \ --arg title "$title" \ From 0783f88a6b3b234cfe87858332f9d84e48d4642b Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Mon, 19 Dec 2022 08:01:55 -0300 Subject: [PATCH 108/109] improve description --- publish-crates | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 422043a9..367f8c42 100755 --- a/publish-crates +++ b/publish-crates @@ -754,7 +754,9 @@ main() { This PR includes crate version updates after they were published to crates.io by the publishing automation. -After the publishing works on \`master\` this PR's branch will automatically be **forced pushed to** with the version updates on top of the latest \`master\` commit. **You should not push commits to this PR** since they'll be overwritten by the force push. If you need to fix anything, instead branch off this PR's branch and create a new PR. +After the publishing works on \`master\` this PR's branch will automatically be **forced pushed to** with crate version updates on top of the latest \`master\` commit. **You should not push commits to this PR** since they would be overwritten by the force push. If you need to fix anything, instead branch off this PR's branch and create a new PR. + +Note: it's expected for crate versions to increase past a single version in the diff because a crate might change on \`master\` multiple times, and therefore be bumped and republished multiple times, until this PR is merged. Visit \`https://crates.io/crates/\$CRATE/versions\` if you want to see for yourself that all the versions in-between were indeed published. For additional context see https://github.com/paritytech/releng-scripts/wiki/Crates-publishing-automation#toc. " From 46971cd2b2844381b3de5ae199e41ff8d4af1816 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 20 Dec 2022 16:59:47 -0300 Subject: [PATCH 109/109] improve PR description --- publish-crates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-crates b/publish-crates index 367f8c42..5a4667ab 100755 --- a/publish-crates +++ b/publish-crates @@ -756,7 +756,7 @@ This PR includes crate version updates after they were published to crates.io by After the publishing works on \`master\` this PR's branch will automatically be **forced pushed to** with crate version updates on top of the latest \`master\` commit. **You should not push commits to this PR** since they would be overwritten by the force push. If you need to fix anything, instead branch off this PR's branch and create a new PR. -Note: it's expected for crate versions to increase past a single version in the diff because a crate might change on \`master\` multiple times, and therefore be bumped and republished multiple times, until this PR is merged. Visit \`https://crates.io/crates/\$CRATE/versions\` if you want to see for yourself that all the versions in-between were indeed published. +Note: it's normal for crate versions to increase past a single version in the diff because a crate might be republished from \`master\` *multiple times* before this PR is merged. Visit \`https://crates.io/crates/\$CRATE/versions\` if you want to see for yourself that all the versions in-between were indeed published. For additional context see https://github.com/paritytech/releng-scripts/wiki/Crates-publishing-automation#toc. "