Repository navigation
234 lines (215 loc) · 7.56 KB
/
Copy pathrelease.yml
File metadata and controls
234 lines (215 loc) · 7.56 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
name: Release
on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
jobs:
get-tag:
name: Find draft release
if: (github.event_name == 'pull_request' && github.head_ref == 'knope/release' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04
permissions:
contents: write
outputs:
tag: ${{ steps.find.outputs.tag }}
version: ${{ steps.find.outputs.version }}
commit: ${{ steps.find.outputs.commit }}
steps:
- name: Find Knope draft release
id: find
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
for attempt in $(seq 1 30); do
tag="$(gh release list --repo "$GITHUB_REPOSITORY" --limit 20 \
--json isDraft,tagName \
--jq '[.[] | select(.isDraft and (.tagName | test("^v[0-9]+\\.[0-9]+\\.[0-9]+$")))][0].tagName // ""')"
if [[ -n "$tag" ]]; then
commit="$(gh release view "$tag" --repo "$GITHUB_REPOSITORY" \
--json targetCommitish --jq '.targetCommitish')"
if [[ -z "$commit" ]]; then
echo "Draft release $tag has no target commit." >&2
exit 1
fi
{
echo "tag=$tag"
echo "version=${tag#v}"
echo "commit=$commit"
} >> "$GITHUB_OUTPUT"
echo "Found draft release $tag at $commit."
exit 0
fi
echo "No draft release yet (attempt $attempt/30); waiting 10s..."
sleep 10
done
echo "No draft release found. Install Knope Bot and merge its release PR first." >&2
exit 1
build:
name: Build (${{ matrix.target }})
needs: get-tag
if: needs.get-tag.outputs.tag != ''
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
artifact: linux-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact: macos-arm64
- os: macos-15-intel
target: x86_64-apple-darwin
artifact: macos-x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: windows-x86_64
runs-on: ${{ matrix.os }}
env:
VERSION: ${{ needs.get-tag.outputs.version }}
MACOSX_DEPLOYMENT_TARGET: "15.0"
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.get-tag.outputs.commit }}
- name: Install Linux dependencies
if: runner.os == 'Linux'
uses: ./.github/actions/linux-deps
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
- name: Build
shell: bash
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package (macOS app)
if: runner.os == 'macOS'
shell: bash
run: |
set -euo pipefail
app="$RUNNER_TEMP/Android CLI GUI.app"
packaging/macos/make-app.sh \
"target/${{ matrix.target }}/release/android-cli-gui" \
"$VERSION" "$app"
mkdir -p dist
ditto -c -k --sequesterRsrc --keepParent "$app" \
"dist/android-cli-gui-v${VERSION}-${{ matrix.artifact }}.zip"
packaging/macos/make-dmg.sh "$app" "$VERSION" \
"dist/android-cli-gui-v${VERSION}-${{ matrix.artifact }}.dmg"
- name: Package (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
asset="android-cli-gui-v${VERSION}-${{ matrix.target }}.tar.gz"
mkdir -p dist
tar -C "target/${{ matrix.target }}/release" -czf "dist/${asset}" android-cli-gui
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$asset = "android-cli-gui-v$($env:VERSION)-${{ matrix.target }}.zip"
New-Item -ItemType Directory -Force -Path dist | Out-Null
Compress-Archive -Path "target/${{ matrix.target }}/release/android-cli-gui.exe" -DestinationPath "dist/$asset"
- uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact }}
path: dist/*
if-no-files-found: error
publish:
name: Upload assets and publish
needs: [get-tag, build]
if: needs.get-tag.outputs.tag != ''
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Upload assets and publish
shell: bash
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
TAG: ${{ needs.get-tag.outputs.tag }}
run: |
set -euo pipefail
cd dist
sha256sum -- * > SHA256SUMS.txt
cat SHA256SUMS.txt
gh release upload "$TAG" --clobber ./*
gh release edit "$TAG" --draft=false --latest
homebrew:
name: Update Homebrew tap
needs: [publish, get-tag]
if: needs.get-tag.outputs.tag != ''
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.repository.default_branch }}
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Render cask
shell: bash
env:
VERSION: ${{ needs.get-tag.outputs.version }}
run: |
set -euo pipefail
sha() {
sha256sum "dist/$1" | cut -d' ' -f1
}
sed \
-e "s/__VERSION__/${VERSION}/g" \
-e "s/__SHA256_MACOS_ARM64__/$(sha "android-cli-gui-v${VERSION}-macos-arm64.dmg")/g" \
-e "s/__SHA256_MACOS_X86_64__/$(sha "android-cli-gui-v${VERSION}-macos-x86_64.dmg")/g" \
packaging/homebrew/android-cli-gui.cask.rb.tmpl \
> dist/android-cli-gui.rb
ruby -c dist/android-cli-gui.rb
- name: Push cask to tap
shell: bash
env:
TAG: ${{ needs.get-tag.outputs.tag }}
HOMEBREW_TAP_DEPLOY_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
run: |
set -euo pipefail
install -d -m 700 "$HOME/.ssh"
key="$HOME/.ssh/homebrew_tap"
printf '%s\n' "$HOMEBREW_TAP_DEPLOY_KEY" > "$key"
chmod 600 "$key"
ssh-keyscan github.com >> "$HOME/.ssh/known_hosts" 2>/dev/null
export GIT_SSH_COMMAND="ssh -i $key -o IdentitiesOnly=yes"
rm -rf tap
git clone --depth 1 git@github.com:RayhanHamada/homebrew-tap.git tap
mkdir -p tap/Casks
cp dist/android-cli-gui.rb tap/Casks/android-cli-gui.rb
if [[ -f tap/Formula/android-cli-gui.rb ]]; then
git -C tap rm Formula/android-cli-gui.rb
fi
git -C tap config user.name "github-actions[bot]"
git -C tap config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C tap add Casks/android-cli-gui.rb
if git -C tap diff --cached --quiet; then
echo "Cask is already up to date."
else
git -C tap commit -m "android-cli-gui ${TAG} (cask)"
git -C tap push origin HEAD:main
fi