-
Notifications
You must be signed in to change notification settings - Fork 1
208 lines (177 loc) · 6.67 KB
/
Copy pathbuild-release.yml
File metadata and controls
208 lines (177 loc) · 6.67 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
name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
build-and-release:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
include:
- os: ubuntu-latest
arch: amd64
platform: linux
artifact_name: todo-app
- os: ubuntu-latest
arch: arm64
platform: linux
artifact_name: todo-app
- os: macos-latest
arch: amd64
platform: macos
artifact_name: todo-app
- os: macos-latest
arch: arm64
platform: macos
artifact_name: todo-app
- os: windows-latest
arch: amd64
platform: windows
artifact_name: todo-app.exe
- os: windows-latest
arch: arm64
platform: windows
artifact_name: todo-app.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install ARM64 Cross-Compiler (Linux)
if: matrix.platform == 'linux' && matrix.arch == 'arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.25.x'
- name: Configure CMake
run: |
if [ "${{ matrix.platform }}" = "linux" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
elif [ "${{ matrix.platform }}" = "macos" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64
elif [ "${{ matrix.platform }}" = "windows" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release -A ARM64
else
cmake -B build -DCMAKE_BUILD_TYPE=Release
fi
shell: bash
- name: Build
run: cmake --build build --config Release
- name: Prepare Artifacts and Checksum
shell: bash
run: |
mkdir -p out
VERSION=${GITHUB_REF_NAME}
ASSET_NAME="todo-app-${VERSION}-${{ matrix.platform }}-${{ matrix.arch }}"
if [ "${{ matrix.platform }}" = "windows" ]; then
FINAL_NAME="${ASSET_NAME}.exe"
if [ -f "build/Release/${{ matrix.artifact_name }}" ]; then
cp "build/Release/${{ matrix.artifact_name }}" "out/${FINAL_NAME}"
else
cp "build/${{ matrix.artifact_name }}" "out/${FINAL_NAME}"
fi
else
FINAL_NAME="${ASSET_NAME}"
cp build/${{ matrix.artifact_name }} out/${FINAL_NAME}
chmod +x out/${FINAL_NAME}
fi
# Generate individual checksum
cd out
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${FINAL_NAME}" > "${FINAL_NAME}.sha256"
else
shasum -a 256 "${FINAL_NAME}" > "${FINAL_NAME}.sha256"
fi
echo "artifact_path=out/${FINAL_NAME}" >> $GITHUB_ENV
echo "checksum_path=out/${FINAL_NAME}.sha256" >> $GITHUB_ENV
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-${{ matrix.arch }}
path: |
${{ env.artifact_path }}
${{ env.checksum_path }}
release:
needs: build-and-release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: all-artifacts
merge-multiple: true
- name: Combine Checksums
working-directory: all-artifacts
run: |
# Combine all .sha256 files into one checksums.txt
cat *.sha256 > checksums.txt
# Remove the individual .sha256 files to keep the release clean
rm *.sha256
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: "CLI Todo App ${{ github.ref_name }}"
draft: false
prerelease: false
generate_release_notes: true
files: |
all-artifacts/*
update-homebrew:
needs: release
runs-on: ubuntu-latest
steps:
- name: Wait for Release Assets
run: sleep 30
- name: Update Homebrew Formula
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
VERSION=${GITHUB_REF_NAME#v}
REPO_NAME="cli-todo-app"
TAP_REPO="GourangaDasSamrat/homebrew-tap"
# Download prebuilt macOS binaries to calculate SHA256
wget https://github.com/GourangaDasSamrat/${REPO_NAME}/releases/download/${GITHUB_REF_NAME}/todo-app-${GITHUB_REF_NAME}-macos-arm64
wget https://github.com/GourangaDasSamrat/${REPO_NAME}/releases/download/${GITHUB_REF_NAME}/todo-app-${GITHUB_REF_NAME}-macos-amd64
ARM64_SHA=$(sha256sum todo-app-${GITHUB_REF_NAME}-macos-arm64 | awk '{print $1}')
AMD64_SHA=$(sha256sum todo-app-${GITHUB_REF_NAME}-macos-amd64 | awk '{print $1}')
echo "ARM64 SHA: ${ARM64_SHA}"
echo "AMD64 SHA: ${AMD64_SHA}"
# Clone tap repository
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${TAP_REPO}.git tap
cd tap
# Update formula with prebuilt binaries
cat > Formula/cli-todo-app.rb <<EOF
class CliTodoApp < Formula
desc "Feature-rich, cross-platform CLI Todo app written in modern C++"
homepage "https://github.com/GourangaDasSamrat/cli-todo-app"
version "${VERSION}"
license "MIT"
if Hardware::CPU.arm?
url "https://github.com/GourangaDasSamrat/cli-todo-app/releases/download/v${VERSION}/todo-app-v${VERSION}-macos-arm64"
sha256 "${ARM64_SHA}"
else
url "https://github.com/GourangaDasSamrat/cli-todo-app/releases/download/v${VERSION}/todo-app-v${VERSION}-macos-amd64"
sha256 "${AMD64_SHA}"
end
def install
bin.install "todo-app-v${VERSION}-macos-arm64" => "todo-app" if Hardware::CPU.arm?
bin.install "todo-app-v${VERSION}-macos-amd64" => "todo-app" if Hardware::CPU.intel?
end
test do
system "#{bin}/todo-app", "--version"
end
end
EOF
# Commit and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/cli-todo-app.rb
git commit -m "Update cli-todo-app to v${VERSION}"
git push