11name : Build -> Test -> Release
22
33on :
4- push :
5- branches :
6- - main
7- - next
8- - alpha
9- - beta
10- - ' *.x*'
4+ release :
5+ types :
6+ - published
117
128env :
139 HUSKY : 0
@@ -16,18 +12,23 @@ jobs:
1612 release :
1713 name : Build -> Test -> Release
1814 runs-on : ubuntu-latest
15+ permissions :
16+ contents : read
17+ id-token : write
1918
2019 steps :
2120 - name : Checkout
2221 uses : actions/checkout@v6
2322 with :
2423 fetch-depth : 0
24+ ref : ${{ github.event.release.tag_name }}
2525
2626 - name : Setup LTS Node
2727 uses : actions/setup-node@v6
2828 with :
2929 node-version : ' lts/*'
3030 cache : ' yarn'
31+ registry-url : ' https://registry.npmjs.org'
3132
3233 - name : Install dependencies
3334 run : yarn install
3839 - name : Test
3940 run : yarn test:all
4041
41- - name : Release
42- if : ${{ success() && (github.event_name != 'pull_request' || github.event.action == 'closed' && github.event.pull_request.merged == true) }}
42+ - name : Resolve release metadata
43+ id : release_meta
44+ env :
45+ RELEASE_PRERELEASE : ${{ github.event.release.prerelease }}
46+ RELEASE_TAG : ${{ github.event.release.tag_name }}
47+ run : |
48+ set -euo pipefail
49+
50+ if [[ ! "${RELEASE_TAG}" =~ ^v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?)$ ]]; then
51+ echo "Release tag must match v<semver> or v<semver>-<prerelease>: ${RELEASE_TAG}" >&2
52+ exit 1
53+ fi
54+
55+ VERSION="${BASH_REMATCH[1]}"
56+
57+ if [[ "${VERSION}" == *-* ]]; then
58+ if [[ "${RELEASE_PRERELEASE}" != "true" ]]; then
59+ echo "Prerelease tag ${RELEASE_TAG} requires the GitHub Release to be marked as a prerelease." >&2
60+ exit 1
61+ fi
62+
63+ CHANNEL="${VERSION#*-}"
64+ CHANNEL="${CHANNEL%%.*}"
65+ CHANNEL="$(printf '%s' "${CHANNEL}" | tr '[:upper:]' '[:lower:]')"
66+
67+ case "${CHANNEL}" in
68+ alpha)
69+ DIST_TAG="alpha"
70+ ;;
71+ beta)
72+ DIST_TAG="beta"
73+ ;;
74+ *)
75+ DIST_TAG="next"
76+ ;;
77+ esac
78+ else
79+ if [[ "${RELEASE_PRERELEASE}" == "true" ]]; then
80+ echo "Stable tag ${RELEASE_TAG} cannot be published from a prerelease GitHub Release." >&2
81+ exit 1
82+ fi
83+
84+ DIST_TAG="latest"
85+ fi
86+
87+ echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
88+ echo "dist_tag=${DIST_TAG}" >> "${GITHUB_OUTPUT}"
89+
90+ - name : Prepare @trrack/core package
91+ env :
92+ RELEASE_VERSION : ${{ steps.release_meta.outputs.version }}
93+ run : |
94+ set -euo pipefail
95+
96+ cp packages/core/package.json packages/core/dist/package.json
97+ cp packages/core/README.md packages/core/dist/README.md
98+ cp packages/core/CHANGELOG.md packages/core/dist/CHANGELOG.md
99+ cp LICENSE packages/core/dist/LICENSE
100+
101+ npm pkg set version="${RELEASE_VERSION}" --prefix packages/core/dist
102+ npm pkg delete scripts --prefix packages/core/dist
103+
104+ - name : Publish @trrack/core
43105 env :
44- GITHUB_TOKEN : ${{ secrets.TRRACK_GITHUB_TOKEN }}
45- NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
46- run : yarn workspace @trrack /core release
106+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
107+ run : npm publish --access public --provenance --tag " ${{ steps.release_meta.outputs.dist_tag }}"
108+ working-directory : packages /core/dist
0 commit comments