-
Notifications
You must be signed in to change notification settings - Fork 1.4k
212 lines (182 loc) · 8.45 KB
/
release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: "Release"
on:
push:
branches:
- master
- release/*
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: "Release"
runs-on: ubuntu-latest
permissions: write-all
# Ensure 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'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
# workaround to ensure force pushes to changeset branch use REPO_TOKEN owner's account
# see https://github.com/changesets/action/issues/70
persist-credentials: false
- 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: Ensure NPM access
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- 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)
echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_ENV
pnpm add --global semver
echo "RELEASE_VERSION_HIGHER_THAN_LATEST=$(semver $LATEST_RELEASE $RELEASE_VERSION | tail -n1 | grep ${RELEASE_VERSION#v} --silent && echo true || echo false)" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release Pull Request or Publish to npm
id: changesets
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 }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Prettify changelog
run: pnpm changeset:update-changelog
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
RELEASE_TAG: ${{ env.RELEASE_VERSION }}
PUBLISHED: ${{ steps.changesets.outputs.published }}
REF_NAME: ${{ github.ref_name }}
LATEST_RELEASE: ${{ env.LATEST_RELEASE }}
RELEASE_VERSION_HIGHER_THAN_LATEST: ${{ env.RELEASE_VERSION_HIGHER_THAN_LATEST }}
- name: Release to @next tag on npm
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
git add .changeset/fuel-labs-ci.md
pnpm changeset version --snapshot next
pnpm changeset publish --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ensure docs are 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 should be deployed
if: startsWith(env.LAST_COMMIT_MSG, 'ci(release):') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true'
run: echo SHOULD_DEPLOY_DOCS=true >> $GITHUB_ENV
- name: Checkout API Docs
if: env.SHOULD_DEPLOY_DOCS == 'true'
uses: actions/checkout@v4
with:
ref: docs
fetch-depth: 0
- name: Generate and Push API Docs
if: env.SHOULD_DEPLOY_DOCS == 'true'
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git merge origin/$GITHUB_REF_NAME --no-edit
pnpm install
pnpm build
rm -f apps/docs/.gitignore
git add apps/docs/src/api/
git add apps/docs/.typedoc/api-links.json
git commit -m "docs: API docs - ${{ env.RELEASE_VERSION }}"
git push
git restore apps/docs/.gitignore
- name: Update docs (nightly)
if: github.ref_name == 'master' && env.SHOULD_DEPLOY_DOCS == 'true'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: update-nightly.yml
ref: master
repo: FuelLabs/docs-hub
token: ${{ secrets.REPO_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'
run: |
PR_TITLE_TEXT='apply `latest` release to `master`'
if [ ${RELEASE_VERSION#v} = "$(semver "$LATEST_VERSION" --increment minor)" ]; then
PR_TITLE="build!: $PR_TITLE_TEXT"
else
PR_TITLE="build: $PR_TITLE_TEXT"
fi
PR_BODY='Automatically created when `latest` published release is newer than `master` due to publishing done via `release/*` branches.'
gh pr create -B master -H $GITHUB_REF_NAME --title "$PR_TITLE" --body "$PR_BODY"
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
LATEST_VERSION: ${{ env.LATEST_VERSION }}
- 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'
run: git push origin --delete ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
# Upload assets to S3
- uses: unfor19/[email protected]
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true'
with:
version: 2
verbose: false
arch: amd64
rootdir: ""
workdir: ""
- uses: aws-actions/configure-aws-credentials@v4
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true'
with:
aws-access-key-id: ${{ secrets.S3_CDN_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.S3_CDN_SECRET_KEY }}
aws-region: us-east-1
- name: Upload assets to s3
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true'
run: |
aws s3 cp ./packages/account/src/providers/assets/images/ s3://${S3_CDN_BUCKET}/assets/ --recursive
env:
S3_CDN_BUCKET: ${{ secrets.S3_CDN_BUCKET }}
- 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"}'