-
-
Notifications
You must be signed in to change notification settings - Fork 0
607 lines (492 loc) · 19.3 KB
/
main.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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
name: build, test & publish on all platforms
on:
push:
tags:
- '*'
jobs:
verify-and-run:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all tags and history
- name: Get the latest commit SHA
id: get_sha
run: echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Debug - Print commit SHA
run: echo "Commit SHA - ${{ env.COMMIT_SHA }}"
- name: Check if commit is on main
id: check_main
run: |
# Fetch all branches to ensure we have the latest references
git fetch origin
# Check if the commit is in the main branch history
if git merge-base --is-ancestor ${{ env.COMMIT_SHA }} origin/main; then
echo "COMMIT_ON_MAIN=true" >> $GITHUB_ENV
else
echo "COMMIT_ON_MAIN=false" >> $GITHUB_ENV
fi
- name: Exit if not on main
if: env.COMMIT_ON_MAIN == 'false'
run: |
echo "This tag's commit is not on the main branch. Exiting workflow."
exit 1
- name: Verify and proceed
if: env.COMMIT_ON_MAIN == 'true'
run: echo "Tag is on main. Proceeding with the workflow..."
linux-x64:
needs: [verify-and-run]
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd /home/runner/work/gild-cli/gild-cli/main && bun install
- name: run tests
run: |
cd /home/runner/work/gild-cli/gild-cli/main && bun test --coverage
- name: build binary
run: |
cd /home/runner/work/gild-cli/gild-cli/main && bun run make
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_linux-x64
path: /home/runner/work/gild-cli/gild-cli/main/dist/gild
windows-x64:
needs: [verify-and-run]
runs-on: windows-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd D:/a/gild-cli/gild-cli/main
bun install
- name: run tests
run: |
cd D:/a/gild-cli/gild-cli/main && bun test --coverage
- name: build binary
run: |
cd D:/a/gild-cli/gild-cli/main
bun run make
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_windows-x64
path: D:/a/gild-cli/gild-cli/main/dist/gild.exe
darwin-x64:
needs: [verify-and-run]
runs-on: macOS-13
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun install
- name: run tests
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun test --coverage
- name: build binary # not using "make" script to be sure target is correct
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun build ./index.ts --compile --target=bun-darwin-x64 --outfile dist/gild
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_darwin-x64
path: /Users/runner/work/gild-cli/gild-cli/main/dist/gild
darwin-arm64:
needs: [verify-and-run]
runs-on: macOS-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun install
- name: run tests
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun test --coverage
- name: build binary # not using "make" script to be sure target is correct
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun build ./index.ts --compile --target=bun-darwin-arm64 --outfile dist/gild
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_darwin-arm64
path: /Users/runner/work/gild-cli/gild-cli/main/dist/gild
linux-x64-binary-test:
needs: [linux-x64]
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v4
with:
path: gild-cli
- name: download all artifacts
uses: actions/download-artifact@v4
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare linux-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ github.ref_name }}\"}" gild-cli/npm/gild-linux-x64/package.json > gild-cli/npm/gild-linux-x64/package.tmp.json && mv gild-cli/npm/gild-linux-x64/package.tmp.json gild-cli/npm/gild-linux-x64/package.json
cp ./gild-cli_${{ github.ref_name }}_linux-x64/gild gild-cli/npm/gild-linux-x64/gild
- name: Display structure of downloaded files
run: ls -R
- name: setup npm
run: |
cd gild-cli/npm/gild
npm link
- name: install gild via npm
run: npm install -g @samifouad/gild
- name: Display structure of files + npm
run: |
ls -R
npm list @samifouad/gild
- name: sanity check
run: gild check
darwin-x64-binary-test:
needs: [darwin-x64]
runs-on: macOS-13 # should default to x64, TODO: might need to specify target some how
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: confirm which arch
run: uname -m
- name: Display structure of downloaded files
run: ls -R
darwin-arm64-binary-test:
needs: [darwin-arm64]
runs-on: macOS-latest # defaults to arm64 as of macOS14
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: confirm which arch
run: uname -m
- name: Display structure of downloaded files
run: ls -R
windows-x64-binary-test:
needs: [windows-x64]
runs-on: windows-latest # defaults to 2022, TODO: might be worth tested 2019 also
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: confirm which arch
run: wmic cpu get DataWidth
- name: Display structure of downloaded files
run: Get-ChildItem -Recurse
binary-tests:
needs: [linux-x64-binary-test, darwin-x64-binary-test, darwin-arm64-binary-test, windows-x64-binary-test]
runs-on: ubuntu-latest
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
publish-gh-release-homebrew:
needs: [binary-tests]
runs-on: ubuntu-latest
steps:
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: download artifacts
uses: actions/download-artifact@v4
- name: release commit hash
run: echo ${{ github.sha }} > release.txt
- name: tarball for linux-x64
run: tar -czf gild-cli_${{ github.ref_name }}_linux-x64.tar.gz gild-cli_${{ github.ref_name }}_linux-x64/gild
- name: sha256 for linux-x64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_linux-x64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_linux-x64.txt
- name: tarball for darwin-arm64
run: tar -czf gild-cli_${{ github.ref_name }}_darwin-arm64.tar.gz gild-cli_${{ github.ref_name }}_darwin-arm64/gild
- name: sha256 for darwin-arm64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_darwin-arm64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_darwin-arm64.txt
- name: tarball for darwin-x64
run: tar -czf gild-cli_${{ github.ref_name }}_darwin-x64.tar.gz gild-cli_${{ github.ref_name }}_darwin-x64/gild
- name: sha256 for darwin-x64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_darwin-x64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_darwin-x64.txt
- name: tarball for windows-x64
run: tar -czf gild-cli_${{ github.ref_name }}_windows-x64.tar.gz gild-cli_${{ github.ref_name }}_windows-x64/gild.exe
- name: sha256 for windows-x64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_windows-x64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_windows-x64.txt
- name: release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ secrets.GH_TOKEN }}
files: |
gild-cli_${{ github.ref_name }}_darwin-arm64.tar.gz
gild-cli_${{ github.ref_name }}_darwin-arm64.txt
gild-cli_${{ github.ref_name }}_darwin-x64.tar.gz
gild-cli_${{ github.ref_name }}_darwin-x64.txt
gild-cli_${{ github.ref_name }}_linux-x64.tar.gz
gild-cli_${{ github.ref_name }}_linux-x64.txt
gild-cli_${{ github.ref_name }}_windows-x64.tar.gz
gild-cli_${{ github.ref_name }}_windows-x64.txt
- name: Compute and export SHA256 hashes
id: compute_hashes
run: |
# Define your targets
targets=("linux-x64" "darwin-x64" "darwin-arm64")
# Loop through each target
for target in "${targets[@]}"; do
# Compute SHA-256 hash for each target file
hash=$(shasum -a 256 "gild-cli_${{ github.ref_name }}_${target}.tar.gz" | awk '{print $1}')
# Set the environment variable
echo "${target^^}_SHA256=$hash" >> $GITHUB_ENV
done
- name: Use SHA256 Variables
run: |
# Example of using the exported environment variables
echo "Linux x64 SHA256: $LINUX_X64_SHA256"
echo "macOS x64 SHA256: $DARWIN_X64_SHA256"
echo "macoS arm64 SHA256: $DARWIN_ARM64_SHA256"
- name: checkout homebrew repo
uses: actions/checkout@v4
with:
repository: samifouad/homebrew-gild
token: ${{ secrets.GH_TOKEN }}
ref: main
path: homebrew-gild
- name: checkout gild-cli repo
uses: actions/checkout@v4
with:
path: gild-cli
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
run: sudo apt-get install -y jq
- name: Update JSON file
run: |
# Use jq to update or create JSON file
echo '{}' | jq \
--arg linux_x64_url "https://github.com/samifouad/gild-cli/releases/download/${{ github.ref_name }}/gild_cli_${{ github.ref_name }}_linux_x64.tar.gz" \
--arg linux_x64_hash "${{ env.LINUX-X64_SHA256 }}" \
--arg darwin_arm64_url "https://github.com/samifouad/gild-cli/releases/download/${{ github.ref_name }}/gild_cli_${{ github.ref_name }}_darwin_arm64.tar.gz" \
--arg darwin_arm64_hash "${{ env.DARWIN-ARM64_SHA256 }}" \
--arg darwin_x64_url "https://github.com/samifouad/gild-cli/releases/download/${{ github.ref_name }}/gild_cli_${{ github.ref_name }}_darwin_x64.tar.gz" \
--arg darwin_x64_hash "${{ env.DARWIN-X64_SHA256 }}" \
--arg version "${{ github.ref_name }}" \
'. + {
linux_x64_url: $linux_x64_url,
linux_x64_hash: $linux_x64_hash,
darwin_arm64_url: $darwin_arm64_url,
darwin_arm64_hash: $darwin_arm64_hash,
darwin_x64_url: $darwin_x64_url,
darwin_x64_hash: $darwin_x64_hash,
version: $version
}' > homebrew.json
- name: verify homebrew.json
run: |
cat homebrew.json
- name: move homebrew.ts
run: |
mv gild-cli/homebrew.ts homebrew.ts
ls -R
- name: run homebrew.ts & print output
run: |
bun run homebrew.ts
cat homebrew-gild/Formula/gild.rb
- name: Set up SSH
env:
RSA_PRIVATE_KEY: ${{ secrets.SIGNING_KEY }}
run: |
echo "$RSA_PRIVATE_KEY" > /tmp/id_rsa
chmod 600 /tmp/id_rsa
eval "$(ssh-agent -s)"
ssh-add /tmp/id_rsa
- name: push changes to homebrew repo
run: |
cd homebrew-gild
git config --global user.email "[email protected]"
git config --global user.name "Sami Fouad"
git config --global gpg.format ssh
git config --global commit.gpgsign true
git config --global tag.gpgSign true
git config --global user.signingkey /tmp/id_rsa
git add .
git commit -m 'automated version bump to ${{ github.ref_name }}'
git tag ${{ github.ref_name }} -m 'automated version bump to ${{ github.ref_name }}'
git push --follow-tags
- name: stop action
run: |
exit 1
publish-linux-x64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: checkout code
uses: actions/checkout@v4
- name: download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare linux-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-linux-x64/package.json > npm/gild-linux-x64/package.tmp.json && mv npm/gild-linux-x64/package.tmp.json npm/gild-linux-x64/package.json
cp ./gild-cli_${{ env.CURRENT_TAG }}_linux-x64/gild npm/gild-linux-x64/gild
- name: configure npm & publish
run: |
cd npm/gild-linux-x64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-windows-x64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
# - name: Display structure of downloaded files
# run: dir /s
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare gild-windows-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-windows-x64/package.json > npm/gild-windows-x64/package.tmp.json && mv npm/gild-windows-x64/package.tmp.json npm/gild-windows-x64/package.json
cp gild-cli_${{ env.CURRENT_TAG }}_windows-x64/gild.exe npm/gild-windows-x64/gild.exe
- name: Configure npm & publish
run: |
cd npm/gild-windows-x64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-darwin-x64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare gild-darwin-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-darwin-x64/package.json > npm/gild-darwin-x64/package.tmp.json && mv npm/gild-darwin-x64/package.tmp.json npm/gild-darwin-x64/package.json
cp ./gild-cli_${{ env.CURRENT_TAG }}_darwin-x64/gild npm/gild-darwin-x64/gild
- name: Configure npm & publish
run: |
cd npm/gild-darwin-x64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-darwin-arm64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare gild-darwin-arm64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-darwin-arm64/package.json > npm/gild-darwin-arm64/package.tmp.json && mv npm/gild-darwin-arm64/package.tmp.json npm/gild-darwin-arm64/package.json
cp gild-cli_${{ env.CURRENT_TAG }}_darwin-arm64/gild npm/gild-darwin-arm64/gild
- name: Configure npm & publish
run: |
cd npm/gild-darwin-arm64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-main-to-npm:
needs: [publish-windows-x64-to-npm, publish-linux-x64-to-npm, publish-darwin-x64-to-npm, publish-darwin-arm64-to-npm]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare package.json
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild/package.json > npm/gild/package.tmp.json && mv npm/gild/package.tmp.json npm/gild/package.json
- name: Configure npm & publish
run: |
cd npm/gild
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}