Skip to content

Commit 85a04b6

Browse files
authored
ci: setup hotfix releasing scripts and settings (#9337)
**Related Issue:** N/A ## Summary Setup continuous integration for releasing hotfixes from a separate branch so normal work can continue on `main`.
1 parent af43d15 commit 85a04b6

File tree

10 files changed

+119
-69
lines changed

10 files changed

+119
-69
lines changed

.github/workflows/chromatic-rc.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/chromatic-main.yml renamed to .github/workflows/chromatic.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: "Chromatic - Main"
1+
name: Chromatic
22
on:
33
push:
4-
branches: [main]
4+
branches: [main, hotfix, rc]
55
pull_request:
6-
branches: [main]
6+
branches: [main, hotfix, rc]
77
types: [labeled, synchronize]
88
jobs:
99
run:
@@ -25,7 +25,7 @@ jobs:
2525
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
2626
zip: true
2727
exitOnceUploaded: true
28-
autoAcceptChanges: main
28+
autoAcceptChanges: ${{ github.base_ref || github.ref_name }}
2929
workingDir: packages/calcite-components
3030
env:
3131
STORYBOOK_SCREENSHOT_TEST_BUILD: true

.github/workflows/deploy-latest.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Deploy Latest
22
on:
33
workflow_dispatch:
44
push:
5-
branches: [main]
5+
branches: [main, hotfix]
66
permissions:
77
contents: write
88
pull-requests: write
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
command: manifest
1717
token: ${{ secrets.ADMIN_TOKEN }}
18-
default-branch: main
18+
default-branch: ${{ github.ref_name }}
1919
extra-files: |
2020
packages/calcite-components/readme.md
2121
- name: Checkout Repository
@@ -24,7 +24,6 @@ jobs:
2424
with:
2525
fetch-depth: 0
2626
token: ${{ secrets.ADMIN_TOKEN }}
27-
ref: main
2827
- name: Setup Node
2928
if: ${{ steps.release.outputs.releases_created }}
3029
uses: actions/setup-node@v4
@@ -41,9 +40,22 @@ jobs:
4140
# For more info, see: https://github.com/Esri/calcite-design-system/pull/9011
4241
git config --global user.email "github-actions[bot]@users.noreply.github.com"
4342
git config --global user.name "github-actions[bot]"
44-
# the "|| true" prevents failure if there are no changes
45-
git add packages/calcite-components/src/components.d.ts || true
46-
git commit -m "build: update types" || true
43+
44+
# The "|| true" prevents failure if there are no changes
45+
git add packages/calcite-components/src/components.d.ts package-lock.json || true
46+
47+
# The release-please PR only updates when there are new deployable
48+
# commits, e.g., fixes, features, or breaking changes. This is fine
49+
# but it means autogenerated files can become outdated.
50+
#
51+
# Lerna will only publish when the working tree is clean, so changes
52+
# to autogenerated files cause the release to fail.
53+
#
54+
# The workaround is to commit the files before releasing so everything
55+
# will be up to date in the dists. The commit will be discarded once
56+
# the container is destroyed, and then the autogenerated files will be
57+
# updated in a subsequent PR.
58+
git commit -m "build: update types and package-lock" || true
4759
4860
npm run publish:latest
4961
env:

.github/workflows/pr-bot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PR Bot
22
on:
33
pull_request:
4-
branches: [main, rc]
4+
branches: [main, rc, hotfix]
55
permissions:
66
pull-requests: write
77
issues: write

.github/workflows/pr-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: E2E
22
on:
33
workflow_dispatch:
44
pull_request:
5-
branches: [main, rc]
5+
branches: [main, rc, hotfix]
66
jobs:
77
e2e:
88
runs-on: ubuntu-20.04

.github/workflows/pr-tests_eslint-plugin-calcite-components.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Run eslint-plugin-calcite-components tests
33
on:
44
pull_request:
55
paths: ["packages/eslint-plugin-calcite-components/**"]
6-
branches: [main, rc]
6+
branches: [main, rc, hotfix]
77
push:
88
paths: ["packages/eslint-plugin-calcite-components/**"]
9-
branches: [main, rc]
9+
branches: [main, rc, hotfix]
1010

1111
jobs:
1212
build:

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"command": {
66
"version": {
77
"conventionalCommits": true,
8-
"allowBranch": ["main", "rc"]
8+
"allowBranch": ["main", "rc", "hotfix"]
99
}
1010
}
1111
}

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
1414
"lint:md": "prettier --write \"**/*.md\" >/dev/null && markdownlint \"{,documentation}/*.md\" --fix --dot --ignore-path .gitignore",
1515
"lint:yml": "prettier --write \".github/**/*.yml\" >/dev/null",
1616
"lint:json": "prettier --write \"*.json\" >/dev/null",
17-
"publish:next": "lerna publish from-package --dist-tag next --yes",
18-
"publish:rc": "lerna publish from-package --dist-tag rc --yes",
19-
"publish:latest": "lerna publish from-package --yes",
20-
"version:next": "npm run util:is-in-sync-with-origin-main && npm run util:is-working-tree-clean && lerna version --conventional-prerelease --preid next --no-git-tag-version --no-push --yes && npm run util:sync-linked-package-versions -- next",
21-
"version:rc": "npm run util:is-in-sync-with-origin-rc && npm run util:is-working-tree-clean && lerna version --conventional-prerelease --preid rc --no-git-tag-version --no-push --yes && npm run util:sync-linked-package-versions -- rc",
22-
"version:latest": "npm run util:is-in-sync-with-origin-main && npm run util:is-working-tree-clean && lerna version --conventional-commits --create-release github --no-git-tag-version --no-push --yes && npm run util:sync-linked-package-versions -- latest",
17+
"version:latest": "./support/release.sh version",
18+
"publish:latest": "./support/release.sh publish",
19+
"version:next": "./support/release.sh version next",
20+
"publish:next": "./support/release.sh publish next",
21+
"version:rc": "./support/release.sh version rc",
22+
"publish:rc": "./support/release.sh publish rc",
23+
"version:hotfix": "./support/release.sh version hotfix",
24+
"publish:hotfix": "./support/release.sh publish hotfix",
2325
"prepare": "husky install",
2426
"start": "turbo run start --log-order=stream",
2527
"test": "turbo run test --log-order=stream",
26-
"util:is-in-sync-with-origin-main": "[ \"$(git rev-parse --abbrev-ref HEAD)\" = \"main\" ] && [ \"$(git rev-parse main)\" = \"$(git rev-parse origin/main)\" ]",
27-
"util:is-in-sync-with-origin-rc": "[ \"$(git rev-parse --abbrev-ref HEAD)\" = \"rc\" ] && [ \"$(git rev-parse rc)\" = \"$(git rev-parse origin/rc)\" ]",
2828
"util:is-next-deployable": "tsx support/isNextDeployable.ts",
29-
"util:is-working-tree-clean": "[ -z \"$(git status --porcelain=v1)\" ]",
3029
"util:push-tags": "git push origin main --follow-tags",
3130
"util:remove-next-changelog-entries": "tsx support/removeNextChangelogEntries.ts",
3231
"util:sync-linked-package-versions": "tsx support/syncLinkedPackageVersions.ts"

support/release.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# This script is used to version and publish releases and pre-releases.
5+
#
6+
# @arg1 The deployment step to run, must be either "version" or "publish".
7+
# @arg2 [optional] The pre-release tag, e.g., "next", "hotfix", or "rc".
8+
# Omit this optional argument for a "latest" release
9+
10+
help() {
11+
[ -n "$1" ] && printf "%s\n" "$@"
12+
echo "Usage: ./release.sh <version | publish> [<pre-release-tag>]"
13+
exit 1
14+
}
15+
16+
correct_branch_checked_out() {
17+
[ "$(git rev-parse --abbrev-ref HEAD)" = "$branch" ]
18+
}
19+
20+
in_sync_with_origin() {
21+
[ "$(git rev-parse "$branch")" = "$(git rev-parse "origin/$branch")" ]
22+
}
23+
24+
working_tree_clean() {
25+
[ -z "$(git status --porcelain=v1)" ]
26+
}
27+
28+
sanity_checks() {
29+
if ! correct_branch_checked_out; then
30+
help "The '$branch' branch must be checked out before deploying $dist_tag"
31+
elif ! in_sync_with_origin; then
32+
help "The repository must be in sync with 'origin/$branch'"
33+
elif ! working_tree_clean; then
34+
help "The working tree must be clean before running this script." \
35+
"Use 'git stash push' to save your changes for later."
36+
fi
37+
}
38+
39+
version() {
40+
sanity_checks
41+
42+
if [ -z "$dist_tag" ]; then
43+
lerna version --no-push --no-git-tag-version --yes \
44+
--conventional-commits \
45+
--create-release github
46+
else
47+
lerna version --no-push --no-git-tag-version --yes \
48+
--conventional-prerelease \
49+
--preid "$dist_tag"
50+
fi
51+
52+
# default to latest if no dist tag was provided in the second argument
53+
npm run util:sync-linked-package-versions -- "${dist_tag:-latest}"
54+
}
55+
56+
publish() {
57+
# only add the dist-tag flag if the second argument was provided
58+
lerna publish from-package --yes ${dist_tag:+--dist-tag $dist_tag}
59+
}
60+
61+
main() {
62+
cmd="$1"
63+
dist_tag="$2"
64+
65+
if [ -z "$dist_tag" ] || [ "$dist_tag" = "next" ]; then
66+
branch="main"
67+
else
68+
branch="$dist_tag"
69+
fi
70+
71+
if [ -z "$cmd" ]; then
72+
help "missing argument(s). Specify the command: 'version' or 'publish'"
73+
elif [ "$cmd" = "version" ]; then
74+
version
75+
elif [ "$cmd" = "publish" ]; then
76+
publish
77+
else
78+
help "invalid command: '$cmd'"
79+
exit 1
80+
fi
81+
}
82+
83+
main "$@"

support/syncLinkedPackageVersions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const exec = promisify(childProcess.exec);
99

1010
const releaseTarget = process.argv[2];
11-
if (!["latest", "next", "rc"].includes(releaseTarget)) {
11+
if (!["latest", "next", "rc", "hotfix"].includes(releaseTarget)) {
1212
throw new Error(`Invalid release target: "${releaseTarget}"`);
1313
}
1414

0 commit comments

Comments
 (0)