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 new file mode 100644 index 00000000000..03d1fecf618 --- /dev/null +++ b/.github/workflows/changesets-preview-pr.yml @@ -0,0 +1,67 @@ +# +# 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 + +on: + push: + branches: + - develop + +jobs: + changesets-release-preview: + runs-on: ubuntu-latest + permissions: + 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: change + with: + token: ${{ secrets.GITHUB_TOKEN }} + filters: | + core-changeset: + - '.changeset/**' + + - name: Setup pnpm + uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 + 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.change.outputs.core-changeset == 'true' + with: + node-version: 20 + cache: pnpm + cache-dependency-path: ./pnpm-lock.yaml + + - 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: Create release preview PR + 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 + commit-message: "changeset: release preview" + committer: app-token-issuer-releng[bot] + branch: changesets/release-preview + title: "[DO NOT MERGE] Changeset Release Preview - v${{ steps.changelog.outputs.version }}" + body: ${{ steps.changelog.outputs.pr_body }} + draft: true + labels: | + release-preview + do-not-merge diff --git a/.github/workflows/cicd-changesets.yml b/.github/workflows/cicd-changesets.yml deleted file mode 100644 index 96363588319..00000000000 --- a/.github/workflows/cicd-changesets.yml +++ /dev/null @@ -1,74 +0,0 @@ -# -# 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 -# - -name: Release Preview - Changeset - -on: - push: - branches: - - develop - -jobs: - cicd-changesets: - runs-on: ubuntu-latest - permissions: - id-token: write - contents: read - actions: read - steps: - - name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - - - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 - id: changeset-added - with: - token: ${{ secrets.GITHUB_TOKEN }} - filters: | - core-changeset: - - added: '.changeset/**' - - - name: Setup pnpm - uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 - if: steps.changeset-added.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' - with: - node-version: 20 - cache: pnpm - cache-dependency-path: ./pnpm-lock.yaml - - - name: Run changeset version - run: pnpm install && pnpm changeset version - 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 - if: steps.changeset-added.outputs.core-changeset == 'true' - uses: smartcontractkit/.github/actions/cicd-changesets@6da79c7b9f14bec077df2c1ad40d53823b409d9c # cicd-changesets@0.3.3 - 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 }} diff --git a/tools/ci/format_changelog b/tools/ci/format_changelog new file mode 100755 index 00000000000..7e508a1e129 --- /dev/null +++ b/tools/ci/format_changelog @@ -0,0 +1,163 @@ +#!/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 +} + +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 <> $GITHUB_OUTPUT + echo "${pr_body}" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT +} + +set_new_changelog_content() { + read -d '' new_changelog < 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 ### + +tail -n +2 CHANGELOG.md > CHANGELOG.md.tmp + +pnpm changeset version + +version=$(jq -r '.version' package.json) +echo "version=$version" >> $GITHUB_OUTPUT + +read -d '' changelog_content <