-
Notifications
You must be signed in to change notification settings - Fork 11
320 lines (284 loc) · 12.7 KB
/
test-release-sync.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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
name: Test, release, and sync
on:
pull_request:
paths:
- "**"
- ".github/workflows/**"
push:
branches:
- main
paths:
- "**"
- ".github/workflows/**"
jobs:
update-lock-file:
if: github.head_ref != 'changeset-release/main'
name: "Update lock file for PRs before checks and build"
runs-on: "ubuntu-22.04"
permissions:
contents: write
pull-requests: write
outputs:
VERIFIED_LOCK_COMMIT: ${{ steps.sync-lock-file.outputs.VERIFIED_LOCK_COMMIT }}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
with:
# use branch name instead of triggering ref so we can commit to the PR branch:
ref: ${{ github.head_ref }}
fetch-depth: 2
- name: "Setup Node"
uses: "actions/setup-node@v3"
env:
SKIP_YARN_COREPACK_CHECK: true
with:
node-version-file: ".nvmrc"
- name: "Install dependencies with yarn cache"
uses: ./.github/actions/yarn-nm-install
with:
cwd: "."
install-mode: "update-lock-only"
# Since we are in update-lock-only mode the resulting yarn cache is much smaller and less useful
# for the rest of the steps. But since this is the first step and the cache is restored for each
# step in the workflow, they all get the same useless cache unless we set a different prefix here:
cache-prefix: "update-lock-file-for-prs"
- name: "Commit and push changes if modified"
id: sync-lock-file
run: |
if [[ $(git rev-parse --abbrev-ref HEAD) == "main" ]] && ! git diff-index --quiet HEAD; then
echo "Lock file must not be modified by CI on main branch."
exit 1;
fi
git config --global user.name 'Lightspark Eng'
git config --global user.email '[email protected]'
git add -A
git diff-index --quiet HEAD || git commit -nm "CI update lock file for PR"
git push
echo "$(git rev-parse HEAD)"
echo "VERIFIED_LOCK_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
checks:
# Wait to see if the lock file should be updated before running checks:
needs: "update-lock-file"
runs-on: "ubuntu-22.04"
strategy:
matrix:
node-version: ["18.x", "20.x"]
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
with:
ref: ${{ needs.update-lock-file.outputs.VERIFIED_LOCK_COMMIT }}
- name: "Setup Node v${{ matrix.node-version }}"
uses: "actions/setup-node@v3"
env:
SKIP_YARN_COREPACK_CHECK: true
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies with yarn cache
uses: ./.github/actions/yarn-nm-install
with:
cwd: "."
- name: Setup .lightsparkenv file
run: |
echo 'export LIGHTSPARK_WALLET_BASE_URL="api.dev.dev.sparkinfra.net"' > ~/.lightsparkenv
echo 'export LIGHTSPARK_ACCOUNT_ID="${{ secrets.LIGHTSPARK_TEST_ACCOUNT_ID }}"' >> ~/.lightsparkenv
echo 'export LIGHTSPARK_JWT_PRIV_KEY="${{ secrets.LIGHTSPARK_TEST_ACCOUNT_JWT_PRIV_KEY }}"' >> ~/.lightsparkenv
echo 'export LIGHTSPARK_JWT_PUB_KEY="${{ secrets.LIGHTSPARK_TEST_ACCOUNT_JWT_PUB_KEY }}"' >> ~/.lightsparkenv
- name: Setup .lightsparkapienv file
run: |
echo 'export LIGHTSPARK_API_TOKEN_CLIENT_ID="${{ secrets.LIGHTSPARK_TEST_ACCOUNT_API_TOKEN_CLIENT_ID }}"' > ~/.lightsparkapienv
echo 'export LIGHTSPARK_API_TOKEN_CLIENT_SECRET="${{ secrets.LIGHTSPARK_TEST_ACCOUNT_API_TOKEN_CLIENT_SECRET }}"' >> ~/.lightsparkapienv
echo 'export BITCOIN_NETWORK="REGTEST"' >> ~/.lightsparkapienv
echo 'export LIGHTSPARK_BASE_URL="https://api.dev.dev.sparkinfra.net"' >> ~/.lightsparkapienv
- run: "yarn checks"
- name: "Notify failure on Slack"
if: "failure() && github.event_name == 'push'"
run: |
curl --data-binary @- --header "Content-Type: application/json" --silent "${{ secrets.SLACK_WEBHOOK_ENGINT }}" <<EOF
{
"text": ":x: ${{ github.workflow }} workflow by ${{ github.actor }} <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id}}|failed> in ${{ github.job }} on <${{ github.server_url }}/${{ github.repository }}/commit/$GITHUB_SHA|${{ github.ref_name }}>"
}
EOF
# turbo doesn't seem to parallelize builds with checks although they don't depend on one another,
# or else there's something in CI that prevents it from doing it well. Faster to keep them separate.
build:
# Wait to see if the lock file should be updated before running checks:
needs: "update-lock-file"
runs-on: "ubuntu-22.04"
strategy:
matrix:
node-version: ["18.x", "20.x"]
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
with:
ref: ${{ needs.update-lock-file.outputs.VERIFIED_LOCK_COMMIT }}
- name: "Setup Node v${{ matrix.node-version }}"
uses: "actions/setup-node@v3"
env:
SKIP_YARN_COREPACK_CHECK: true
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies with yarn cache
uses: ./.github/actions/yarn-nm-install
with:
cwd: "."
- run: "yarn build"
- name: "Notify failure on Slack"
if: "failure() && github.event_name == 'push'"
run: |
curl --data-binary @- --header "Content-Type: application/json" --silent "${{ secrets.SLACK_WEBHOOK_ENGINT }}" <<EOF
{
"text": ":x: ${{ github.workflow }} workflow by ${{ github.actor }} <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id}}|failed> in ${{ github.job }} on <${{ github.server_url }}/${{ github.repository }}/commit/$GITHUB_SHA|${{ github.ref_name }}>"
}
EOF
release:
name: Release
needs: ["checks", "build"]
permissions:
contents: write
pull-requests: write
if: "success() && github.event_name == 'push'"
runs-on: "ubuntu-22.04"
environment: npm
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: "Setup Node"
uses: "actions/setup-node@v3"
env:
SKIP_YARN_COREPACK_CHECK: true
with:
node-version-file: ".nvmrc"
- name: Install dependencies with yarn cache
uses: ./.github/actions/yarn-nm-install
with:
cwd: "."
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# If the Version Packages PR has been created in the changesets step we should check if our workspace
# package.json files have been updated from dependency bumps and update the lock file if so:
- name: "Install dependencies with yarn cache"
id: update-lock-file-for-version-packages-pr
if: steps.changesets.outputs.published == 'false' && github.ref == 'refs/heads/main'
uses: ./.github/actions/yarn-nm-install
with:
cwd: "."
install-mode: "update-lock-only"
# check if previous step updated the lock file and commit and push if so:
- name: Update lock file for Version Packages PR
if: steps.changesets.outputs.published == 'false' && github.ref == 'refs/heads/main'
run: |
if git ls-remote --exit-code --heads origin changeset-release/main; then
git fetch origin changeset-release/main
if git show-ref --quiet changeset-release/main; then
git checkout changeset-release/main
git push --set-upstream origin changeset-release/main
git config --global user.name 'Lightspark Eng'
git config --global user.email '[email protected]'
git add -A
git diff-index --quiet HEAD || git commit -nm "CI update lock file for PR"
git push
echo "$(git rev-parse HEAD)"
else
echo "changeset-release/main branch does not exist locally."
fi
else
echo "changeset-release/main branch does not exist on remote."
fi
- name: Notify publish on Slack
if: steps.changesets.outputs.published == 'true'
# You can do something when a publish happens.
run: |
json_escape () {
printf '%s' "$1" | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
}
format_packages() {
local json_input="$1"
local formatted_output
formatted_output=$(python -c "import json; data = $json_input; formatted_data = [f\"{item['name'].replace('@lightsparkdev/', '')}@{item['version']}\" for item in data]; print(', '.join(formatted_data))")
echo "$formatted_output"
}
formatted_packages=$(format_packages '${{ steps.changesets.outputs.publishedPackages }}')
text=$(json_escape ":white_check_mark: ${{ github.actor }} <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id}}|published> new js-sdk versions from <${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}|${{ github.ref_name }}>: $formatted_packages")
curl --data-binary @- --header "Content-Type: application/json" --silent "${{ secrets.SLACK_WEBHOOK_ENGINT }}" <<EOF
{
"text": $text
}
EOF
- name: "Notify failure on Slack"
if: "failure() && github.event_name == 'push'"
run: |
curl --data-binary @- --header "Content-Type: application/json" --silent "${{ secrets.SLACK_WEBHOOK_ENGINT }}" <<EOF
{
"text": ":x: js-sdk public repo: ${{ github.workflow }} workflow by ${{ github.actor }} <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id}}|failed> in ${{ github.job }} on <${{ github.server_url }}/${{ github.repository }}/commit/$GITHUB_SHA|${{ github.ref_name }}>"
}
EOF
create-webdev-pr:
name: Create Webdev PR
if: "github.event_name == 'push'"
runs-on: "ubuntu-22.04"
environment: npm
permissions:
contents: write
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Reset develop to main
run: |
git checkout develop
git reset --hard origin/main
git push origin develop --force
git checkout main
- name: Generate a token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: "Run Copybara"
env:
TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
ls -la
git config --global user.name 'Lightspark Eng'
git config --global user.email '[email protected]'
echo "https://x-access-token:${TOKEN}@github.com" > ~/.git-credentials
on_exit() {
# See this for possible error codes from Copybara https://github.com/google/copybara/issues/236
exit_code=$?
case $exit_code in
0)
echo "Copybara completed successfully"
exit 0
;;
4)
echo "Copybara completed with no changes detected, exiting 0"
exit 0
;;
*)
echo "Copybara failed with exit code $exit_code"
exit $exit_code
;;
esac
}
curl https://lsdev-repo.s3-us-west-2.amazonaws.com/github-actions/copybara_deploy.jar --output ./copybara.jar
trap on_exit EXIT
java -jar copybara.jar ./copy.bara.sky js-sdk-push-to-webdev --nogit-destination-rebase
# - name: "Notify failure on Slack"
# if: "failure() && github.event_name == 'push'"
# run: |
# curl --data-binary @- --header "Content-Type: application/json" --silent "${{ secrets.SLACK_WEBHOOK_ENGINT }}" <<EOF
# {
# "text": ":x: ${{ github.workflow }} workflow by ${{ github.actor }} <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id}}|failed> in ${{ github.job }} on <${{ github.server_url }}/${{ github.repository }}/commit/$GITHUB_SHA|${{ github.ref_name }}>"
# }
# EOF