Repository navigation
207 lines (199 loc) · 8.51 KB
/
Copy pathrelease.yml
File metadata and controls
207 lines (199 loc) · 8.51 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
name: Release
# Fully automated release, triggered by a version bump on main:
# 1. bump __version__ in mac_storage_dashboard/__init__.py
# 2. merge/push to main
# 3. this workflow tags v<version>, builds the app, creates the GitHub
# release, publishes to PyPI and updates the Homebrew tap
# Docs pushes are no-ops (the tag check below skips everything).
# See RELEASING.md for the one-time setup (PyPI + tap token).
on:
push:
branches: [main]
workflow_dispatch: {} # manual run: retries/repairs, always proceeds
permissions:
contents: write
concurrency:
group: release-main
cancel-in-progress: false
jobs:
version:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
version: ${{ steps.read.outputs.version }}
release: ${{ steps.read.outputs.release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read the version and decide whether to release
id: read
run: |
VERSION="$(grep -oE '__version__ = "[^"]+"' mac_storage_dashboard/__init__.py \
| head -1 | sed -E 's/.*"([^"]+)"/\1/')"
if [ -z "$VERSION" ]; then
echo "::error::Could not read __version__ from mac_storage_dashboard/__init__.py"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Manual run — proceeding with v$VERSION"
echo "release=true" >> "$GITHUB_OUTPUT"
elif git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then
echo "Tag v$VERSION already exists — nothing to release (docs push?)"
echo "release=false" >> "$GITHUB_OUTPUT"
else
echo "New version v$VERSION — releasing"
echo "release=true" >> "$GITHUB_OUTPUT"
fi
app-release:
needs: version
if: needs.version.outputs.release == 'true'
runs-on: macos-latest
outputs:
sha256: ${{ steps.zip.outputs.sha256 }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Regression test (cleanup engine)
run: python3 tests/cleanup_test.py
- name: Build the app
run: python3 -m mac_storage_dashboard app --out dist
- name: Validate the app bundle (headless-safe)
# NOTE: deliberately does NOT launch the applet. CI runners have no
# interactive desktop session, so AppleScript applets can fail to
# start for reasons unrelated to the build and block every release.
# Real launch testing happens locally (open the app / release.command).
run: |
APP="dist/Mac Storage Dashboard.app"
for f in Contents/MacOS/applet \
Contents/Info.plist \
Contents/Resources/launch.sh \
Contents/Resources/server.py \
Contents/Resources/scanner.py \
Contents/Resources/index.html \
Contents/Resources/favicon.svg; do
if [ ! -f "$APP/$f" ]; then
echo "::error::the built app is missing $f"
exit 1
fi
done
test -x "$APP/Contents/MacOS/applet" \
|| { echo "::error::the applet is not executable"; exit 1; }
bash -n "$APP/Contents/Resources/launch.sh" \
|| { echo "::error::launch.sh has a syntax error"; exit 1; }
grep -q 'DASHBOARD_DATA_DIR' "$APP/Contents/Resources/launch.sh" \
|| { echo "::error::launch.sh does not pass DASHBOARD_DATA_DIR to the server"; exit 1; }
python3 - "$APP/Contents/Resources/server.py" \
"$APP/Contents/Resources/scanner.py" <<'PYEOF'
import pathlib, sys
for f in sys.argv[1:]:
compile(pathlib.Path(f).read_text(encoding="utf-8"), f, "exec")
PYEOF
V="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"
if [ "$V" != "${{ needs.version.outputs.version }}" ]; then
echo "::error::app version '$V' != __version__ '${{ needs.version.outputs.version }}'"
exit 1
fi
if [ ! -f "$APP/Contents/Resources/AppIcon.icns" ]; then
echo "::warning::AppIcon.icns was not built — the app will use the default icon."
fi
echo "Bundle validated (v$V)"
- name: Zip the app and hash it
id: zip
run: |
ditto -c -k --keepParent "dist/Mac Storage Dashboard.app" "dist/Mac-Storage-Dashboard.zip"
SHA="$(shasum -a 256 "dist/Mac-Storage-Dashboard.zip" | awk '{print $1}')"
echo "sha256=$SHA" >> "$GITHUB_OUTPUT"
echo "zip sha256: $SHA"
- name: Create or update the GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
V="v${{ needs.version.outputs.version }}"
gh release view "$V" >/dev/null 2>&1 \
|| gh release create "$V" --title "$V" --target "$GITHUB_SHA" --generate-notes
gh release upload "$V" "dist/Mac-Storage-Dashboard.zip" --clobber
pypi:
needs: [version, app-release]
if: needs.version.outputs.release == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # PyPI Trusted Publishing (no API token needed)
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build sdist + wheel
run: |
python3 -m pip install --quiet --upgrade build
python3 -m build
- name: Check whether this version is already on PyPI
id: check
run: |
V="${{ needs.version.outputs.version }}"
if curl -sf "https://pypi.org/pypi/mac-storage-dashboard/$V/json" >/dev/null; then
echo "v$V is already on PyPI — skipping the upload."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
# Uses PyPI Trusted Publishing (one-time setup on pypi.org — see
# RELEASING.md). Prefer an API token instead? Set the PYPI_API_TOKEN
# secret and add: with: { password: "${{ secrets.PYPI_API_TOKEN }}" }
- uses: pypa/gh-action-pypi-publish@release/v1
if: steps.check.outputs.exists == 'false'
homebrew:
needs: [version, app-release]
if: needs.version.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update the Homebrew tap
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
if [ -z "$TAP_TOKEN" ]; then
echo "::warning::HOMEBREW_TAP_TOKEN is not set — skipping the tap update (see RELEASING.md)."
exit 0
fi
V="${{ needs.version.outputs.version }}"
SHA="${{ needs.app-release.outputs.sha256 }}"
OWNER="${GITHUB_REPOSITORY_OWNER}"
TAP="homebrew-tap"
URL="https://x-access-token:${TAP_TOKEN}@github.com/${OWNER}/${TAP}.git"
if ! git clone --quiet --depth 1 "$URL" tap 2>/dev/null; then
echo "Tap ${OWNER}/${TAP} not found — creating it"
GH_TOKEN="$TAP_TOKEN" gh repo create "${OWNER}/${TAP}" --public \
--description "Homebrew tap for Mac Storage Dashboard"
for attempt in 1 2 3; do
# brand-new repo — retry in case it isn't queryable yet
if git clone --quiet --depth 1 "$URL" tap 2>/dev/null; then break; fi
echo "clone attempt $attempt failed — retrying"
sleep 3
done
fi
if [ ! -d tap/.git ]; then
echo "::error::could not clone ${OWNER}/${TAP}"
exit 1
fi
mkdir -p tap/Casks
sed -e "s/REPLACE_WITH_VERSION/$V/" \
-e "s/REPLACE_WITH_SHA256_FROM_release.command/$SHA/" \
packaging/homebrew/mac-storage-dashboard.rb > tap/Casks/mac-storage-dashboard.rb
cd tap
git checkout -B main
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Casks/mac-storage-dashboard.rb
if git diff --cached --quiet; then
echo "Cask is already up to date."
else
git commit -m "mac-storage-dashboard $V"
git push origin main
echo "Tap updated with mac-storage-dashboard $V"
fi