Repository navigation
170 lines (153 loc) · 5.89 KB
/
Copy pathrelease.yml
File metadata and controls
170 lines (153 loc) · 5.89 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
name: Release
on:
push:
tags:
# Stable tags only. Prerelease tags (vX.Y.Z-beta.N) contain a '-' and
# are handled by release-beta.yml; every job below is additionally
# guarded with !contains(github.ref_name, '-') because this 'v*'
# pattern matches them too.
- "v*"
permissions:
contents: write
jobs:
build-platforms:
if: ${{ !contains(github.ref_name, '-') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: darwin
platform: macOS
goarch: amd64
- goos: darwin
platform: macOS
goarch: arm64
- goos: linux
platform: Linux
goarch: amd64
- goos: linux
platform: Linux
goarch: arm64
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Build ${{ matrix.platform }} ${{ matrix.goarch }} archive
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
PLATFORM: ${{ matrix.platform }}
VERSION: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
run: |
set -euo pipefail
build_date="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
target="myworktree_${VERSION}_${PLATFORM}_${GOARCH}"
dist_dir="dist/${target}"
mkdir -p "${dist_dir}"
# Only strip debug symbols (-s), keep symbol table (-w removed)
# to preserve macOS code signing compatibility
ldflags="-s -X myworktree/internal/version.Version=${VERSION} -X myworktree/internal/version.Commit=${COMMIT} -X myworktree/internal/version.BuildDate=${build_date}"
CGO_ENABLED=0 GOOS="${GOOS}" GOARCH="${GOARCH}" go build -trimpath -ldflags "${ldflags}" -o "${dist_dir}/myworktree" ./cmd/myworktree
CGO_ENABLED=0 GOOS="${GOOS}" GOARCH="${GOARCH}" go build -trimpath -ldflags "${ldflags}" -o "${dist_dir}/mw" ./cmd/mw
cp README.md README.zh-CN.md LICENSE CHANGELOG.md "${dist_dir}/"
tar -C dist -czf "dist/${target}.tar.gz" "${target}"
- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.platform }}-${{ matrix.goarch }}
path: dist/*.tar.gz
if-no-files-found: error
codesign-notarize:
if: ${{ vars.APPLE_ENABLE_CODESIGN == 'true' && !contains(github.ref_name, '-') }}
runs-on: macos-latest
needs: build-platforms
strategy:
fail-fast: false
matrix:
goarch:
- amd64
- arm64
steps:
- name: Download archive
uses: actions/download-artifact@v4
with:
name: release-macOS-${{ matrix.goarch }}
path: dist
- name: Extract and codesign
env:
APPLE_DEVELOPER_ID_CERT_BASE64: ${{ secrets.APPLE_DEVELOPER_ID_CERT_BASE64 }}
APPLE_DEVELOPER_ID_CERT_PASSWORD: ${{ secrets.APPLE_DEVELOPER_ID_CERT_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
run: |
set -euo pipefail
archive=$(ls dist/*.tar.gz)
basename=$(basename "${archive}" .tar.gz)
mkdir -p dist/extracted
tar xzf "${archive}" -C dist/extracted
# Import Apple Developer signing certificate
KEYCHAIN="build.keychain"
security create-keychain -p "" "${KEYCHAIN}"
security default-keychain -s "${KEYCHAIN}"
security unlock-keychain -p "" "${KEYCHAIN}"
security set-keychain-settings -lut 21600 "${KEYCHAIN}"
echo "${APPLE_DEVELOPER_ID_CERT_BASE64}" | base64 -d > cert.p12
security import cert.p12 -k "${KEYCHAIN}" -P "${APPLE_DEVELOPER_ID_CERT_PASSWORD}" -T /usr/bin/codesign -T /usr/bin/pkgbuild
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "" "${KEYCHAIN}"
for binary in myworktree mw; do
# Sign with hardened runtime (required for notarization)
codesign --force --options runtime --timestamp --sign "${APPLE_TEAM_ID}" \
"dist/extracted/${basename}/${binary}"
done
# Notarize each binary
for binary in myworktree mw; do
zip_path="dist/${binary}.zip"
ditto -c -k --keepParent "dist/extracted/${basename}/${binary}" "${zip_path}"
xcrun notarytool submit "${zip_path}" \
--apple-id "${APPLE_ID}" \
--team-id "${APPLE_TEAM_ID}" \
--password "${APPLE_APP_SPECIFIC_PASSWORD}" \
--wait
xcrun stapler staple "dist/extracted/${basename}/${binary}"
done
# Re-pack the signed archive
tar czf "${archive}" -C dist/extracted "${basename}"
# Clean up keychain
security delete-keychain "${KEYCHAIN}"
- name: Upload signed archive
uses: actions/upload-artifact@v4
with:
name: release-macOS-${{ matrix.goarch }}
path: dist/*.tar.gz
if-no-files-found: error
overwrite: true
publish:
runs-on: ubuntu-latest
needs: [build-platforms, codesign-notarize]
if: ${{ !failure() && !contains(github.ref_name, '-') }}
steps:
- name: Download archives
uses: actions/download-artifact@v4
with:
path: dist
pattern: release-*
merge-multiple: true
- name: Generate checksums
run: |
set -euo pipefail
cd dist
shasum -a 256 ./*.tar.gz > checksums.txt
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
dist/*.tar.gz
dist/checksums.txt