forked from 1lck/Lithe-IDEA
-
Notifications
You must be signed in to change notification settings - Fork 0
280 lines (249 loc) · 8.85 KB
/
Copy pathrelease-macos.yml
File metadata and controls
280 lines (249 loc) · 8.85 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
name: Release macOS
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Semantic version to release, for example 0.1.0"
required: true
type: string
permissions:
contents: read
concurrency:
group: release-macos-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
name: Resolve release version
if: github.actor == github.repository_owner
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
build_number: ${{ steps.version.outputs.build_number }}
steps:
- name: Resolve release version
id: version
env:
EVENT_NAME: ${{ github.event_name }}
MANUAL_VERSION: ${{ inputs.version }}
shell: bash
run: |
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
version="$MANUAL_VERSION"
else
version="${GITHUB_REF_NAME#v}"
fi
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release version must use the form MAJOR.MINOR.PATCH: $version"
exit 1
fi
{
echo "version=$version"
echo "tag=v$version"
echo "build_number=$GITHUB_RUN_NUMBER"
} >> "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.architecture }} release
needs: prepare
runs-on: macos-14
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
architecture:
- arm64
- x86_64
steps:
- name: Check out source
uses: actions/checkout@v7
- name: Set up Swift
uses: swift-actions/setup-swift@v2
with:
swift-version: "6.2"
- name: Set up Rust target
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.architecture == 'arm64' && 'aarch64-apple-darwin' || 'x86_64-apple-darwin' }}
- name: Restore SwiftPM dependencies
uses: actions/cache@v6
with:
path: |
.build/checkouts
.build/repositories
~/.cache/org.swift.swiftpm
key: swiftpm-${{ runner.os }}-6.2-${{ hashFiles('Package.resolved') }}
- name: Restore Cargo dependencies
uses: actions/cache@v6
with:
path: |
~/.cargo/git
~/.cargo/registry
key: cargo-dependencies-${{ runner.os }}-${{ hashFiles('rust/Cargo.lock') }}
- name: Build and package the App
env:
LITHE_ARCH: ${{ matrix.architecture }}
LITHE_VERSION: ${{ needs.prepare.outputs.version }}
LITHE_BUILD_NUMBER: ${{ needs.prepare.outputs.build_number }}
run: |
./scripts/package-app.sh
./scripts/create-dmg.sh
dmg_name="Lithe-${LITHE_VERSION}-${LITHE_ARCH}.dmg"
(cd dist && shasum -a 256 "$dmg_name" > "$dmg_name.sha256")
- name: Verify the bundle and disk image
env:
LITHE_ARCH: ${{ matrix.architecture }}
LITHE_VERSION: ${{ needs.prepare.outputs.version }}
run: |
app_path="dist/Lithe-${LITHE_ARCH}.app"
dmg_path="dist/Lithe-${LITHE_VERSION}-${LITHE_ARCH}.dmg"
codesign --verify --deep --strict "$app_path"
/usr/libexec/PlistBuddy \
-c "Print :CFBundleShortVersionString" \
"$app_path/Contents/Info.plist"
/usr/libexec/PlistBuddy \
-c "Print :CFBundleVersion" \
"$app_path/Contents/Info.plist"
lipo "$app_path/Contents/MacOS/Lithe" -verify_arch "$LITHE_ARCH"
hdiutil imageinfo "$dmg_path" > /dev/null
test -s "$dmg_path"
(cd dist && shasum -a 256 -c "Lithe-${LITHE_VERSION}-${LITHE_ARCH}.dmg.sha256")
- name: Upload release assets
uses: actions/upload-artifact@v7
with:
name: macos-release-${{ matrix.architecture }}
path: |
dist/Lithe-${{ needs.prepare.outputs.version }}-${{ matrix.architecture }}.dmg
dist/Lithe-${{ needs.prepare.outputs.version }}-${{ matrix.architecture }}.dmg.sha256
if-no-files-found: error
retention-days: 7
publish:
name: Publish macOS release
needs:
- prepare
- build
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ needs.prepare.outputs.version }}
tag: ${{ needs.prepare.outputs.tag }}
steps:
- name: Check out source
uses: actions/checkout@v7
- name: Download release assets
uses: actions/download-artifact@v8
with:
pattern: macos-release-*
path: dist
merge-multiple: true
- name: Verify downloaded assets
env:
LITHE_VERSION: ${{ needs.prepare.outputs.version }}
shell: bash
run: |
for architecture in arm64 x86_64; do
(cd dist && shasum -a 256 -c "Lithe-${LITHE_VERSION}-${architecture}.dmg.sha256")
done
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.prepare.outputs.tag }}
LITHE_VERSION: ${{ needs.prepare.outputs.version }}
shell: bash
run: |
notes_file="docs/releases/v${LITHE_VERSION}.md"
release_args=(
"$RELEASE_TAG"
"dist/Lithe-${LITHE_VERSION}-arm64.dmg"
"dist/Lithe-${LITHE_VERSION}-arm64.dmg.sha256"
"dist/Lithe-${LITHE_VERSION}-x86_64.dmg"
"dist/Lithe-${LITHE_VERSION}-x86_64.dmg.sha256"
--repo "$GITHUB_REPOSITORY"
--target "$GITHUB_SHA"
--title "Lithe $RELEASE_TAG"
)
if [[ -f "$notes_file" ]]; then
release_args+=(--notes-file "$notes_file")
else
release_args+=(--generate-notes)
fi
gh release create "${release_args[@]}"
update-cask:
name: Update Homebrew Cask
needs: publish
runs-on: macos-14
permissions:
contents: write
pull-requests: write
steps:
- name: Check out the default branch
uses: actions/checkout@v7
with:
ref: main
- name: Download release checksums
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.publish.outputs.tag }}
LITHE_VERSION: ${{ needs.publish.outputs.version }}
run: |
checksum_dir="$RUNNER_TEMP/lithe-release"
mkdir -p "$checksum_dir"
gh release download "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--pattern "*.dmg.sha256" \
--dir "$checksum_dir"
echo "CHECKSUM_DIR=$checksum_dir" >> "$GITHUB_ENV"
- name: Update the Cask metadata
env:
LITHE_VERSION: ${{ needs.publish.outputs.version }}
run: |
arm_sha=$(awk 'NR == 1 { print $1 }' "$CHECKSUM_DIR/Lithe-${LITHE_VERSION}-arm64.dmg.sha256")
intel_sha=$(awk 'NR == 1 { print $1 }' "$CHECKSUM_DIR/Lithe-${LITHE_VERSION}-x86_64.dmg.sha256")
LITHE_ARM64_SHA256="$arm_sha" \
LITHE_X86_64_SHA256="$intel_sha" \
ruby scripts/update-homebrew-cask.rb
- name: Validate the Cask
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }}
run: |
brew tap 1lck/lithe https://github.com/1lck/Lithe-IDEA.git
tap_path="$(brew --repository)/Library/Taps/1lck/homebrew-lithe"
cp "$GITHUB_WORKSPACE/Casks/lithe.rb" "$tap_path/Casks/lithe.rb"
brew style --cask 1lck/lithe/lithe
brew audit --cask --online 1lck/lithe/lithe
- name: Create or update the Cask pull request
env:
GH_TOKEN: ${{ github.token }}
LITHE_VERSION: ${{ needs.publish.outputs.version }}
run: |
branch="automation/homebrew-cask-v${LITHE_VERSION}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$branch"
git add Casks/lithe.rb
if git diff --cached --quiet; then
exit 0
fi
git commit -m "lithe ${LITHE_VERSION}"
git fetch origin "$branch" || true
git push --force-with-lease origin "HEAD:refs/heads/$branch"
existing_pr=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head "$branch" \
--state open \
--json url \
--jq '.[0].url // empty')
if [[ -n "$existing_pr" ]]; then
echo "Updated existing pull request: $existing_pr"
exit 0
fi
gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head "$branch" \
--title "lithe ${LITHE_VERSION}" \
--body "Automated Homebrew Cask metadata update for Lithe ${LITHE_VERSION}."