@@ -14,39 +14,77 @@ jobs:
1414 strategy :
1515 fail-fast : false
1616 matrix :
17- os : [ubuntu-latest, macos-latest]
1817 include :
1918 - os : ubuntu-latest
20- artifact_suffix : linux
19+ artifact_suffix : linux-x86_64
20+ archive_name : g-systemctl-linux-x86_64.tar.gz
2121 - os : macos-latest
2222 artifact_suffix : macos
23+ archive_name : g-systemctl-macos.tar.gz
2324
2425 steps :
2526 - name : Checkout code
2627 uses : actions/checkout@v4
2728
2829 - name : Install dependencies (Linux)
29- if : matrix .os == 'ubuntu-latest '
30+ if : runner .os == 'Linux '
3031 run : |
3132 sudo apt-get update
3233 sudo apt-get install -y cmake build-essential
3334
3435 - name : Install dependencies (macOS)
35- if : matrix .os == 'macos-latest '
36+ if : runner .os == 'macOS '
3637 run : brew install cmake
3738
38- - name : Configure and Build
39+ - name : Get version
40+ id : version
41+ shell : bash
42+ run : |
43+ if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
44+ echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
45+ else
46+ echo "VERSION=0.0.0-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
47+ fi
48+
49+ - name : Configure and build
50+ run : |
51+ cmake -S . -B build \
52+ -DCMAKE_BUILD_TYPE=Release \
53+ -DG_SYSTEMCTL_VERSION=${{ steps.version.outputs.VERSION }}
54+ cmake --build build --config Release --parallel
55+
56+ - name : Package binary archive
57+ shell : bash
58+ run : |
59+ mkdir -p dist/g-systemctl-${{ steps.version.outputs.VERSION }}
60+ cp build/g-systemctl dist/g-systemctl-${{ steps.version.outputs.VERSION }}/
61+ chmod +x dist/g-systemctl-${{ steps.version.outputs.VERSION }}/g-systemctl
62+ tar -czf dist/${{ matrix.archive_name }} -C dist g-systemctl-${{ steps.version.outputs.VERSION }}
63+
64+ - name : Build Debian package
65+ if : runner.os == 'Linux'
66+ shell : bash
67+ run : |
68+ cmake --build build --target package --config Release
69+ deb_package="$(find build -maxdepth 1 -name '*.deb' -print -quit)"
70+ cp "$deb_package" dist/g-systemctl-linux-amd64.deb
71+
72+ - name : Generate checksums
73+ shell : bash
3974 run : |
40- mkdir -p build
41- cd build
42- cmake -DCMAKE_BUILD_TYPE=Release ..
43- make -j$(nproc)
75+ cd dist
76+ for file in *; do
77+ if [[ -f "$file" ]]; then
78+ shasum -a 256 "$file"
79+ fi
80+ done > SHA256SUMS-${{ matrix.artifact_suffix }}.txt
4481
4582 - name : Upload artifact
4683 uses : actions/upload-artifact@v4
4784 with :
4885 name : g-systemctl-${{ matrix.artifact_suffix }}
49- path : build/g-systemctl
86+ path : dist/*
87+ if-no-files-found : error
5088
5189 create-release :
5290 needs : build
@@ -59,34 +97,45 @@ jobs:
5997
6098 - name : Get version
6199 id : version
62- run : echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
100+ run : |
101+ echo "TAG=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
102+ echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
63103
64- - name : Download Linux artifact
104+ - name : Download artifacts
65105 uses : actions/download-artifact@v4
66106 with :
67- name : g-systemctl-linux
68- path : artifacts/linux
107+ path : artifacts
108+ merge-multiple : true
69109
70- - name : Download macOS artifact
71- uses : actions/download-artifact@v4
72- with :
73- name : g-systemctl-macos
74- path : artifacts/macos
110+ - name : Generate Homebrew formula
111+ shell : bash
112+ run : |
113+ source_url="https://github.com/shakg/g-systemctl/archive/refs/tags/${{ steps.version.outputs.TAG }}.tar.gz"
114+ source_sha="$(curl -L "$source_url" | shasum -a 256 | awk '{print $1}')"
115+ sed \
116+ -e "s|refs/tags/v1.0.0.tar.gz|refs/tags/${{ steps.version.outputs.TAG }}.tar.gz|" \
117+ -e "s|REPLACE_WITH_RELEASE_TARBALL_SHA256|${source_sha}|" \
118+ Formula/g-systemctl.rb > artifacts/g-systemctl.rb
75119
76- - name : Make artifacts executable
120+ - name : Generate combined checksums
77121 run : |
78- chmod +x artifacts/linux/g-systemctl
79- chmod +x artifacts/ macos/ g-systemctl
122+ cd artifacts
123+ shasum -a 256 g-systemctl-linux-x86_64.tar.gz g-systemctl- macos.tar.gz g-systemctl-linux-amd64.deb g-systemctl.rb > SHA256SUMS.txt
80124
81125 - name : Create Release
82126 uses : softprops/action-gh-release@v2
83127 with :
84- tag_name : ${{ steps.version.outputs.VERSION }}
85- name : Release ${{ steps.version.outputs.VERSION }}
128+ tag_name : ${{ steps.version.outputs.TAG }}
129+ name : Release ${{ steps.version.outputs.TAG }}
86130 draft : false
87131 prerelease : false
88132 files : |
89- artifacts/linux/g-systemctl
90- artifacts/macos/g-systemctl
133+ artifacts/g-systemctl-linux-x86_64.tar.gz
134+ artifacts/g-systemctl-macos.tar.gz
135+ artifacts/g-systemctl-linux-amd64.deb
136+ artifacts/g-systemctl.rb
137+ artifacts/SHA256SUMS.txt
138+ artifacts/SHA256SUMS-linux-x86_64.txt
139+ artifacts/SHA256SUMS-macos.txt
91140 env :
92141 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments