From a6b8ddfdfb967e9ee32479177b4a9dbb8e1523d1 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Fri, 3 May 2024 15:02:18 -0500 Subject: [PATCH 01/14] add format_changelog script --- tools/ci/format_changelog | 134 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100755 tools/ci/format_changelog diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog new file mode 100755 index 00000000000..a939b021656 --- /dev/null +++ b/tools/ci/format_changelog @@ -0,0 +1,134 @@ +#!/usr/bin/env bash + +create_changesets_json() { + echo "[[]]" > changesets.json +} + +create_tags_json() { + json="{}" + for tag in "${tags_list[@]}"; do + tag=${tag:1} + json=$(jq --arg k "$tag" '.[$k] = []' <<< "$json") + done + echo "$json" > tags.json +} + +append_changeset_content() { + if [[ $1 != "" ]]; then + jq --argjson idx "$changesets_index" --arg str "$1" \ + '.[$idx] += [$str]' changesets.json > tmp.json && mv tmp.json changesets.json + fi +} + +append_changelog_content() { + for tag in "${tags_list[@]}"; do + tag=${tag:1} + array_length=$(jq -r --arg key "$tag" '.[$key] | length' tags.json) + if [[ $array_length -eq 0 ]]; then + continue + fi + changesets=$(jq -r --arg key "$tag" '.[$key] | join("\n\n")' tags.json) + read -d '' changelog_content < CHANGELOG.md +} + +# checks for tags in each changeset entry and append to tags.json +match_tags() { + changesets_with_index=$(jq -r 'to_entries | .[] | "\(.key) \(.value | join(" "))"' changesets.json) + + echo "$changesets_with_index" | while IFS= read -r line; do + index="${line%% *}" + changeset_content="${line#* }" + changeset_formatted=$(jq -r --argjson idx "$index" '.[$idx] | join("\n")' changesets.json) + found_tag="" + for tag in "${tags_list[@]}"; do + if [[ "$changeset_content" =~ $tag ]]; then + found_tag=${tag:1} + jq --arg key "$found_tag" --arg val "$changeset_formatted" \ + '.[$key] += [$val]' tags.json > tmp.json && mv tmp.json tags.json + fi + done + if [[ $found_tag == "" ]] && [[ ! -z $changeset_content ]]; then + found_tag="untagged" + jq --arg key "$found_tag" --arg val "$changeset_formatted" \ + '.[$key] += [$val]' tags.json > tmp.json && mv tmp.json tags.json + fi + done +} + +cleanup() { + rm -f CHANGELOG.md.tmp + rm -f changesets.json + rm -f tags.json +} + +### SCRIPT STARTS HERE ### +cp CHANGELOG.md CHANGELOG.md.tmp +tail -n +2 CHANGELOG.md > CHANGELOG.md.tmp + +pnpm changeset version + +version=$(jq -r '.version' package.json) +read -d '' changelog_content < Date: Fri, 3 May 2024 15:15:58 -0500 Subject: [PATCH 02/14] refactor changesets release preview workflow --- ...angesets.yml => changesets-preview-pr.yml} | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) rename .github/workflows/{cicd-changesets.yml => changesets-preview-pr.yml} (52%) diff --git a/.github/workflows/cicd-changesets.yml b/.github/workflows/changesets-preview-pr.yml similarity index 52% rename from .github/workflows/cicd-changesets.yml rename to .github/workflows/changesets-preview-pr.yml index 96363588319..1367bb5128e 100644 --- a/.github/workflows/cicd-changesets.yml +++ b/.github/workflows/changesets-preview-pr.yml @@ -1,6 +1,5 @@ # -# This action creates or updates a Release Preview PR that shows which changes are going to be part of the next release -# when a PR is merged into develop branch +# This action creates or updates a Release Preview PR that shows which changes are going to be part of the next release. # name: Release Preview - Changeset @@ -8,26 +7,26 @@ name: Release Preview - Changeset on: push: branches: - - develop + - re-2590/refactor-changesets-release-preview # remove after testing + # - develop jobs: - cicd-changesets: + changesets-release-preview: runs-on: ubuntu-latest permissions: - id-token: write - contents: read - actions: read + contents: write + pull-requests: write steps: - name: Checkout repository uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 - id: changeset-added + id: change with: token: ${{ secrets.GITHUB_TOKEN }} filters: | core-changeset: - - added: '.changeset/**' + - '.changeset/**' - name: Setup pnpm uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 @@ -43,32 +42,34 @@ jobs: cache: pnpm cache-dependency-path: ./pnpm-lock.yaml - - name: Run changeset version - run: pnpm install && pnpm changeset version + - name: Generate new changelog + if: steps.changeset-added.outputs.core-changeset == 'true' + run: pnpm install && ./tools/ci/format_changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: steps.changeset-added.outputs.core-changeset == 'true' - name: Get release version if: steps.changeset-added.outputs.core-changeset == 'true' id: get-release-version run: echo "version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT - - name: cicd-changesets + - name: Create release preview PR if: steps.changeset-added.outputs.core-changeset == 'true' - uses: smartcontractkit/.github/actions/cicd-changesets@6da79c7b9f14bec077df2c1ad40d53823b409d9c # cicd-changesets@0.3.3 + uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 with: - # general inputs - git-user: app-token-issuer-releng[bot] - git-email: app-token-issuer-releng[bot]@users.noreply.github.com - pnpm-use-cache: false - pr-draft: true - pr-title: "[DO NOT MERGE] Changeset Release Preview - v${{ steps.get-release-version.outputs.version }}" - # aws inputs - aws-region: ${{ secrets.AWS_REGION }} - aws-role-arn: ${{ secrets.AWS_OIDC_CHAINLINK_CI_AUTO_PR_TOKEN_ISSUER_ROLE_ARN }} - aws-lambda-url: ${{ secrets.AWS_INFRA_RELENG_TOKEN_ISSUER_LAMBDA_URL }} - # grafana inputs - gc-basic-auth: ${{ secrets.GRAFANA_INTERNAL_BASIC_AUTH }} - gc-host: ${{ secrets.GRAFANA_INTERNAL_HOST }} - gc-org-id: ${{ secrets.GRAFANA_INTERNAL_TENANT_ID }} + add-paths: | + .changeset/** + CHANGELOG.md + commit-message: "changeset: release preview" + committer: app-token-issuer-releng[bot] + branch: changesets/release-preview + title: "[DO NOT MERGE] Changeset Release Preview - v${{ steps.get-release-version.outputs.version }}" + body: | + This PR is a preview of the changes that will be included in the next release. Please do not merge this PR. + + draft: true + labels: | + release-preview + do-not-merge From 36f8eaea9c2502e239cbfabe8fb2d8eb7dbba96a Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Fri, 3 May 2024 15:20:54 -0500 Subject: [PATCH 03/14] update branch to test and add changeset file --- .changeset/many-comics-begin.md | 5 +++++ .github/workflows/changesets-preview-pr.yml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/many-comics-begin.md diff --git a/.changeset/many-comics-begin.md b/.changeset/many-comics-begin.md new file mode 100644 index 00000000000..139023916df --- /dev/null +++ b/.changeset/many-comics-begin.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +Refactor changesets release preview workflow #internal diff --git a/.github/workflows/changesets-preview-pr.yml b/.github/workflows/changesets-preview-pr.yml index 1367bb5128e..fbeedca1a23 100644 --- a/.github/workflows/changesets-preview-pr.yml +++ b/.github/workflows/changesets-preview-pr.yml @@ -7,7 +7,7 @@ name: Release Preview - Changeset on: push: branches: - - re-2590/refactor-changesets-release-preview # remove after testing + - re-2590/refactor-changeset-release-preview # remove after testing # - develop jobs: From 9740d8caed9e4ed0bcab74370f91522a3b5878f3 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Fri, 3 May 2024 15:22:43 -0500 Subject: [PATCH 04/14] fix --- .github/workflows/changesets-preview-pr.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/changesets-preview-pr.yml b/.github/workflows/changesets-preview-pr.yml index fbeedca1a23..ac2aab18a07 100644 --- a/.github/workflows/changesets-preview-pr.yml +++ b/.github/workflows/changesets-preview-pr.yml @@ -30,31 +30,31 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 - if: steps.changeset-added.outputs.core-changeset == 'true' + if: steps.change.outputs.core-changeset == 'true' with: version: ^8.0.0 - name: Setup node uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - if: steps.changeset-added.outputs.core-changeset == 'true' + if: steps.change.outputs.core-changeset == 'true' with: node-version: 20 cache: pnpm cache-dependency-path: ./pnpm-lock.yaml - name: Generate new changelog - if: steps.changeset-added.outputs.core-changeset == 'true' + if: steps.change.outputs.core-changeset == 'true' run: pnpm install && ./tools/ci/format_changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get release version - if: steps.changeset-added.outputs.core-changeset == 'true' + if: steps.change.outputs.core-changeset == 'true' id: get-release-version run: echo "version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT - name: Create release preview PR - if: steps.changeset-added.outputs.core-changeset == 'true' + if: steps.change.outputs.core-changeset == 'true' uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 with: add-paths: | From 48c0d7cf0835054576b75b0fb36c80c2cafb4cf1 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Fri, 3 May 2024 15:30:07 -0500 Subject: [PATCH 05/14] add git-token --- .github/workflows/changesets-preview-pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/changesets-preview-pr.yml b/.github/workflows/changesets-preview-pr.yml index ac2aab18a07..8b333c20845 100644 --- a/.github/workflows/changesets-preview-pr.yml +++ b/.github/workflows/changesets-preview-pr.yml @@ -57,6 +57,7 @@ jobs: if: steps.change.outputs.core-changeset == 'true' uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 with: + git-token: ${{ secrets.GITHUB_TOKEN }} add-paths: | .changeset/** CHANGELOG.md From 07f482b51ef6617978a6aef69092d39d0750ad00 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Mon, 6 May 2024 14:00:11 -0500 Subject: [PATCH 06/14] add set_pr_body and refactor workflow --- .github/workflows/changesets-preview-pr.yml | 14 ++-------- tools/ci/format_changelog | 31 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.github/workflows/changesets-preview-pr.yml b/.github/workflows/changesets-preview-pr.yml index 8b333c20845..14a7690e657 100644 --- a/.github/workflows/changesets-preview-pr.yml +++ b/.github/workflows/changesets-preview-pr.yml @@ -44,15 +44,11 @@ jobs: - name: Generate new changelog if: steps.change.outputs.core-changeset == 'true' + id: changelog run: pnpm install && ./tools/ci/format_changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Get release version - if: steps.change.outputs.core-changeset == 'true' - id: get-release-version - run: echo "version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT - - name: Create release preview PR if: steps.change.outputs.core-changeset == 'true' uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 @@ -64,12 +60,8 @@ jobs: commit-message: "changeset: release preview" committer: app-token-issuer-releng[bot] branch: changesets/release-preview - title: "[DO NOT MERGE] Changeset Release Preview - v${{ steps.get-release-version.outputs.version }}" - body: | - This PR is a preview of the changes that will be included in the next release. Please do not merge this PR. - + title: "[DO NOT MERGE] Changeset Release Preview - v${{ steps.changelog.outputs.version }}" + body: ${{ steps.changelog.outputs.pr_body }} draft: true labels: | release-preview diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index a939b021656..b224143b232 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -38,8 +38,35 @@ EOF done } +set_pr_body() { + # GitHub Issues/PRs messages have a max size limit on the message body payload. + # This is the error: `body is too long (maximum is 65536 characters)`. + max_pr_desc_char_length=65000 + version=$(jq -r '.version' package.json) + echo "version=$version" >> $GITHUB_OUTPUT + read -d '' pr_header <> $GITHUB_OUTPUT +} + set_new_changelog_content() { - append_changelog_content read -d '' new_changelog < Date: Mon, 6 May 2024 14:05:10 -0500 Subject: [PATCH 07/14] fix multi-line string output --- tools/ci/format_changelog | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index b224143b232..83b129d40e9 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -63,7 +63,11 @@ ${pr_header} ${changelog_content} EOF fi - echo "pr_body=$pr_body" >> $GITHUB_OUTPUT + { + echo "$pr_body<> $GITHUB_OUTPUT } set_new_changelog_content() { From 0bb1d227535fe8e513345684d9f28659d20c8626 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Mon, 6 May 2024 14:09:30 -0500 Subject: [PATCH 08/14] fix --- tools/ci/format_changelog | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index 83b129d40e9..4fbdca1eaf1 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -63,11 +63,10 @@ ${pr_header} ${changelog_content} EOF fi - { - echo "$pr_body<> $GITHUB_OUTPUT + # for multi-line output + echo "pr_body<> $GITHUB_OUTPUT + echo "${pr_body}" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT } set_new_changelog_content() { From b419ae594a87b2428e3bc3b85abc0d4620f31439 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Mon, 6 May 2024 14:13:50 -0500 Subject: [PATCH 09/14] fix format --- tools/ci/format_changelog | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index 4fbdca1eaf1..bc5cdeaeb32 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -46,20 +46,16 @@ set_pr_body() { echo "version=$version" >> $GITHUB_OUTPUT read -d '' pr_header < Date: Mon, 6 May 2024 14:21:24 -0500 Subject: [PATCH 10/14] remove testing branch trigger --- .github/workflows/changesets-preview-pr.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/changesets-preview-pr.yml b/.github/workflows/changesets-preview-pr.yml index 14a7690e657..03d1fecf618 100644 --- a/.github/workflows/changesets-preview-pr.yml +++ b/.github/workflows/changesets-preview-pr.yml @@ -7,8 +7,7 @@ name: Release Preview - Changeset on: push: branches: - - re-2590/refactor-changeset-release-preview # remove after testing - # - develop + - develop jobs: changesets-release-preview: From ba7d6a4834146ec37fbee7c108fa0be76d4f64c3 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Mon, 6 May 2024 14:25:12 -0500 Subject: [PATCH 11/14] refactor --- tools/ci/format_changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index bc5cdeaeb32..e59e083022c 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -42,8 +42,6 @@ set_pr_body() { # GitHub Issues/PRs messages have a max size limit on the message body payload. # This is the error: `body is too long (maximum is 65536 characters)`. max_pr_desc_char_length=65000 - version=$(jq -r '.version' package.json) - echo "version=$version" >> $GITHUB_OUTPUT read -d '' pr_header < CHANGELOG.md.tmp pnpm changeset version version=$(jq -r '.version' package.json) +echo "version=$version" >> $GITHUB_OUTPUT + read -d '' changelog_content < Date: Tue, 7 May 2024 10:56:27 -0500 Subject: [PATCH 12/14] add explicit fail exit --- tools/ci/format_changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index e59e083022c..90e65f59d5b 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -euo pipefail + create_changesets_json() { echo "[[]]" > changesets.json } From 1e89fde9cb67e709579220c4d507dc7f8a22a068 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Tue, 7 May 2024 13:53:15 -0500 Subject: [PATCH 13/14] refactor --- tools/ci/format_changelog | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index 90e65f59d5b..442019f4bb5 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -1,7 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail - create_changesets_json() { echo "[[]]" > changesets.json } @@ -105,7 +103,7 @@ cleanup() { } ### SCRIPT STARTS HERE ### -cp CHANGELOG.md CHANGELOG.md.tmp + tail -n +2 CHANGELOG.md > CHANGELOG.md.tmp pnpm changeset version @@ -122,7 +120,6 @@ EOF current_changelog=$(cat CHANGELOG.md.tmp) is_current_version=false -checking_current_changeset=false changesets_index=0 tags_list=( "#nops" "#added" "#changed" "#removed" "#updated" "#deprecation_notice" "#breaking_change" "#db_update" "#wip" "#bugfix" "#internal" "#untagged") @@ -143,12 +140,7 @@ while IFS= read -r line; do if [[ $is_current_version = true ]]; then # saving each changeset to changeset.json # check for start of changeset entry as it could be multi-lined entry - if [[ $line == "- ["* ]] && [[ $checking_current_changeset = true ]]; then - checking_current_changeset=false - changesets_index=$((changesets_index+1)) - append_changeset_content "$line" - elif [[ $line == "- ["* ]] && [[ $checking_current_changeset = false ]]; then - checking_current_changeset=true + if [[ $line == "- ["* ]]; then changesets_index=$((changesets_index+1)) append_changeset_content "$line" elif [[ $line != "##"* ]]; then From 3d4c42fba2fba6f5c7c66130d84fc2a46012f9e0 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Tue, 7 May 2024 14:04:41 -0500 Subject: [PATCH 14/14] add back set -euo pipefail --- tools/ci/format_changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog index 442019f4bb5..7e508a1e129 100755 --- a/tools/ci/format_changelog +++ b/tools/ci/format_changelog @@ -1,5 +1,12 @@ #!/usr/bin/env bash +set -euo pipefail + +if [[ -z "${GITHUB_OUTPUT:-}" ]]; then + echo "GITHUB_OUTPUT environment variable is not set." + exit 1 +fi + create_changesets_json() { echo "[[]]" > changesets.json }