From c603049a72cbc89071983b225c7bb4b10a9a724c Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 6 Feb 2023 16:35:32 +0100 Subject: [PATCH 1/7] chore: clean up deprecated set-output --- .github/workflows/automerge.yml | 4 ++-- .github/workflows/check-3rd-party.yml | 2 +- .github/workflows/dispatch.yml | 10 +++++----- .github/workflows/stale-repos.yml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 5fd9e162..6bc3058b 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -27,11 +27,11 @@ jobs: echo "Committer: $committer" if [[ "$committer" != "web3-bot@users.noreply.github.com" ]]; then echo "Commit $commit wasn't committed by web3-bot, but by $committer." - echo "::set-output name=status::false" + echo "status=false" >> $GITHUB_OUTPUT exit fi done - echo "::set-output name=status::true" + echo "status=true" >> $GITHUB_OUTPUT automerge: needs: automerge-check runs-on: ubuntu-latest diff --git a/.github/workflows/check-3rd-party.yml b/.github/workflows/check-3rd-party.yml index 36203b6a..f04459e3 100644 --- a/.github/workflows/check-3rd-party.yml +++ b/.github/workflows/check-3rd-party.yml @@ -15,7 +15,7 @@ jobs: - id: set-matrix run: | TARGETS=$(find . -type f -name "*.yml" | sed "s|^\./||" | grep -v workflow-templates/header.yml | jq -R -s -c 'split("\n")[:-1]') - echo "::set-output name=targets::$TARGETS" + echo "targets=$TARGETS" >> $GITHUB_OUTPUT check: needs: [ matrix ] runs-on: ubuntu-latest diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index c90712da..9f23f921 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -8,8 +8,8 @@ on: push: branches: [ master, testing ] workflow_dispatch: - -concurrency: + +concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -53,7 +53,7 @@ jobs: echo "::endgroup::" done batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< "${targets[@]}") - echo "::set-output name=batches::$batches" + echo "batches=$batches" >> $GITHUB_OUTPUT dispatch: needs: [ matrix ] name: Dispatch copy workflow(batch ${{ matrix.cfg.key }}) @@ -86,7 +86,7 @@ jobs: start_date="$(date +%s)" # 2 toJson calls are needed to turn the array of targets into a string echo '{"targets":${{ toJson(toJson(matrix.cfg.value)) }}}' | jq -c '.' | gh workflow run "${{ env.WORKFLOW_YML }}" --ref "${{ github.ref }}" --repo "${{ env.WORKFLOW_REPO }}" --json - echo "::set-output name=start_date::$start_date" + echo "start_date=$start_date" >> $GITHUB_OUTPUT - id: run name: Wait for copy workflow run to start run: | @@ -97,7 +97,7 @@ jobs: if [[ ! -z "$run" ]]; then run_start_date="$(date --date="$(jq -r '.created_at' <<< "$run")" +%s)" if [[ "$run_start_date" > "${{ steps.dispatch.outputs.start_date }}" ]]; then - echo "::set-output name=id::$(jq -r '.id' <<< "$run")" + echo "id=$(jq -r '.id' <<< "$run")" >> $GITHUB_OUTPUT break fi fi diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index b0258bb8..090ea038 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -33,7 +33,7 @@ jobs: repos="$(jq -nc '$head - $base' --argjson head "$repos" --argjson base "$base")" fi - echo "::set-output name=repos::$repos" + echo "repos=$repos" >> $GITHUB_OUTPUT - name: find deleted / archived repositories if: ${{ steps.repos.outputs.repos != '[]' }} run: | From aa6757fb1a2127bf02ec23b982cb81e320dd5eb3 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 6 Feb 2023 16:53:30 +0100 Subject: [PATCH 2/7] chore: do not use substitution inside run --- .github/workflows/add-label-by-query.yml | 2 +- .github/workflows/automerge.yml | 9 ++++++--- .github/workflows/check-3rd-party.yml | 4 +++- .github/workflows/copy-workflow.yml | 16 +++++++++------- .github/workflows/create-prs.yml | 6 +++--- .github/workflows/dispatch.yml | 19 +++++++++++++------ .github/workflows/releaser.yml | 14 +++++++++----- .github/workflows/stale-repos.yml | 17 +++++++++++------ .github/workflows/tagpush.yml | 12 +++++++----- templates/.github/workflows/go-test.yml | 2 +- .../.github/workflows/js-test-and-release.yml | 2 +- 11 files changed, 64 insertions(+), 39 deletions(-) diff --git a/.github/workflows/add-label-by-query.yml b/.github/workflows/add-label-by-query.yml index 26fc7146..2b5b16e6 100644 --- a/.github/workflows/add-label-by-query.yml +++ b/.github/workflows/add-label-by-query.yml @@ -22,7 +22,7 @@ jobs: steps: - name: Add label by query env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} QUERY: ${{ github.event.inputs.query }} LABEL: ${{ github.event.inputs.label }} DRY_RUN: ${{ github.event.inputs.dry-run }} diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 6bc3058b..ba91bdb5 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -21,8 +21,11 @@ jobs: fetch-depth: 0 - name: Check if we should automerge id: should-automerge + env: + BASE_REF: ${{ github.event.pull_request.base.ref }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | - for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do + for commit in $(git rev-list --first-parent origin/$BASE_REF..$HEAD_SHA); do committer=$(git show --format=$'%ce' -s $commit) echo "Committer: $committer" if [[ "$committer" != "web3-bot@users.noreply.github.com" ]]; then @@ -43,13 +46,13 @@ jobs: uses: lewagon/wait-on-check-action@3a563271c3f8d1611ed7352809303617ee7e54ac # v1.2.0 with: ref: ${{ github.event.pull_request.head.sha }} - repo-token: ${{ secrets.GITHUB_TOKEN }} + repo-token: ${{ github.token }} wait-interval: 10 running-workflow-name: '${{ inputs.job }} / ${{ github.job }}' # the name of the check for this job - name: Merge PR uses: pascalgn/automerge-action@eb68b061739cb9d81564f8e812d0b3c45f0fb09a # v0.15.5 env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ github.token }}" MERGE_LABELS: "" MERGE_METHOD: "squash" MERGE_DELETE_BRANCH: true diff --git a/.github/workflows/check-3rd-party.yml b/.github/workflows/check-3rd-party.yml index f04459e3..23bb1b48 100644 --- a/.github/workflows/check-3rd-party.yml +++ b/.github/workflows/check-3rd-party.yml @@ -27,4 +27,6 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run check - run: .github/workflows/check-3rd-party.sh ${{ matrix.file }} + env: + FILE: ${{ matrix.file }} + run: .github/workflows/check-3rd-party.sh $FILE diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 2eaa2163..2390f470 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -53,16 +53,17 @@ jobs: - name: determine files to add # By setting the environment variable, it's possible to programmatically add / modify this list. # See https://github.com/protocol/.github/blob/38135c75e47839623bf9b2748275d8c6167a8fa8/.github/workflows/copy-workflow.yml#L163-L168 for an example, how we used to make use of this. - run: | - files=${{ toJson(toJson(matrix.cfg.files)) }} - extra_files=${{ toJson(toJson(matrix.cfg.extra_files)) }} - files=$(echo -e "$files" "$extra_files" | jq -nc '[inputs] | add') - echo "FILES=$files" >> $GITHUB_ENV + env: + FILES: ${{ toJson(toJson(matrix.cfg.files)) }} + EXTRA_FILE: ${{ toJson(toJson(matrix.cfg.extra_files)) }} + run: echo "FILES=$(echo -e "$FILES" "$EXTRA_FILES" | jq -nc '[inputs] | add')" >> $GITHUB_ENV - name: is initial workflow deployment # INITIAL_WORKFLOW_DEPLOYMENT=1 iff none of the files in the target repository exist yet + env: + FILES: ${{ toJson(env.FILES) }} run: | initial_workflow_deployment=1 - for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do + for f in $(jq -r '.[]' <<< "$FILES"); do if [[ -f $TARGET_REPO_DIR/$f ]]; then initial_workflow_deployment=0 break @@ -110,8 +111,9 @@ jobs: } } TEMPLATE_ENGINE: s#\$\{\{\{\s*(.*?)\s*\}\}\}#`jq -cjn 'env.CONTEXT | fromjson.$1'`#ge + FILES: ${{ toJSON(env.FILES) }} run: | - for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do + for f in $(jq -r '.[]' <<< "$FILES"); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) diff --git a/.github/workflows/create-prs.yml b/.github/workflows/create-prs.yml index 01c96d15..f6f77d57 100644 --- a/.github/workflows/create-prs.yml +++ b/.github/workflows/create-prs.yml @@ -31,8 +31,8 @@ jobs: echo "Processing ${target}" base="$(gh api "/repos/${target}" --jq '.default_branch')" # checks if a PR needs to be created - if [[ "$(gh api -X GET "/repos/${target}/compare/${base}...${{ env.PR_BRANCH }}" --jq '.status')" == 'ahead' ]]; then - if [[ "$(gh api -X GET "/repos/${target}/pulls" -f head="$(echo "${target}" | cut -d/ -f1):${{ env.PR_BRANCH }}" -f base="$base" --jq 'length')" != '0' ]] ; then + if [[ "$(gh api -X GET "/repos/${target}/compare/${base}...$PR_BRANCH" --jq '.status')" == 'ahead' ]]; then + if [[ "$(gh api -X GET "/repos/${target}/pulls" -f head="$(echo "${target}" | cut -d/ -f1):$PR_BRANCH" -f base="$base" --jq 'length')" != '0' ]] ; then echo "The PR already exists. Skipping." continue fi @@ -47,7 +47,7 @@ jobs: pr_create_cooldown_in_seconds=1 # max cumulative sleep time - 68.25 minutes while true; do - if result="$(gh api "/repos/$target/pulls" -f title="${{ env.PR_TITLE }}" -f head="${{ env.PR_BRANCH }}" -f base="$base")"; then + if result="$(gh api "/repos/$target/pulls" -f title="$PR_TITLE" -f head="$PR_BRANCH" -f base="$base")"; then echo "Successfully created a PR for '$target' ($pr_create_attempt/$pr_create_max_attempts)" echo "Sleeping for $pr_create_cooldown_in_seconds seconds before creating a next one" sleep $pr_create_cooldown_in_seconds diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 9f23f921..1ab660dc 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -52,7 +52,7 @@ jobs: targets+=($(jq -c ".repositories[] | $defaults + ." $config)) echo "::endgroup::" done - batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< "${targets[@]}") + batches=$(jq -sc '[. | _nwise($MAX_REPOS_PER_WORKFLOW)] | to_entries' <<< "${targets[@]}") echo "batches=$batches" >> $GITHUB_OUTPUT dispatch: needs: [ matrix ] @@ -82,31 +82,38 @@ jobs: steps: - id: dispatch name: Dispatch copy workflow + env: + TARGETS: ${{ toJson(toJson(matrix.cfg.value)) }} + run: | start_date="$(date +%s)" # 2 toJson calls are needed to turn the array of targets into a string - echo '{"targets":${{ toJson(toJson(matrix.cfg.value)) }}}' | jq -c '.' | gh workflow run "${{ env.WORKFLOW_YML }}" --ref "${{ github.ref }}" --repo "${{ env.WORKFLOW_REPO }}" --json + echo "{\"targets\": $TARGETS}" | jq -c '.' | gh workflow run "$WORKFLOW_YML" --ref "$GITHUB_REF" --repo "$WORKFLOW_REPO" --json echo "start_date=$start_date" >> $GITHUB_OUTPUT - id: run name: Wait for copy workflow run to start + env: + START_DATE: ${{ steps.dispatch.outputs.start_date }} run: | # checks every 3 seconds until the most recent copy workflow run's created_at is later than this job's start_date while sleep 3; do - run="$(gh api "/repos/${{ env.WORKFLOW_REPO }}/actions/workflows/${{ env.WORKFLOW_YML }}/runs?per_page=1" --jq '.workflow_runs[0]')" + run="$(gh api "/repos/$WORKFLOW_REPO/actions/workflows/$WORKFLOW_YML/runs?per_page=1" --jq '.workflow_runs[0]')" # nothing to check if no copy workflow run was returned if [[ ! -z "$run" ]]; then run_start_date="$(date --date="$(jq -r '.created_at' <<< "$run")" +%s)" - if [[ "$run_start_date" > "${{ steps.dispatch.outputs.start_date }}" ]]; then + if [[ "$run_start_date" > "$START_DATE" ]]; then echo "id=$(jq -r '.id' <<< "$run")" >> $GITHUB_OUTPUT break fi fi done - name: Wait for copy workflow run to complete + env: + RUN_ID: ${{ steps.run.outputs.id }} run: | # delays checking copy workflow's run status to save on GH API requests - sleep ${{ env.WORKFLOW_COMPLETION_CHECK_DELAY }} + sleep $WORKFLOW_COMPLETION_CHECK_DELAY # checks every 3 seconds until the copy workflow run's status is completed # redirects the stdout to /dev/null because it is very chatty - gh run watch "${{ steps.run.outputs.id }}" --repo "${{ env.WORKFLOW_REPO }}" > /dev/null + gh run watch "$RUN_ID" --repo "$WORKFLOW_REPO" > /dev/null diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml index 64174686..ce0d4f0d 100644 --- a/.github/workflows/releaser.yml +++ b/.github/workflows/releaser.yml @@ -13,7 +13,9 @@ jobs: - name: Determine version run: echo "VERSION=$(jq -r .version version.json)" >> $GITHUB_ENV - name: Determine branch - run: echo "DEFAULT_BRANCH=refs/heads/${{ github.event.repository.default_branch }}" >> $GITHUB_ENV + env: + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: echo "DEFAULT_BRANCH=refs/heads/$DEFAULT_BRANCH" >> $GITHUB_ENV - name: Create a release, if we're on the default branch run: echo "CREATETAG=true" >> $GITHUB_ENV if: env.DEFAULT_BRANCH == github.ref @@ -22,21 +24,23 @@ jobs: id: getmergedpr uses: actions-ecosystem/action-get-merged-pull-request@59afe90821bb0b555082ce8ff1e36b03f91553d9 # v1.0.1 with: - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ github.token }} - name: Check if the "release" label was set on the PR if: steps.getmergedpr.outputs.number != '' && env.DEFAULT_BRANCH != github.ref + env: + LABELS: ${{ steps.getmergedpr.outputs.labels }} run: | while IFS= read -r label; do if [[ "$label" == "release" ]]; then echo "CREATETAG=true" >> $GITHUB_ENV break fi - done <<< "${{ steps.getmergedpr.outputs.labels }}" + done <<< "$LABELS" - name: Create release if: env.CREATETAG == 'true' run: | git fetch origin --tags - if ! $(git rev-list ${{ env.VERSION}}.. &> /dev/null); then - git tag ${{ env.VERSION }} + if ! $(git rev-list $VERSION.. &> /dev/null); then + git tag $VERSION git push --tags fi diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index 090ea038..09321c26 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -15,15 +15,17 @@ jobs: - uses: actions/checkout@v3 - id: repos name: find repositories to check + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} run: | # returns a JSON array of repository objects with the following schema: # [ {"config": "$JSON_CONFIG_FILE_PATH", "repo": "$GITHUB_REPOSITORY_FULL_NAME"} ] repos="$(jq -nc '[inputs | .repositories[] | {"config":input_filename,"repo":.target}]' configs/*.json)" - if [[ '${{ github.event_name }}' == 'pull_request' ]]; then + if [[ "$GITHUB_EVENT_NAME" == 'pull_request' ]]; then # resets the checkout to PR target commit - git fetch origin ${{ github.event.pull_request.base.sha }} - git checkout ${{ github.event.pull_request.base.sha }} + git fetch origin $BASE_SHA + git checkout $BASE_SHA # returns a JSON array of repository objects as they exist on pull request target base="$(jq -nc '[inputs | .repositories[] | {"config":input_filename,"repo":.target}]' configs/*.json)" @@ -36,13 +38,16 @@ jobs: echo "repos=$repos" >> $GITHUB_OUTPUT - name: find deleted / archived repositories if: ${{ steps.repos.outputs.repos != '[]' }} + env: + GITHUB_TOKEN: ${{ github.token }} + REPOS: ${{ steps.repos.outputs.repos }} run: | status=0 while read config; do echo "::group::$config" while read repo; do exists=true - output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$repo") || exists=false + output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$repo") || exists=false if ! $exists; then echo "Repository $repo does not exist." status=1 @@ -52,7 +57,7 @@ jobs: echo "Repository $repo is archived." status=1 fi - done <<< "$(jq -r '.[] | select(.config == $key) | .repo' --arg key "$config" <<< '${{ steps.repos.outputs.repos }}')" + done <<< "$(jq -r '.[] | select(.config == $key) | .repo' --arg key "$config" <<< "$REPOS")" echo "::endgroup::" - done <<< "$(jq -r 'map(.config) | unique | .[]' <<< '${{ steps.repos.outputs.repos }}')" + done <<< "$(jq -r 'map(.config) | unique | .[]' <<< "$REPOS")" exit $status diff --git a/.github/workflows/tagpush.yml b/.github/workflows/tagpush.yml index b2c19e90..05570ade 100644 --- a/.github/workflows/tagpush.yml +++ b/.github/workflows/tagpush.yml @@ -20,18 +20,20 @@ jobs: - run: cat "$GITHUB_EVENT_PATH" | jq -M . - name: extract tag name run: | - tagname=$(echo "${{ github.ref }}" | sed "s/refs\/tags\///") - echo $tagnmae + tagname=$(echo "$GITHUB_REF" | sed "s/refs\/tags\///") + echo $tagname echo "TAGNAME=$tagname" >> $GITHUB_ENV - name: create issue template file if: ${{ github.event.pusher.name != 'web3-bot' }} + env: + PUSHER: ${{ github.event.pusher.name }} run: | echo "---" >> .github/workflows/tagpush.md - echo "title: ${{ env.ISSUE_TITLE }}" | sed "s/%tagname%/${{ env.TAGNAME }}/" >> .github/workflows/tagpush.md - echo "assignees: ${{ env.ISSUE_ASSIGNEE }}" | sed "s/%pusher%/${{ github.event.pusher.name }}/" >> .github/workflows/tagpush.md + echo "title: $ISSUE_TITLE" | sed "s/%tagname%/$TAGNAME/" >> .github/workflows/tagpush.md + echo "assignees: $ISSUE_ASSIGNEE" | sed "s/%pusher%/$PUSHER/" >> .github/workflows/tagpush.md echo "---" >> .github/workflows/tagpush.md cat <> .github/workflows/tagpush.md - ${{ env.ISSUE_BODY }} + $ISSUE_BODY EOF - run: cat .github/workflows/tagpush.md - name: create an issue diff --git a/templates/.github/workflows/go-test.yml b/templates/.github/workflows/go-test.yml index 0f26e3ec..737e7b12 100644 --- a/templates/.github/workflows/go-test.yml +++ b/templates/.github/workflows/go-test.yml @@ -54,7 +54,7 @@ jobs: GOARCH: 386 with: run: | - export "PATH=${{ env.PATH_386 }}:$PATH" + export "PATH=$PATH_386:$PATH" go test -v -shuffle=on ./... - name: Run tests with race detector # speed things up. Windows and OSX VMs are slow diff --git a/templates/.github/workflows/js-test-and-release.yml b/templates/.github/workflows/js-test-and-release.yml index 0bd8f243..14d6f155 100644 --- a/templates/.github/workflows/js-test-and-release.yml +++ b/templates/.github/workflows/js-test-and-release.yml @@ -139,5 +139,5 @@ jobs: docker-username: ${{ secrets.DOCKER_USERNAME }} - run: npm run --if-present release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} From f8bbba90f28f616380f291bff156845819049680 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 6 Feb 2023 16:56:59 +0100 Subject: [PATCH 3/7] chore: do not use substitution in if --- .github/actions/copy-workflow-go/action.yml | 4 ++-- .github/workflows/copy-workflow.yml | 8 ++++---- .github/workflows/stale-repos.yml | 2 +- .github/workflows/tagpush.yml | 6 +++--- templates/.github/workflows/go-check.yml | 6 +++--- templates/.github/workflows/go-test.yml | 2 +- templates/.github/workflows/js-test-and-release.yml | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index 50b2f282..5e19ff10 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -70,7 +70,7 @@ runs: fi fi - name: go mod tidy (on initial workflow deployment) - if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }} + if: env.INITIAL_WORKFLOW_DEPLOYMENT == 1 uses: protocol/multiple-go-modules@v1.2 with: working-directory: ${{ env.TARGET_REPO_DIR }} @@ -81,7 +81,7 @@ runs: git commit -m "run go mod tidy" fi - name: gofmt -s (on initial workflow deployment and on new Go version) - if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}} + if: env.INITIAL_WORKFLOW_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1 working-directory: ${{ env.TARGET_REPO_DIR }} shell: bash run: | diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 2390f470..d5ca35fe 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -71,7 +71,7 @@ jobs: done echo "INITIAL_WORKFLOW_DEPLOYMENT=$initial_workflow_deployment" >> $GITHUB_ENV - name: remove Travis (on initial workflow deployment) - if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }} + if: env.INITIAL_WORKFLOW_DEPLOYMENT == 1 working-directory: ${{ env.TARGET_REPO_DIR }} run: | if [[ -f .travis.yml ]]; then @@ -79,7 +79,7 @@ jobs: git commit -m "disable Travis" fi - name: remove CircleCI (on initial workflow deployment) - if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }} + if: env.INITIAL_WORKFLOW_DEPLOYMENT == 1 working-directory: ${{ env.TARGET_REPO_DIR }} run: | if [[ -d .circleci ]]; then @@ -87,7 +87,7 @@ jobs: git commit -m "disable CircleCI" fi - name: remove gx (on initial workflow deployment) - if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }} + if: env.INITIAL_WORKFLOW_DEPLOYMENT == 1 working-directory: ${{ env.TARGET_REPO_DIR }} run: | if [[ -d .gx ]]; then @@ -146,7 +146,7 @@ jobs: working-directory: ${{ env.TARGET_REPO_DIR }} run: echo "NEEDS_UPDATE=$(git rev-list HEAD...origin/$(git rev-parse --abbrev-ref HEAD) --ignore-submodules --count 2> /dev/null || echo 1)" >> $GITHUB_ENV - name: Force push web3-bot/sync branch - if: ${{ env.NEEDS_UPDATE != 0 }} + if: env.NEEDS_UPDATE != 0 working-directory: ${{ env.TARGET_REPO_DIR }} run: | git checkout -B web3-bot/sync diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index 09321c26..b5df67fa 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -37,7 +37,7 @@ jobs: echo "repos=$repos" >> $GITHUB_OUTPUT - name: find deleted / archived repositories - if: ${{ steps.repos.outputs.repos != '[]' }} + if: steps.repos.outputs.repos != '[]' env: GITHUB_TOKEN: ${{ github.token }} REPOS: ${{ steps.repos.outputs.repos }} diff --git a/.github/workflows/tagpush.yml b/.github/workflows/tagpush.yml index 05570ade..9d119e9e 100644 --- a/.github/workflows/tagpush.yml +++ b/.github/workflows/tagpush.yml @@ -24,7 +24,7 @@ jobs: echo $tagname echo "TAGNAME=$tagname" >> $GITHUB_ENV - name: create issue template file - if: ${{ github.event.pusher.name != 'web3-bot' }} + if: github.event.pusher.name != 'web3-bot' env: PUSHER: ${{ github.event.pusher.name }} run: | @@ -37,7 +37,7 @@ jobs: EOF - run: cat .github/workflows/tagpush.md - name: create an issue - if: ${{ github.event.pusher.name != 'web3-bot' }} + if: github.event.pusher.name != 'web3-bot' uses: JasonEtco/create-an-issue@e27dddc79c92bc6e4562f268fffa5ed752639abd # v2.9.1 env: GITHUB_TOKEN: ${{ github.token }} @@ -45,5 +45,5 @@ jobs: with: filename: .github/workflows/tagpush.md - name: fail build if push wasn't done by web3-bot - if: ${{ github.event.pusher.name != 'web3-bot' }} + if: github.event.pusher.name != 'web3-bot' run: exit 1 diff --git a/templates/.github/workflows/go-check.yml b/templates/.github/workflows/go-check.yml index f9c8352c..6e3baec0 100644 --- a/templates/.github/workflows/go-check.yml +++ b/templates/.github/workflows/go-check.yml @@ -30,7 +30,7 @@ jobs: fi git diff --exit-code -- go.sum go.mod - name: gofmt - if: ${{ success() || failure() }} # run this step even if the previous one failed + if: success() || failure() # run this step even if the previous one failed run: | out=$(gofmt -s -l .) if [[ -n "$out" ]]; then @@ -38,12 +38,12 @@ jobs: exit 1 fi - name: go vet - if: ${{ success() || failure() }} # run this step even if the previous one failed + if: success() || failure() # run this step even if the previous one failed uses: protocol/multiple-go-modules@v1.2 with: run: go vet ./... - name: staticcheck - if: ${{ success() || failure() }} # run this step even if the previous one failed + if: success() || failure() # run this step even if the previous one failed uses: protocol/multiple-go-modules@v1.2 with: run: | diff --git a/templates/.github/workflows/go-test.yml b/templates/.github/workflows/go-test.yml index 737e7b12..5ca30f0b 100644 --- a/templates/.github/workflows/go-test.yml +++ b/templates/.github/workflows/go-test.yml @@ -26,7 +26,7 @@ jobs: go version go env - name: Use msys2 on windows - if: ${{ matrix.os == 'windows' }} + if: matrix.os == 'windows' shell: bash # The executable for msys2 is also called bash.cmd # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells diff --git a/templates/.github/workflows/js-test-and-release.yml b/templates/.github/workflows/js-test-and-release.yml index 14d6f155..0c521261 100644 --- a/templates/.github/workflows/js-test-and-release.yml +++ b/templates/.github/workflows/js-test-and-release.yml @@ -124,7 +124,7 @@ jobs: release: needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/${{{ github.default_branch }}}' + if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.default_branch) steps: - uses: actions/checkout@v3 with: From 5f4096e41e44ded57de8c2e8fff0ced3df65a0f7 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 6 Feb 2023 16:59:00 +0100 Subject: [PATCH 4/7] chore: skip env var brakets where possible --- .github/actions/copy-workflow-go/action.yml | 16 ++++++++-------- .github/workflows/create-prs.yml | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index 5e19ff10..5c0dba40 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -50,15 +50,15 @@ runs: # As of Go 1.19 io/ioutil is deprecated # We automate its upgrade here because it is quite a widely used package while read file; do - sed -i 's/ioutil.NopCloser/io.NopCloser/' "${file}"; - sed -i 's/ioutil.ReadAll/io.ReadAll/' "${file}"; + sed -i 's/ioutil.NopCloser/io.NopCloser/' "$file"; + sed -i 's/ioutil.ReadAll/io.ReadAll/' "$file"; # ReadDir replacement might require manual intervention (https://pkg.go.dev/io/ioutil#ReadDir) - sed -i 's/ioutil.ReadDir/os.ReadDir/' "${file}"; - sed -i 's/ioutil.ReadFile/os.ReadFile/' "${file}"; - sed -i 's/ioutil.TempDir/os.MkdirTemp/' "${file}"; - sed -i 's/ioutil.TempFile/os.CreateTemp/' "${file}"; - sed -i 's/ioutil.WriteFile/os.WriteFile/' "${file}"; - sed -i 's/ioutil.Discard/io.Discard/' "${file}"; + sed -i 's/ioutil.ReadDir/os.ReadDir/' "$file"; + sed -i 's/ioutil.ReadFile/os.ReadFile/' "$file"; + sed -i 's/ioutil.TempDir/os.MkdirTemp/' "$file"; + sed -i 's/ioutil.TempFile/os.CreateTemp/' "$file"; + sed -i 's/ioutil.WriteFile/os.WriteFile/' "$file"; + sed -i 's/ioutil.Discard/io.Discard/' "$file"; done <<< "$(find . -type f -name '*.go')" go install golang.org/x/tools/cmd/goimports@v0.5.0 diff --git a/.github/workflows/create-prs.yml b/.github/workflows/create-prs.yml index f6f77d57..d333b9a6 100644 --- a/.github/workflows/create-prs.yml +++ b/.github/workflows/create-prs.yml @@ -28,16 +28,16 @@ jobs: done failed=() for target in ${targets[@]}; do - echo "Processing ${target}" - base="$(gh api "/repos/${target}" --jq '.default_branch')" + echo "Processing $target" + base="$(gh api "/repos/$target" --jq '.default_branch')" # checks if a PR needs to be created - if [[ "$(gh api -X GET "/repos/${target}/compare/${base}...$PR_BRANCH" --jq '.status')" == 'ahead' ]]; then - if [[ "$(gh api -X GET "/repos/${target}/pulls" -f head="$(echo "${target}" | cut -d/ -f1):$PR_BRANCH" -f base="$base" --jq 'length')" != '0' ]] ; then + if [[ "$(gh api -X GET "/repos/$target/compare/$base...$PR_BRANCH" --jq '.status')" == 'ahead' ]]; then + if [[ "$(gh api -X GET "/repos/$target/pulls" -f head="$(echo "$target" | cut -d/ -f1):$PR_BRANCH" -f base="$base" --jq 'length')" != '0' ]] ; then echo "The PR already exists. Skipping." continue fi else - echo "The branch does not exist or has diverged from ${base}. Skipping." + echo "The branch does not exist or has diverged from $base. Skipping." continue fi # tries to create a PR in target From 2170b04ae93101a7d0929c8534d09c3711737ef6 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 6 Feb 2023 17:03:32 +0100 Subject: [PATCH 5/7] fix: env var substitution --- .github/workflows/dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 1ab660dc..96f538ca 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -52,7 +52,7 @@ jobs: targets+=($(jq -c ".repositories[] | $defaults + ." $config)) echo "::endgroup::" done - batches=$(jq -sc '[. | _nwise($MAX_REPOS_PER_WORKFLOW)] | to_entries' <<< "${targets[@]}") + batches=$(jq -sc "[. | _nwise($MAX_REPOS_PER_WORKFLOW)] | to_entries" <<< "${targets[@]}") echo "batches=$batches" >> $GITHUB_OUTPUT dispatch: needs: [ matrix ] From 0854c63ebb5851b4bc720d7659b86ea91d918613 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 6 Feb 2023 17:12:04 +0100 Subject: [PATCH 6/7] fix: double toJSON --- .github/workflows/check-3rd-party.yml | 2 +- .github/workflows/copy-workflow.yml | 12 +++++------- .github/workflows/dispatch.yml | 8 +++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/check-3rd-party.yml b/.github/workflows/check-3rd-party.yml index 23bb1b48..1df81c88 100644 --- a/.github/workflows/check-3rd-party.yml +++ b/.github/workflows/check-3rd-party.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - file: ${{ fromJson(needs.matrix.outputs.targets) }} + file: ${{ fromJSON(needs.matrix.outputs.targets) }} name: ${{ matrix.file }} steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index d5ca35fe..6af22692 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - cfg: ${{ fromJson(github.event.inputs.targets) }} + cfg: ${{ fromJSON(github.event.inputs.targets) }} max-parallel: 10 env: TARGET_REPO_DIR: "target-repo" @@ -54,13 +54,12 @@ jobs: # By setting the environment variable, it's possible to programmatically add / modify this list. # See https://github.com/protocol/.github/blob/38135c75e47839623bf9b2748275d8c6167a8fa8/.github/workflows/copy-workflow.yml#L163-L168 for an example, how we used to make use of this. env: - FILES: ${{ toJson(toJson(matrix.cfg.files)) }} - EXTRA_FILE: ${{ toJson(toJson(matrix.cfg.extra_files)) }} - run: echo "FILES=$(echo -e "$FILES" "$EXTRA_FILES" | jq -nc '[inputs] | add')" >> $GITHUB_ENV + FILES: | + ${{ toJSON(matrix.cfg.files) }} + ${{ toJSON(matrix.cfg.extra_files) }} + run: echo "FILES=$(jq -nc '[inputs] | add' <<< "$FILES")" >> $GITHUB_ENV - name: is initial workflow deployment # INITIAL_WORKFLOW_DEPLOYMENT=1 iff none of the files in the target repository exist yet - env: - FILES: ${{ toJson(env.FILES) }} run: | initial_workflow_deployment=1 for f in $(jq -r '.[]' <<< "$FILES"); do @@ -111,7 +110,6 @@ jobs: } } TEMPLATE_ENGINE: s#\$\{\{\{\s*(.*?)\s*\}\}\}#`jq -cjn 'env.CONTEXT | fromjson.$1'`#ge - FILES: ${{ toJSON(env.FILES) }} run: | for f in $(jq -r '.[]' <<< "$FILES"); do echo -e "\nProcessing $f." diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 96f538ca..4fed8545 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -73,7 +73,7 @@ jobs: # The triggered copy workflow runs use that final array as their matrix. # Since max-parallel here is 1, we'll end up with at most max-parallel from copy workflow + 1 parallel jobs. # 20 is the upper limit on parallel jobs on a free plan. - cfg: ${{ fromJson(needs.matrix.outputs.batches) }} + cfg: ${{ fromJSON(needs.matrix.outputs.batches) }} max-parallel: 1 env: GITHUB_TOKEN: ${{ secrets.WEB3BOT_GITHUB_TOKEN }} @@ -83,12 +83,10 @@ jobs: - id: dispatch name: Dispatch copy workflow env: - TARGETS: ${{ toJson(toJson(matrix.cfg.value)) }} - + TARGETS: ${{ toJSON(matrix.cfg.value) }} run: | start_date="$(date +%s)" - # 2 toJson calls are needed to turn the array of targets into a string - echo "{\"targets\": $TARGETS}" | jq -c '.' | gh workflow run "$WORKFLOW_YML" --ref "$GITHUB_REF" --repo "$WORKFLOW_REPO" --json + gh workflow run "$WORKFLOW_YML" --ref "$GITHUB_REF" --repo "$WORKFLOW_REPO" --field "targets=$TARGETS" echo "start_date=$start_date" >> $GITHUB_OUTPUT - id: run name: Wait for copy workflow run to start From 9ca8c5f6861c34e99607958e48aa9daaa1c9ba68 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Tue, 7 Feb 2023 11:07:34 +0100 Subject: [PATCH 7/7] Update templates/.github/workflows/js-test-and-release.yml --- templates/.github/workflows/js-test-and-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/.github/workflows/js-test-and-release.yml b/templates/.github/workflows/js-test-and-release.yml index 0c521261..14d6f155 100644 --- a/templates/.github/workflows/js-test-and-release.yml +++ b/templates/.github/workflows/js-test-and-release.yml @@ -124,7 +124,7 @@ jobs: release: needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.default_branch) + if: github.event_name == 'push' && github.ref == 'refs/heads/${{{ github.default_branch }}}' steps: - uses: actions/checkout@v3 with: