-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: refactor release workflow #3678
Open
nedsalk
wants to merge
18
commits into
master
Choose a base branch
from
ns/chore/release-workflow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−92
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e2167f2
chore: split release workflow
nedsalk 30b01d2
use equality
nedsalk 49e76d9
change quotes
nedsalk b14bf38
bring back file to not have merge conflicts
nedsalk 90e4d74
Merge remote-tracking branch 'origin/master' into ns/chore/release-wo…
nedsalk 8c2dd43
move gh package publishing to changesets-pr
nedsalk d1ad21d
rename `release-v2` to `release`
nedsalk a807f8d
some reordering for minimal impact
nedsalk 3c2b3a0
typo
nedsalk bcbdeb2
move `next` publishing to separate workflow
nedsalk 7eb8b35
remove publish-related flags
nedsalk 8e945a3
remove node auth token for changesets
nedsalk ff302c0
remove `version` command from release
nedsalk ee41e36
Merge remote-tracking branch 'origin/master' into ns/chore/release-wo…
nedsalk 5c46ace
fix names and conditional
nedsalk 3df65d8
fix formatting
nedsalk bb7c896
fix formatting 2
nedsalk fc65ae4
fix formatting 3
nedsalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: "Changesets PR" | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- release/* | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
changesets-pr: | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
# First check ensures that the workflow runs only if the commit is NOT the changesets PR commit. | ||
# Second check ensures that the workflow runs only after a commit is pushed into the branch, | ||
# and not when the branch is created. | ||
# This is to avoid running the workflow when a release/* branch is created. | ||
if: | | ||
github.event.head_commit.message != 'ci(release): versioning packages and changesets' && | ||
github.event.before != '0000000000000000000000000000000000000000' | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
|
||
- name: CI Setup | ||
uses: ./.github/actions/ci-setup | ||
|
||
# if there are changesets present, package.json will be bumped | ||
- name: Bump and Collect Versions | ||
run: | | ||
pnpm changeset version | ||
echo "RELEASE_VERSION=v$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)" >> $GITHUB_ENV | ||
echo "FUEL_CORE_VERSION=$(cat ./internal/fuel-core/VERSION)" >> $GITHUB_ENV | ||
echo "FORC_VERSION=$(cat ./internal/forc/VERSION)" >> $GITHUB_ENV | ||
git reset --hard | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set branch name and changeset PR title | ||
run: | | ||
echo "CHANGESET_PR_TITLE=$(echo "ci(release): \`${{ env.RELEASE_VERSION }}\` @ \`${{ github.ref_name }}\`")" >> $GITHUB_ENV | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Create Release Pull Request | ||
uses: FuelLabs/changesets-action@main | ||
with: | ||
version: pnpm changeset:version-with-docs | ||
commit: "ci(release): versioning packages and changesets" | ||
title: ${{ env.CHANGESET_PR_TITLE }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Prettify changelog | ||
run: pnpm changeset:update-changelog | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REF_NAME: ${{ github.ref_name }} | ||
PUBLISHED: "false" | ||
|
||
# # Commenting out as we require permissions to trigger across repos | ||
# - name: Update docs | ||
# if: github.ref_name == 'master' | ||
# uses: benc-uk/workflow-dispatch@v1 | ||
# with: | ||
# workflow: update-nightly.yml | ||
# ref: master | ||
# repo: FuelLabs/docs-hub | ||
# token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Upload assets to S3 | ||
- uses: unfor19/install-aws-cli-action@v1.0.7 | ||
if: github.ref_name == 'master' | ||
with: | ||
version: 2 | ||
verbose: false | ||
arch: amd64 | ||
rootdir: "" | ||
workdir: "" | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
if: github.ref_name == 'master' | ||
with: | ||
role-to-assume: ${{ vars.AWS_ROLE_ARN }} | ||
aws-region: ${{ vars.AWS_S3_REGION }} | ||
|
||
- name: Upload assets to s3 | ||
if: github.ref_name == 'master' | ||
run: | | ||
aws s3 cp ./packages/account/src/assets/images/ s3://${{ vars.AWS_S3_BUCKET }}/providers/ --recursive |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: "Publish to next tag" | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
publish-to-next: | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
|
||
- name: CI Setup | ||
uses: ./.github/actions/ci-setup | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Create .npmrc | ||
run: | | ||
cat << EOF > "$HOME/.npmrc" | ||
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN | ||
@FuelLabs:registry=https://npm.pkg.github.com | ||
EOF | ||
env: | ||
HOME: ${{ github.workspace }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Release to @next tag on GitHub Packages | ||
run: | | ||
git checkout master | ||
|
||
CHANGESET_FILE=$(git diff-tree --no-commit-id --name-only HEAD -r ".changeset/*-*-*.md") | ||
if [ -z "$CHANGESET_FILE" ]; then | ||
echo "No changesets found, skipping release to @next tag" | ||
exit 0 | ||
fi | ||
|
||
AFFECTED_PACKAGES=$(sed -n '/---/,/---/p' "$CHANGESET_FILE" | sed '/---/d') | ||
if [ -z "$AFFECTED_PACKAGES" ]; then | ||
echo "No packages affected by changesets, skipping release to @next tag" | ||
exit 0 | ||
fi | ||
|
||
pnpm changeset:next | ||
pnpm changeset version --snapshot next | ||
pnpm changeset publish --tag next | ||
env: | ||
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HOME: ${{ github.workspace }} | ||
npm_config_registry: "https://npm.pkg.github.com" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,16 @@ concurrency: ${{ github.workflow }}-${{ github.ref }} | |
|
||
jobs: | ||
release: | ||
name: "Release" | ||
runs-on: ubuntu-latest | ||
environment: npm-deploy | ||
permissions: write-all | ||
# Ensure that the workflow runs only after a commit is pushed into the branch | ||
# First check ensures that the workflow runs only when the changesets PR commit is pushed into the branch. | ||
# Second check ensures that the workflow runs only after a commit is pushed into the branch, | ||
# and not when the branch is created. | ||
# This is to avoid running the workflow when a release/* branch is created. | ||
if: github.event.before != '0000000000000000000000000000000000000000' | ||
if: | | ||
github.event.head_commit.message == 'ci(release): versioning packages and changesets' && | ||
github.event.before != '0000000000000000000000000000000000000000' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, because the workflow won't run at all except when the changesets PR gets merged, we won't be getting the manual approval requests in our notifications that were caused by |
||
|
||
steps: | ||
- name: Checkout | ||
|
@@ -48,10 +50,6 @@ jobs: | |
- name: Build | ||
run: pnpm build | ||
|
||
- name: Set branch name and changeset PR title | ||
run: | | ||
echo "CHANGESET_PR_TITLE=$(echo "ci(release): \`${{ env.RELEASE_VERSION }}\` @ \`${{ github.ref_name }}\`")" >> $GITHUB_ENV | ||
|
||
- name: Get latest release | ||
run: | | ||
LATEST_RELEASE=$(pnpm run --silent changeset:get-latest-release) | ||
|
@@ -62,14 +60,10 @@ jobs: | |
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create Release Pull Request or Publish to npm | ||
id: changesets | ||
- name: Publish to npm | ||
uses: FuelLabs/changesets-action@main | ||
with: | ||
publish: pnpm changeset:publish ${{ env.RELEASE_VERSION }} ${{ github.ref_name }} | ||
version: pnpm changeset:version-with-docs | ||
commit: "ci(release): versioning packages and changesets" | ||
title: ${{ env.CHANGESET_PR_TITLE }} | ||
createGithubReleases: aggregate | ||
githubReleaseName: ${{ env.RELEASE_VERSION }} | ||
githubTagName: ${{ env.RELEASE_VERSION }} | ||
|
@@ -82,62 +76,18 @@ jobs: | |
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
RELEASE_TAG: ${{ env.RELEASE_VERSION }} | ||
PUBLISHED: ${{ steps.changesets.outputs.published }} | ||
PUBLISHED: "true" | ||
REF_NAME: ${{ github.ref_name }} | ||
LATEST_RELEASE: ${{ env.LATEST_RELEASE }} | ||
RELEASE_VERSION_HIGHER_THAN_LATEST: ${{ env.RELEASE_VERSION_HIGHER_THAN_LATEST }} | ||
|
||
- name: Create .npmrc | ||
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true' | ||
run: | | ||
cat << EOF > "$HOME/.npmrc" | ||
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN | ||
@FuelLabs:registry=https://npm.pkg.github.com | ||
EOF | ||
env: | ||
HOME: ${{ github.workspace }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Release to @next tag on GitHub Packages | ||
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true' | ||
run: | | ||
git checkout master | ||
|
||
CHANGESET_FILE=$(git diff-tree --no-commit-id --name-only HEAD -r ".changeset/*-*-*.md") | ||
if [ -z "$CHANGESET_FILE" ]; then | ||
echo "No changesets found, skipping release to @next tag" | ||
exit 0 | ||
fi | ||
|
||
AFFECTED_PACKAGES=$(sed -n '/---/,/---/p' "$CHANGESET_FILE" | sed '/---/d') | ||
if [ -z "$AFFECTED_PACKAGES" ]; then | ||
echo "No packages affected by changesets, skipping release to @next tag" | ||
exit 0 | ||
fi | ||
|
||
pnpm changeset:next | ||
pnpm changeset version --snapshot next | ||
pnpm changeset publish --tag next | ||
env: | ||
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HOME: ${{ github.workspace }} | ||
npm_config_registry: "https://npm.pkg.github.com" | ||
|
||
# ensure docs API is always deployed after merge of changeset PR | ||
- name: Get the last commit message and set env vars | ||
run: echo LAST_COMMIT_MSG=$(git --no-pager log -1 --pretty=%B) >> $GITHUB_ENV | ||
|
||
- name: Decides if Docs API should be deployed | ||
if: startsWith(env.LAST_COMMIT_MSG, 'ci(release):') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true' | ||
run: echo DEPLOY_STABLE_DOCS_API=true >> $GITHUB_ENV | ||
|
||
# nightly docs API gets updated on every merge to master | ||
# and is configured in the vercel dashboard | ||
# stable docs API gets updated only when a new release is published | ||
- name: Update Docs API (stable) | ||
if: github.ref_name == 'master' && env.DEPLOY_STABLE_DOCS_API == 'true' | ||
if: | | ||
github.ref_name == 'master' && | ||
env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true' | ||
env: | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_TS_DOCS_API_PROJECT_ID }} | ||
|
@@ -156,7 +106,9 @@ jobs: | |
# token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create PR to apply latest release to master | ||
if: steps.changesets.outputs.published == 'true' && startsWith(github.ref_name, 'release/') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true' | ||
if: | | ||
startsWith(github.ref_name, 'release/') && | ||
env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true' | ||
run: | | ||
PR_TITLE_TEXT='apply `latest` release to `master`' | ||
if [ ${RELEASE_VERSION#v} = "$(semver "$LATEST_VERSION" --increment minor)" ]; then | ||
|
@@ -176,38 +128,18 @@ jobs: | |
- name: Delete the release branch | ||
# We check env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'false' | ||
# because we don't want to delete the branch that is used in the "Create PR to apply latest release to master" step above | ||
if: steps.changesets.outputs.published == 'true' && startsWith(github.ref_name, 'release/') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'false' | ||
if: | | ||
startsWith(github.ref_name, 'release/') && | ||
env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'false' | ||
run: git push origin --delete ${{ github.ref_name }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Upload assets to S3 | ||
- uses: unfor19/install-aws-cli-action@v1.0.7 | ||
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true' | ||
with: | ||
version: 2 | ||
verbose: false | ||
arch: amd64 | ||
rootdir: "" | ||
workdir: "" | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true' | ||
with: | ||
role-to-assume: ${{ vars.AWS_ROLE_ARN }} | ||
aws-region: ${{ vars.AWS_S3_REGION }} | ||
|
||
- name: Upload assets to s3 | ||
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true' | ||
run: | | ||
aws s3 cp ./packages/account/src/assets/images/ s3://${{ vars.AWS_S3_BUCKET }}/providers/ --recursive | ||
|
||
# # Commenting out as we require permissions to trigger across repos | ||
# - name: Notify migrations and disclosures of the new release (breaking changes) | ||
# run: | | ||
# curl -X POST \ | ||
# -H "Accept: application/vnd.github.v3+json" \ | ||
# -H "Authorization: token ${{ secrets.MIGRATIONS_RELEASE_TRIGGER_TOKEN }}" \ | ||
# https://api.github.com/repos/FuelLabs/migrations-and-disclosures/dispatches \ | ||
# -d '{"event_type":"update_versions"}' | ||
# # Commenting out as we require permissions to trigger across repos | ||
# - name: Notify migrations and disclosures of the new release (breaking changes) | ||
# run: | | ||
# curl -X POST \ | ||
# -H "Accept: application/vnd.github.v3+json" \ | ||
# -H "Authorization: token ${{ secrets.MIGRATIONS_RELEASE_TRIGGER_TOKEN }}" \ | ||
# https://api.github.com/repos/FuelLabs/migrations-and-disclosures/dispatches \ | ||
# -d '{"event_type":"update_versions"}' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this
if
statement, as well as the one in therelease.yaml
file, in these workflows. I was specifically testing if the workflow will be started or not, and it works as is expected from the logic. If you want to test it yourself, you can create a new branch with a file with this workflow:Commit the file and do the following steps:
git push --set-upstream origin your_branch_name
- the workflow won't run because ofgithub.event.before != '0000000000000000000000000000000000000000'
git commit --allow-empty -m "ci(release): versioning packages and changesets" && git push
- the workflow won't run because the commit message equals'ci(release): versioning packages and changesets'
git commit --allow-empty -m "whatever" && git push
- the workflow will runThe same holds for the
release.yaml
workflow, just point 2 will succeed and point 3 will fail.