-
Notifications
You must be signed in to change notification settings - Fork 83
292 lines (264 loc) · 11.9 KB
/
deploy-npm.yml
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
name: Deploy to NPM
on:
workflow_dispatch:
workflow_call:
inputs:
is_called:
type: string
required: true
secrets:
RS_PROD_BUGSNAG_API_KEY:
required: true
NPM_TOKEN:
required: true
SLACK_BOT_TOKEN:
required: true
SLACK_RELEASE_CHANNEL_ID:
required: true
permissions:
id-token: write # Allows the JWT to be requested from GitHub's OIDC provider
contents: read # Required for actions/checkout
env:
NODE_OPTIONS: '--no-warnings'
jobs:
deploy:
name: Deploy to NPM
# As we publish the NPM package with provenance, we must use GitHub-hosted runners
runs-on: ubuntu-latest
if: ${{ inputs.is_called == 'true' || (github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.sha }}
- name: Get new version number
run: |
current_version_v1=$(jq -r .version packages/analytics-v1.1/package.json)
current_version_sw=$(jq -r .version packages/analytics-js-service-worker/package.json)
current_version_cookie_utils=$(jq -r .version packages/analytics-js-cookies/package.json)
current_version=$(jq -r .version packages/analytics-js/package.json)
echo "CURRENT_VERSION_V1_VALUE=$current_version_v1" >> $GITHUB_ENV
echo "CURRENT_VERSION_SW_VALUE=$current_version_sw" >> $GITHUB_ENV
echo "CURRENT_VERSION_COOKIE_UTILS_VALUE=$current_version_cookie_utils" >> $GITHUB_ENV
echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV
- name: Get versions in NPM
run: |
current_npm_version=$(npm show @rudderstack/analytics-js version 2>/dev/null || echo "not found")
echo "CURRENT_NPM_VERSION=$current_npm_version" >> $GITHUB_ENV
current_npm_version_sw=$(npm show @rudderstack/analytics-js-service-worker version 2>/dev/null || echo "not found")
echo "CURRENT_NPM_VERSION_SW=$current_npm_version_sw" >> $GITHUB_ENV
current_npm_version_cookie_utils=$(npm show @rudderstack/analytics-js-cookies version 2>/dev/null || echo "not found")
echo "CURRENT_NPM_VERSION_COOKIE_UTILS=$current_npm_version_cookie_utils" >> $GITHUB_ENV
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
env:
HUSKY: 0
REMOTE_MODULES_BASE_PATH: 'https://cdn.rudderlabs.com/v3/modern/plugins'
BUGSNAG_API_KEY: ${{ secrets.RS_PROD_BUGSNAG_API_KEY }}
BUGSNAG_RELEASE_STAGE: 'production'
run: |
npm run setup:ci
- name: Build release artifacts
env:
BUGSNAG_API_KEY: ${{ secrets.RS_PROD_BUGSNAG_API_KEY }}
BUGSNAG_RELEASE_STAGE: 'production'
run: |
npm run build:package
npm run build:package:modern
- name: Get the two latest monorepo versions
run: |
CURRENT_VERSION=$(git tag -l "v3*" --sort=-version:refname | head -n 1)
LAST_VERSION=$(git tag -l "v3*" --sort=-version:refname | head -n 2 | awk 'NR == 2 { print $1 }')
echo "Current version: $CURRENT_VERSION"
echo "Previous version: $LAST_VERSION"
echo "current_monorepo_version=$(echo $CURRENT_VERSION)" >> $GITHUB_ENV
echo "last_monorepo_version=$(echo $LAST_VERSION)" >> $GITHUB_ENV
echo "DATE=$(date)" >> $GITHUB_ENV
- name: Publish package to NPM
env:
HUSKY: 0
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: |
# Remove unnecessary fields from package.json before publishing
./scripts/make-package-json-publish-ready.sh
npm set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npx nx release publish --base=${{ env.last_monorepo_version }} --head=${{ env.current_monorepo_version }}
# Reset the changes made to package.json
git reset --hard
git clean -fd
- name: Wait for NPM propagation
run: |
# It has been observed that the NPM package is not immediately available after publish.
echo "Waiting for NPM propagation..."
sleep 15
- name: Get versions in NPM after publish
run: |
npm cache clean --force
new_npm_version=$(npm show @rudderstack/analytics-js version 2>/dev/null || echo "not found")
echo "NEW_NPM_VERSION=$new_npm_version" >> $GITHUB_ENV
new_npm_version_sw=$(npm show @rudderstack/analytics-js-service-worker version 2>/dev/null || echo "not found")
echo "NEW_NPM_VERSION_SW=$new_npm_version_sw" >> $GITHUB_ENV
new_npm_version_cookie_utils=$(npm show @rudderstack/analytics-js-cookies version 2>/dev/null || echo "not found")
echo "NEW_NPM_VERSION_COOKIE_UTILS=$new_npm_version_cookie_utils" >> $GITHUB_ENV
- name: Debug environment variables
continue-on-error: true
run: |
echo "CURRENT_NPM_VERSION=${{ env.CURRENT_NPM_VERSION }}"
echo "NEW_NPM_VERSION=${{ env.NEW_NPM_VERSION }}"
echo "CURRENT_NPM_VERSION_SW=${{ env.CURRENT_NPM_VERSION_SW }}"
echo "NEW_NPM_VERSION_SW=${{ env.NEW_NPM_VERSION_SW }}"
echo "CURRENT_NPM_VERSION_COOKIE_UTILS=${{ env.CURRENT_NPM_VERSION_COOKIE_UTILS }}"
echo "NEW_NPM_VERSION_COOKIE_UTILS=${{ env.NEW_NPM_VERSION_COOKIE_UTILS }}"
- name: Send message to Slack channel
if: env.CURRENT_NPM_VERSION != env.NEW_NPM_VERSION && env.NEW_NPM_VERSION != 'not found'
id: slack
continue-on-error: true
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
PROJECT_NAME: 'JS SDK NPM Package'
NPM_PACKAGE_URL: 'https://www.npmjs.com/package/@rudderstack/analytics-js'
RELEASES_URL: 'https://github.com/rudderlabs/rudder-sdk-js/releases/tag/@rudderstack/analytics-js@'
with:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New Release: ${{ env.PROJECT_NAME }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
"image_url": "https://img.icons8.com/color/452/npm.png",
"alt_text": "NPM Icon"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "For more details, check the full release notes <${{env.RELEASES_URL}}${{ env.CURRENT_VERSION_VALUE }}|here>."
}
]
}
]
}
- name: Send message to Slack channel for Service Worker
if: env.CURRENT_NPM_VERSION_SW != env.NEW_NPM_VERSION_SW && env.NEW_NPM_VERSION_SW != 'not found'
id: slackSw
continue-on-error: true
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
PROJECT_NAME: 'JS SDK Service Worker NPM Package'
NPM_PACKAGE_URL: 'https://www.npmjs.com/package/@rudderstack/analytics-js-service-worker'
RELEASES_URL: 'https://github.com/rudderlabs/rudder-sdk-js/releases/tag/@rudderstack/analytics-js-service-worker@'
with:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_SW_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New Release: ${{ env.PROJECT_NAME }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_SW_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
"image_url": "https://img.icons8.com/color/452/npm.png",
"alt_text": "NPM Icon"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "For more details, check the full release notes <${{ env.RELEASES_URL }}${{ env.CURRENT_VERSION_SW_VALUE }}|here>."
}
]
}
]
}
- name: Send message to Slack channel for cookie utilities
if: env.CURRENT_NPM_VERSION_COOKIE_UTILS != env.NEW_NPM_VERSION_COOKIE_UTILS && env.NEW_NPM_VERSION_COOKIE_UTILS != 'not found'
id: slack-cookie-utils
continue-on-error: true
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
PROJECT_NAME: 'JS SDK Cookies Utilities'
NPM_PACKAGE_URL: 'https://www.npmjs.com/package/@rudderstack/analytics-js-cookies'
RELEASES_URL: 'https://github.com/rudderlabs/rudder-sdk-js/releases/tag/@rudderstack/analytics-js-cookies@'
with:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New Release: ${{ env.PROJECT_NAME }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.NPM_PACKAGE_URL }}|v${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
"image_url": "https://img.icons8.com/color/452/npm.png",
"alt_text": "NPM Icon"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "For more details, check the full release notes <${{ env.RELEASES_URL }}${{ env.CURRENT_VERSION_COOKIE_UTILS_VALUE }}|here>."
}
]
}
]
}