-
Notifications
You must be signed in to change notification settings - Fork 9
551 lines (454 loc) · 16.8 KB
/
publish.yml
File metadata and controls
551 lines (454 loc) · 16.8 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
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
name: Build and release Git-Mastery CLI
on:
workflow_run:
workflows:
- Bump version tag on merge
types:
- completed
workflow_dispatch:
push:
tags:
- "v*.*.*"
permissions:
contents: write
pull-requests: write
packages: read
issues: read
jobs:
prepare:
uses: git-mastery/actions/.github/workflows/get-latest-tag.yml@main
secrets: inherit
linux-build:
needs: prepare
if: needs.prepare.outputs.should_publish == 'true'
strategy:
matrix:
include:
- os: ubuntu-latest
arch: amd64
- os: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.os }}
env:
ARCHITECTURE: ${{ matrix.arch }}
VERSION_NUMBER: ${{ needs.prepare.outputs.version_number }}
FILENAME: gitmastery-${{ needs.prepare.outputs.version_number }}-linux-${{ matrix.arch }}
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.13"
- name: Install dependencies
run: uv sync
- name: Build binary
run: |
echo "__version__ = \"$REF_NAME\"" > app/version.py
uv run pyinstaller --onefile main.py --name $FILENAME
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/${{ env.FILENAME }}
tag_name: ${{ env.REF_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish package as artifact
uses: actions/upload-artifact@v7
with:
name: ${{ env.FILENAME }}
path: dist/${{ env.FILENAME }}
debian-build:
# We support both ARM64 and AMD64 since Debian comes with support for
# these two out of the box
needs: [prepare, linux-build]
if: needs.prepare.outputs.should_publish == 'true'
strategy:
matrix:
include:
- os: ubuntu-latest
arch: amd64
- os: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.os }}
env:
ARCHITECTURE: ${{ matrix.arch }}
VERSION: ${{ needs.prepare.outputs.version_number }}
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
path: "app"
fetch-depth: 0
- name: Extract variables
env:
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
run: |
# Get the tag's commit message
cd app/
CHANGELOG_MESSAGE=$(git show ${REF_NAME} --no-patch --pretty=format:%s)
echo "CHANGELOG_MESSAGE=${CHANGELOG_MESSAGE}" >> $GITHUB_ENV
- name: Install Debian packaging tools
run: |
sudo apt-get update
sudo apt-get install devscripts build-essential debhelper-compat
- name: Create folder structure for ${{ env.ARCHITECTURE }} distribution
run: |
mkdir gitmastery-${VERSION}-${ARCHITECTURE}
- name: Download ${{ env.ARCHITECTURE }} binaries from artifacts
uses: actions/download-artifact@v8
with:
name: gitmastery-${{ env.VERSION }}-linux-${{ env.ARCHITECTURE }}
path: gitmastery-${{ env.VERSION }}-${{ env.ARCHITECTURE }}/
- name: Create upstream tarball .orig.tar.gz
run: |
# Create .orig.tar.gz file
tar -czf gitmastery_${VERSION}.orig.tar.gz gitmastery-${VERSION}-${ARCHITECTURE}/gitmastery-${VERSION}-linux-${ARCHITECTURE}
- name: Generate Debian packaging files
working-directory: gitmastery-${{ env.VERSION }}-${{ env.ARCHITECTURE }}
# TODO: Update to something agnostic
env:
EMAIL: woojiahao1234@gmail.com
NAME: Jiahao, Woo
run: |
file gitmastery-${VERSION}-linux-${ARCHITECTURE}
# Create the debian folder
mkdir debian
# Generate the changelog
# TODO: Maybe detect if major version change, then make it urgent
dch --create -v ${VERSION}-1 -u low --package gitmastery "$CHANGELOG_MESSAGE"
# Create the control file
# TODO: Maybe detect if major version change, then make it mandatory
echo """Source: gitmastery
Maintainer: $NAME <$EMAIL>
Section: misc
Priority: optional
Standards-Version: 4.7.0
Build-Depends: debhelper-compat (= 13)
Package: gitmastery
Architecture: ${ARCHITECTURE}
Depends: ${shlibs:Depends}, ${misc:Depends}, libc6 (>= 2.35), python3
Description: execute Git-Mastery
gitmastery is a Git learning tool built by the National University of Singapore School of Computing
""" > debian/control
# Copy over the MIT license from the main app to this release
cat ../app/LICENSE > debian/copyright
mkdir debian/source
echo "3.0 (quilt)" > debian/source/format
# Provide the rules for installation, using -e to preserve the tab character as per:
# https://wiki.debian.org/Packaging/Intro
# $(DESTDIR) resolves to debian/binarypackage/ as seen in
# https://www.debian.org/doc/manuals/debmake-doc/ch06.en.html#ftn.idp1797
echo -e $"""#!/usr/bin/make -f
%:
\tdh \$@
\n
override_dh_auto_install:
\tinstall -D -m 0755 gitmastery-${VERSION}-linux-${ARCHITECTURE} debian/gitmastery/usr/bin/gitmastery
""" > debian/rules
echo """usr/bin
""" > debian/gitmastery.dirs
mkdir -p debian/source
echo """gitmastery-${VERSION}-linux-${ARCHITECTURE}
""" > debian/source/include-binaries
cat debian/rules
# Build the package
dpkg-buildpackage -us -uc -a ${ARCHITECTURE}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: gitmastery_${{ env.VERSION }}-1_${{ env.ARCHITECTURE }}.deb
tag_name: ${{ needs.prepare.outputs.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
debian-publish-apt:
needs: [prepare, debian-build]
if: needs.prepare.outputs.should_publish == 'true'
permissions: write-all
uses: git-mastery/gitmastery-apt-repo/.github/workflows/debian-apt-repo.yml@main
with:
version: ${{ needs.prepare.outputs.ref_name }}
secrets: inherit
arch-build:
needs: prepare
if: needs.prepare.outputs.should_publish == 'true'
runs-on: ubuntu-latest
env:
ARCHITECTURE: amd64
VERSION_NUMBER: ${{ needs.prepare.outputs.version_number }}
FILENAME: gitmastery-${{ needs.prepare.outputs.version_number }}-arch-amd64
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Build binary
run: |
echo "__version__ = \"$REF_NAME\"" > app/version.py
docker run --rm \
-v $PWD:/pkg \
archlinux:base-devel \
bash -c "
pacman -Sy --noconfirm curl openssl git &&
curl -LsSf https://astral.sh/uv/install.sh | sh &&
export PATH=\"/root/.local/bin:\$PATH\" &&
cd /pkg &&
uv sync &&
uv run pyinstaller --onefile main.py --name $FILENAME --distpath /pkg/dist
"
# Fix file ownership after Docker run
sudo chown -R $(id -u):$(id -g) .
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/${{ env.FILENAME }}
tag_name: ${{ env.REF_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish package as artifact
uses: actions/upload-artifact@v7
with:
name: ${{ env.FILENAME }}
path: dist/${{ env.FILENAME }}
arch-publish:
# Since Arch linux currently only supports x86_64 out of the box, we will focus
# on supporting that first
needs: [prepare, arch-build]
if: needs.prepare.outputs.should_publish == 'true'
runs-on: ubuntu-latest
env:
ARCHITECTURE: amd64
VERSION: ${{ needs.prepare.outputs.version_number }}
environment: Main
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
path: "app"
fetch-depth: 0
- name: Set environment variables
env:
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
run: |
# Get the tag's commit message
cd app/
CHANGELOG_MESSAGE=$(git show ${REF_NAME} --no-patch --pretty=format:%s)
echo "CHANGELOG_MESSAGE=${CHANGELOG_MESSAGE}" >> $GITHUB_ENV
- name: Setup SSH for Github Actions
env:
AUR_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh
echo "${AUR_PRIVATE_KEY}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts
# TODO: Maybe swap to a SoC specific account
git config --global user.name "Jiahao, Woo"
git config --global user.email "woojiahao1234@gmail.com"
git config --global init.defaultBranch master
- name: Create AUR package repository
run: git clone ssh://aur@aur.archlinux.org/gitmastery-bin.git aur-pkg
- name: Publish to AUR
env:
RELEASE_AMD64_URL: https://github.com/git-mastery/app/releases/download/${{ needs.prepare.outputs.ref_name }}/gitmastery-${{ env.VERSION }}-arch-amd64
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
run: |
cd aur-pkg
BINARY_NAME=gitmastery-${VERSION}-linux-${ARCHITECTURE}
echo -e $"""$CHANGELOG_MESSAGE
\n""" >> gitmastery.changelog
cat gitmastery.changelog
echo """# Maintainer: Jiahao, Woo <woojiahao1234@gmail.com>
pkgname=gitmastery-bin
pkgver=\"$REF_NAME\"
pkgrel=1
pkgdesc=\"Git-Mastery CLI for practicing Git\"
arch=('x86_64')
url='https://github.com/git-mastery/app'
license=('MIT')
depends=(
'python'
)
changelog=\"gitmastery.changelog\"
source=(\"${BINARY_NAME}::${RELEASE_AMD64_URL}\")
sha256sums=('SKIP')
package() {
install -D -m 0755 \"\$srcdir/$BINARY_NAME\" \"\$pkgdir/usr/bin/gitmastery\"
chmod 755 \"\$pkgdir/usr/bin/gitmastery\"
}
""" >> PKGBUILD
cat PKGBUILD
# Generate the .SRCINFO within a Docker container
# We attach the current directory (aur-pkg) as the pkg directory volume
docker run --rm \
-v $PWD:/pkg \
archlinux:base-devel \
bash -c "
pacman -Sy --noconfirm sudo git base-devel && \
useradd -m builder && \
echo 'builder ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
chown -R builder:builder /pkg && \
su builder -c 'cd /pkg && makepkg --printsrcinfo > .SRCINFO'
"
# Fix file ownership after Docker run
sudo chown -R $(id -u):$(id -g) .
git add .
git commit -m "Update package"
git push --force
windows:
needs: prepare
if: needs.prepare.outputs.should_publish == 'true'
runs-on: windows-latest
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.13"
- name: Install dependencies
run: uv sync
- name: Build binary
shell: pwsh
env:
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
run: |
$version_content = '__version__ = "{0}"' -f $env:REF_NAME
$version_content | Out-File -FilePath app/version.py -Encoding utf8
uv run pyinstaller --onefile --name gitmastery main.py
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/gitmastery.exe
tag_name: ${{ needs.prepare.outputs.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
winget-publish:
needs: [prepare, windows]
if: needs.prepare.outputs.should_publish == 'true'
runs-on: windows-latest
permissions:
contents: read
steps:
- name: Submit to WinGet
uses: vedantmgoyal9/winget-releaser@v2
with:
identifier: GitMastery.GitMastery
version: ${{ needs.prepare.outputs.version_number }}
release-tag: ${{ needs.prepare.outputs.ref_name }}
token: ${{ secrets.ORG_PAT }}
installers-regex: '\.exe$'
macos-build:
needs: prepare
if: needs.prepare.outputs.should_publish == 'true'
# We use macos-15-intel since it's the latest image that currently supports AMD64
strategy:
matrix:
include:
- os: macos-15-intel
arch: amd64
- os: macos-latest
arch: arm64
runs-on: ${{ matrix.os }}
outputs:
sha256-arm64: ${{ steps.checksum-arm64.outputs.sha256 }}
sha256-amd64: ${{ steps.checksum-amd64.outputs.sha256 }}
env:
ARCHITECTURE: ${{ matrix.arch }}
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.13"
- name: Install dependencies
run: uv sync
- name: Build binary
run: |
echo "__version__ = \"$REF_NAME\"" > app/version.py
uv run pyinstaller --onefile --name "gitmastery-$ARCHITECTURE" main.py
- name: Generate SHA256 (amd64)
if: matrix.arch == 'amd64'
id: checksum-amd64
run: |
FILENAME=gitmastery-amd64
SHA256=$(shasum -a 256 dist/$FILENAME | cut -d ' ' -f1)
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
- name: Generate SHA256 (arm64)
if: matrix.arch == 'arm64'
id: checksum-arm64
run: |
FILENAME=gitmastery-arm64
SHA256=$(shasum -a 256 dist/$FILENAME | cut -d ' ' -f1)
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/gitmastery-${{ matrix.arch }}
tag_name: ${{ needs.prepare.outputs.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
macos-publish:
needs: [prepare, macos-build]
if: needs.prepare.outputs.should_publish == 'true'
runs-on: ubuntu-latest
steps:
- name: Update Homebrew Tap
env:
GH_TOKEN: ${{ secrets.ORG_PAT }}
REF_NAME: ${{ needs.prepare.outputs.ref_name }}
VERSION_NUMBER: ${{ needs.prepare.outputs.version_number }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git clone https://x-access-token:${GH_TOKEN}@github.com/git-mastery/homebrew-gitmastery.git
cd homebrew-gitmastery
cat <<EOF > gitmastery.rb
class Gitmastery < Formula
desc "CLI tool for Git-Mastery"
homepage "https://github.com/git-mastery/cli"
version "$VERSION_NUMBER"
on_arm do
url "https://github.com/git-mastery/cli/releases/download/${REF_NAME}/gitmastery-arm64"
sha256 "${{ needs.macos-build.outputs.sha256-arm64 }}"
end
on_intel do
url "https://github.com/git-mastery/cli/releases/download/${REF_NAME}/gitmastery-amd64"
sha256 "${{ needs.macos-build.outputs.sha256-amd64 }}"
end
def install
if Hardware::CPU.arm?
chmod 0755, "gitmastery-arm64"
bin.install "gitmastery-arm64" => "gitmastery"
else
chmod 0755, "gitmastery-amd64"
bin.install "gitmastery-amd64" => "gitmastery"
end
end
test do
system "#{bin}/gitmastery", "--help"
end
end
EOF
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/git-mastery/homebrew-gitmastery.git
git remote -v
git add gitmastery.rb
git commit -m "Update to ${REF_NAME}"
git push origin main
macos-test:
strategy:
matrix:
os: [macos-15-intel, macos-latest]
runs-on: ${{ matrix.os }}
needs: macos-publish
steps:
- run: |
brew tap git-mastery/gitmastery
brew install gitmastery
file "$(brew --prefix)/bin/gitmastery"
gitmastery --help