This repository was archived by the owner on Jan 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (173 loc) · 6.72 KB
/
cd.yaml
File metadata and controls
209 lines (173 loc) · 6.72 KB
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
name: CD
on:
push:
branches-ignore:
- '**'
tags:
- 'release-prod-*'
- 'release-pr-*'
env:
GITHUB_API_URL_BASE: https://api.github.com/repos/${{ github.repository }}
# Node.js
NODE_VERSION: 'lts/*'
PNPM_VERSION: '9'
NPM_REGISTRY_URL: 'https://registry.npmjs.org'
NODE_AUTH_TOKEN: ${{ secrets.READ_ONLY_NPM_TOKEN }}
HUSKY: 0
# Nx Cloud
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
wait-for-ci:
runs-on: ${{ vars.NOL_RUNNER }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: ${{ env.NPM_REGISTRY_URL }}
# cache: 'pnpm'
- name: Wait for CI
uses: fountainhead/action-wait-for-check@v1.1.0
id: wait-for-ci
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: build
- name: Shutdown workflow
if: steps.wait-for-ci.outputs.conclusion != 'success'
run: node -e 'process.exit(1)'
release:
needs: wait-for-ci
if: startsWith(github.event.ref, 'refs/tags/release-prod-')
runs-on: ${{ vars.NOL_RUNNER }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: ${{ env.NPM_REGISTRY_URL }}
# cache: 'pnpm'
- name: Get release version
run: echo "DEPLOY_VERSION=v$(cat ./lerna.json | jq -r '.version')" >> $GITHUB_ENV
- name: Install dependencies
env:
NODE_AUTH_TOKEN: ${{ secrets.READ_ONLY_NPM_TOKEN }}
run: pnpm install
- run: pnpm run build
- name: Release
env:
NODE_AUTH_TOKEN: ${{ secrets.READ_WRITE_NPM_TOKEN }}
run: pnpm -r publish --no-git-checks
tag:
needs: release
if: success()
runs-on: ${{ vars.NOL_RUNNER }}
steps:
- uses: actions/checkout@v4
- name: Get released version
run: echo "TAG_NAME=v$(cat ./lerna.json | jq -r '.version')" >> $GITHUB_ENV
- name: Create tag object
id: create-tag-object
# https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-tag-object
run: |
curl --url $GITHUB_API_URL_BASE/git/tags \
-f \
--request POST \
-H 'Authorization: token ${{ secrets.TRIPLE_BOT_GITHUB_TOKEN }}' \
-H 'Content-Type: application/json' \
-d "{\"tag\":\"$TAG_NAME\",\"message\":\"released at \`${{ github.event.updated_at }}\`\",\"object\":\"${GITHUB_SHA}\",\"type\":\"commit\"}" \
> tag.json
echo "::set-output name=tag-sha::$(node -p -e 'require(`./tag.json`).sha')"
- name: Check tag ref exist
id: check-tag-ref
# https://docs.github.com/en/free-pro-team@latest/rest/reference/git#get-a-reference
run: |
curl --url $GITHUB_API_URL_BASE/git/refs/tags/$TAG_NAME \
-sI \
-o /dev/null \
-w "%{http_code}" \
-H 'Authorization: token ${{ secrets.TRIPLE_BOT_GITHUB_TOKEN }}' \
> status
echo "::set-output name=status::$(cat status)"
- name: Create new tag ref
if: ${{ steps.check-tag-ref.outputs.status != '200' }}
env:
TAG_SHA: ${{ steps.create-tag-object.outputs.tag-sha }}
# https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
run: |
curl --url $GITHUB_API_URL_BASE/git/refs \
-f \
--request POST \
-H 'Authorization: token ${{ secrets.TRIPLE_BOT_GITHUB_TOKEN }}' \
-H 'Content-Type: application/json' \
-d "{\"ref\":\"refs/tags/$TAG_NAME\",\"sha\":\"$TAG_SHA\"}"
- name: Update tag ref
if: ${{ steps.check-tag-ref.outputs.status == '200' }}
env:
TAG_SHA: ${{ steps.create-tag-object.outputs.tag-sha }}
# https://docs.github.com/en/free-pro-team@latest/rest/reference/git#update-a-reference
run: |
curl --url $GITHUB_API_URL_BASE/git/refs/tags/$TAG_NAME \
-f \
--request PATCH \
-H 'Authorization: token ${{ secrets.TRIPLE_BOT_GITHUB_TOKEN }}' \
-H 'Content-Type: application/json' \
-d "{\"force\":true,\"sha\":\"${TAG_SHA}\"}"
canary-release:
needs: wait-for-ci
if: startsWith(github.event.ref, 'refs/tags/release-pr-')
runs-on: ${{ vars.NOL_RUNNER }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: ${{ env.NPM_REGISTRY_URL }}
# cache: 'pnpm'
- name: Get release version
env:
TAG_NAME: ${{ github.event.ref }}
run: |
NEXT_VERSION=$(node -e "const [major, minor, patch] = require('./lerna.json').version.split('.');console.log(['v'+major, minor, parseInt(patch, 10) + 1].join('.'))")
PR_NUMBER=${TAG_NAME:21} # refs/tags/release-pr-<num>에서 <num>만 추출
REF_COUNT=$(node -p -e "Math.max(0, parseInt((\"$(git describe --always --long --dirty --match "v*.*.*")\".match(/^(?:.*@)?.*-(\d+)-.*?$/) || ['0', '0'])[1], 10) - 1)")
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "DEPLOY_VERSION=$NEXT_VERSION-pr-$PR_NUMBER.$REF_COUNT" >> $GITHUB_ENV
- name: Install dependencies
env:
NODE_AUTH_TOKEN: ${{ secrets.READ_ONLY_NPM_TOKEN }}
run: pnpm install
- run: pnpm run build
- run: |
pnpm exec lerna version $DEPLOY_VERSION \
--amend \
--force-publish \
--ignore-scripts \
--no-git-tag-version \
--preid "pr-$PR_NUMBER" \
--yes
- name: Publish as canary
env:
NODE_AUTH_TOKEN: ${{ secrets.READ_WRITE_NPM_TOKEN }}
run: pnpm -r publish --tag canary --no-git-checks
- name: Notify released version on pull request
run: |
curl \
--url $GITHUB_API_URL_BASE/issues/${{ env.PR_NUMBER }}/comments \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-f --request POST \
-d "{\"body\":\"${{ env.DEPLOY_VERSION }} has been published!\"}"