Upsert Release PR #1221
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Upsert Release PR | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| selected-adapters: | |
| description: comma (and/or space) separated list of adapters to release (if empty, all changed adapters with changesets will be released) | |
| required: false | |
| default: '' | |
| # TODO: This entire workflow would be immensely sped up (~3min -> 30s tops) if: | |
| # - Readme generation did not require built TS files | |
| # - Readme generation was optimized a bit | |
| # - We only installed the changeset package | |
| # Prevent race condition in writing to the changeset branch. | |
| concurrency: | |
| group: deploy-and-release | |
| cancel-in-progress: false | |
| jobs: | |
| consume-changesets: | |
| name: Upsert Release PR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| # Needed to set up GATI token | |
| id-token: write | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| UPSTREAM_BRANCH: 'HEAD~1' | |
| SELECTED_ADAPTERS: ${{ inputs.selected-adapters }} | |
| steps: | |
| - name: Check if changeset release branch already exists | |
| shell: bash | |
| run: | | |
| if git ls-remote --exit-code "https://github.com/${GITHUB_REPOSITORY}.git" changeset-release/main; then | |
| echo "Branch already exists: changeset-release/main" | |
| exit 1 | |
| fi | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | |
| fetch-depth: 0 | |
| # We install only the changesets tool so we can do the mock changesets before installing dependencies, | |
| # as the setup action will only build the files relevant to the changed adapters | |
| - name: Install changesets tool | |
| run: | | |
| yarn add @changesets/cli@$(jq -r '.devDependencies."@changesets/cli"' package.json) | |
| - name: Configure git | |
| shell: bash | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Get changeset arguments | |
| run: | | |
| set -e | |
| CHANGESET_ARGUMENTS="$(yarn get-changeset-arguments "$SELECTED_ADAPTERS")" | |
| echo "CHANGESET_ARGUMENTS=$CHANGESET_ARGUMENTS" >> "$GITHUB_ENV" | |
| - name: Temporarily calculate changesets to generate readmes with proper versions | |
| run: | | |
| yarn changeset version $CHANGESET_ARGUMENTS | |
| git add -A | |
| git commit -m "Changesets mock" | |
| - name: Set up and install dependencies | |
| uses: ./.github/actions/setup | |
| with: | |
| base-branch: ${{ env.UPSTREAM_BRANCH }} | |
| # We want to build all packages for the documentation generation step so that the Masterlist is up to date for all EAs | |
| build-all: 'true' | |
| - name: Increase monorepo version | |
| run: | | |
| BUMPED_VERSION=$(jq -r '.version | split(".")[1] | tonumber | . + 1 | tostring | "1." + . + ".0"' package.json) | |
| jq ".version = \"$BUMPED_VERSION\"" package.json > package.tmp.json | |
| mv package.tmp.json package.json | |
| echo "BUMPED_VERSION=$BUMPED_VERSION" >> $GITHUB_ENV | |
| - name: Generate documentation | |
| run: | | |
| yarn generate:master-list -v | |
| # Only generate READMEs for adapters being released. | |
| yarn generate:readme -v $(.github/scripts/list-packages-adapters.sh HEAD | jq -r '"--adapters " + .adapters[].shortName' | tr '\n' ' ') | |
| - name: Undo temporary changesets and commit docs | |
| run: | | |
| git stash | |
| git reset HEAD^ --hard | |
| git stash pop | |
| - name: Commit docs | |
| run: | | |
| git add MASTERLIST.md | |
| git add "*README.md" | |
| yarn lint-staged | |
| - name: Stash changes for changesets action to pick up in custom script | |
| run: | | |
| git stash | |
| - name: Set up GATI token for PR creation | |
| id: setup-github-token | |
| uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # setup-github-token@0.1.2 | |
| with: | |
| aws-role-arn: ${{ secrets.GATI_AWS_ROLE_ARN_FOR_CREATE_PRS }} | |
| aws-lambda-url: ${{ secrets.GATI_LAMBDA_DATA_FEEDS_URL }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Create Release Pull Request | |
| uses: smartcontractkit/.github/actions/signed-commits@4b7aa1d5b60f0d5704400a1d2b192905ad386e6c # changesets-signed-commits@1.2.4 | |
| with: | |
| # This version command is not only necessary because of yarn pnp, but because the changeset action | |
| # performs git resets and we want to keep those changes, so we stash and then pop them here. | |
| # All the previous steps would technically make more sense in the script itself, but we | |
| # keep them as separate ones so it's easier to see them from the github UI to debug. | |
| version: ./.github/scripts/run-changesets.sh ${{ env.CHANGESET_ARGUMENTS }} | |
| title: 'Release ${{ env.BUMPED_VERSION }}' | |
| commit: 'Release ${{ env.BUMPED_VERSION }}' | |
| env: | |
| # If we use secrets.GITHUB_TOKEN, then the created PR doesn't | |
| # trigger other workflows. So we use the token created in the | |
| # previous step. | |
| GITHUB_TOKEN: ${{ steps.setup-github-token.outputs.access-token }} | |
| - name: Annotate release PR description | |
| env: | |
| GITHUB_TOKEN: ${{ steps.setup-github-token.outputs.access-token }} | |
| # We use gh pr list with exact title match instead of --search to avoid GitHub search index lag | |
| run: | | |
| PR_NUMBER=$(gh pr list \ | |
| --base "${{ github.ref_name }}" \ | |
| --state open \ | |
| --json number,title \ | |
| --jq ".[] | select(.title == \"Release $BUMPED_VERSION\") | .number") | |
| PR_BODY=$(gh pr view "$PR_NUMBER" --json body --jq '.body') | |
| printf -v PR_BODY_PREFIX "This release was triggered by @%s.\n\n" "${{ github.actor }}" | |
| printf -v UPDATED_BODY "%s%s" "$PR_BODY_PREFIX" "$PR_BODY" | |
| gh api \ | |
| --method PATCH \ | |
| "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" \ | |
| -f body="$UPDATED_BODY" \ | |
| --silent | |
| - name: Tag changesets commit | |
| run: | | |
| # Delete the tags if they already exist (ignore errors if they don't) | |
| git tag -d "v$BUMPED_VERSION" || true | |
| git push --delete origin "v$BUMPED_VERSION" || true | |
| git tag "v$BUMPED_VERSION" | |
| git push origin "v$BUMPED_VERSION" | |
| # Because the workflows won't run and we technically don't need them for this autogenerated PR, | |
| # we manually skip all the required checks by using the GitHub API directly. | |
| - name: Skip required checks manually | |
| run: | | |
| COMMIT_SHA=$(git rev-parse HEAD) | |
| ./.github/scripts/skip-check.sh $COMMIT_SHA "Adapter changes accompanied by a changeset" | |
| ./.github/scripts/skip-check.sh $COMMIT_SHA "Documentation generation test" | |
| ./.github/scripts/skip-check.sh $COMMIT_SHA "Install and verify dependencies" | |
| ./.github/scripts/skip-check.sh $COMMIT_SHA "Run integration tests for changed adapters" | |
| ./.github/scripts/skip-check.sh $COMMIT_SHA "Run linters and formatters" | |
| ./.github/scripts/skip-check.sh $COMMIT_SHA "Run unit tests for changed adapters" |