Skip to content

Commit

Permalink
Use bot token in prerelease workflows (#11716)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessbell authored Mar 21, 2024
1 parent a0d114e commit 8e5c66b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 17 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/change-prerelease-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Change Prerelease Tag

on:
workflow_dispatch:
inputs:
branch:
description: "Branch name"
type: string
default: "release-"
required: true
tag:
description: "New tag name"
type: string
default: "rc"
required: true

jobs:
change_prerelease_tag:
name: Changesets Update Prerelease Tag
runs-on: ubuntu-latest
# Allow GITHUB_TOKEN to have write permissions
permissions:
contents: write

steps:
- uses: actions/create-github-app-token@v1
id: github-actions-bot-app-token
with:
app-id: 819772
private-key: ${{ secrets.APOLLO_GITHUB_ACTIONS_BOT_PRIVATE_KEY }}
repositories: ${{ github.repository }}
owner: ${{ github.repository_owner }}

# Check out the repository, using the Github Actions Bot app's token so
# that we can push later.
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ steps.github-actions-bot-app-token.outputs.token }}
# Checkout release branch entered when workflow was kicked off
ref: ${{ github.event.inputs.branch }}
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0

- name: Setup Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Write latest version to package.json and package-lock.json
run: |
version=$(npm show @apollo/client version)
npm pkg set version="$version"
npm i
- name: Update prerelease tag in .changeset/pre.json
uses: restackio/update-json-file-action@v2.1
with:
file: .changeset/pre.json
fields: '{"tag": "${{github.event.inputs.tag}}"}'

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Prepare for ${{ github.event.inputs.tag }} release
# Commit these changes to the branch workflow is running against
branch: ${{ github.event.inputs.branch }}
32 changes: 16 additions & 16 deletions .github/workflows/exit-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ jobs:
contents: write

steps:
- uses: actions/create-github-app-token@v1
id: github-actions-bot-app-token
with:
app-id: 819772
private-key: ${{ secrets.APOLLO_GITHUB_ACTIONS_BOT_PRIVATE_KEY }}
repositories: ${{ github.repository }}
owner: ${{ github.repository_owner }}

# Check out the repository, using the Github Actions Bot app's token so
# that we can push later.
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ steps.github-actions-bot-app-token.outputs.token }}
# Checkout release branch entered when workflow was kicked off
ref: ${{ github.event.inputs.branch }}
# Fetch entire git history so Changesets can generate changelogs
Expand All @@ -32,22 +43,11 @@ jobs:
with:
node-version: 20.x

- name: Get latest tagged version
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@v1

- name: Remove 'v' prefix from version number (e.g. v1.0.0)
uses: mad9000/actions-find-and-replace-string@5
id: formatversion
with:
source: ${{ steps.previoustag.outputs.tag }}
find: "v"
replace: ""

- name: Write previous version to package.json
uses: jaywcjlove/github-action-package@v2.0.0
with:
version: ${{ steps.formatversion.outputs.value }}
- name: Write latest version to package.json and package-lock.json
run: |
version=$(npm show @apollo/client version)
npm pkg set version="$version"
npm i
- name: Remove pre.json
run: npx rimraf .changeset/pre.json
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@ jobs:
pull-requests: write
id-token: write
steps:
- uses: actions/create-github-app-token@v1
id: github-actions-bot-app-token
with:
app-id: 819772
private-key: ${{ secrets.APOLLO_GITHUB_ACTIONS_BOT_PRIVATE_KEY }}
repositories: ${{ github.repository }}
owner: ${{ github.repository_owner }}

# Check out the repository, using the Github Actions Bot app's token so
# that we can push later.
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ steps.github-actions-bot-app-token.outputs.token }}
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0
Expand Down Expand Up @@ -56,7 +67,7 @@ jobs:
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag alpha
if: steps.check_files.outputs.files_exists == 'false' && !contains(github.event.head_commit.message, 'Exit prerelease')
run: npx changeset pre enter alpha
run: npx changeset pre enter alpha && git add -A && git commit -m 'Enter prerelease mode' && git push

- name: Create prerelease PR
# If .changeset/pre.json exists and we are not currently cutting a
Expand Down

0 comments on commit 8e5c66b

Please sign in to comment.