From 680735ac5a75fa109d97212e80bc6669939fdbb8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 21:04:10 +0000 Subject: [PATCH] Add CI, macOS app bundle and release workflow ci.yml: gofmt, go vet and go test -race on Linux and macOS, a Windows cross-build, and the .app bundle as a build artifact. scripts/build-app.sh: universal (arm64 + amd64) xWinAmp.app with an icon drawn by tools/mkicon, Info.plist and an ad-hoc signature, zipped with ditto. release.yml: on v* tags, builds the macOS app, a Linux tarball and a Windows exe and attaches them to a GitHub Release. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01WzyyXFv9vmrtp3o7PfAFBV --- .github/workflows/ci.yml | 50 +++++++++++++++ .github/workflows/release.yml | 66 ++++++++++++++++++++ README.md | 22 ++++++- scripts/build-app.sh | 73 ++++++++++++++++++++++ tools/mkicon/main.go | 111 ++++++++++++++++++++++++++++++++++ 5 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100755 scripts/build-app.sh create mode 100644 tools/mkicon/main.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f19df96 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Install ALSA and X11 headers + run: | + sudo apt-get update + sudo apt-get install -y libasound2-dev libgl1-mesa-dev libxrandr-dev \ + libxcursor-dev libxinerama-dev libxi-dev libxxf86vm-dev + - name: gofmt + run: | + unformatted=$(gofmt -l .) + if [ -n "$unformatted" ]; then + echo "Run gofmt on:"; echo "$unformatted"; exit 1 + fi + - run: go vet ./... + - run: go test -race ./... + - name: Cross-build for Windows + run: GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build ./... + + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: go vet ./... + - run: go test -race ./... + - name: Build xWinAmp.app + run: scripts/build-app.sh + - uses: actions/upload-artifact@v4 + with: + name: xWinAmp-app + path: dist/xWinAmp-macos.zip + retention-days: 7 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fa62924 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,66 @@ +name: Release + +on: + push: + tags: ["v*"] + +permissions: + contents: read + +jobs: + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Build xWinAmp.app + run: VERSION=${{ github.ref_name }} scripts/build-app.sh + - uses: actions/upload-artifact@v4 + with: + name: macos + path: dist/xWinAmp-macos.zip + + linux-windows: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Install ALSA and X11 headers + run: | + sudo apt-get update + sudo apt-get install -y libasound2-dev libgl1-mesa-dev libxrandr-dev \ + libxcursor-dev libxinerama-dev libxi-dev libxxf86vm-dev + - name: Build + run: | + mkdir -p dist + go build -trimpath -ldflags "-s -w" -o dist/xwinamp ./cmd/xwinamp + tar -czf dist/xwinamp-linux-amd64.tar.gz -C dist xwinamp + # -H=windowsgui: no console window behind the player. + GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \ + go build -trimpath -ldflags "-s -w -H=windowsgui" -o dist/xwinamp.exe ./cmd/xwinamp + (cd dist && zip -q xwinamp-windows-amd64.zip xwinamp.exe) + - uses: actions/upload-artifact@v4 + with: + name: linux-windows + path: | + dist/xwinamp-linux-amd64.tar.gz + dist/xwinamp-windows-amd64.zip + + release: + needs: [macos, linux-windows] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + - uses: softprops/action-gh-release@v2 + with: + files: dist/* + generate_release_notes: true diff --git a/README.md b/README.md index f6079bc..2cb703a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A Winamp-style audio player written in Go. macOS first, Linux and Windows later. -Status: step 3 of 4. Player window with a playlist; CI and macOS app packaging come next. +Status: player window with a playlist, CI and release builds (steps 1-4 of the initial plan). ![xWinAmp main window](docs/screenshot.png) @@ -13,6 +13,8 @@ Status: step 3 of 4. Player window with a playlist; CI and macOS app packaging c - `playlist/` - track list, next/prev, repeat/shuffle, M3U. No UI code. - `cmd/xwinamp/` - the desktop player; saves the playlist and settings between runs. - `cmd/xwinamp-cli/` - terminal player built on `player`. +- `tools/mkicon/` - draws the app icon. +- `scripts/build-app.sh` - builds `dist/xWinAmp.app` on macOS. Supported formats: MP3, WAV, FLAC, OGG Vorbis. @@ -57,6 +59,24 @@ While playing, type a command and press Enter: `p` pause/resume, `s` stop, `sudo apt install libasound2-dev libgl1-mesa-dev libxrandr-dev libxcursor-dev libxinerama-dev libxi-dev libxxf86vm-dev`. File dialogs need `zenity` or `kdialog` installed. +## macOS app + +```sh +scripts/build-app.sh # dist/xWinAmp.app and dist/xWinAmp-macos.zip +VERSION=1.0.0 scripts/build-app.sh +``` + +The app is a universal binary (Apple Silicon and Intel). It is ad-hoc signed, +not signed with a Developer ID, so on first launch open it with right click → +Open. + +## Releases + +Pushing a tag like `v0.1.0` runs `.github/workflows/release.yml`, which builds +the macOS app, a Linux binary and a Windows `.exe` and attaches them to a +GitHub Release. `.github/workflows/ci.yml` checks formatting, vet and tests on +Linux and macOS for every pull request. + ## Tests ```sh diff --git a/scripts/build-app.sh b/scripts/build-app.sh new file mode 100755 index 0000000..77c1c22 --- /dev/null +++ b/scripts/build-app.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# Builds dist/xWinAmp.app (universal arm64 + amd64) and dist/xWinAmp-macos.zip. +# Runs on macOS only: it needs lipo, sips, iconutil and ditto. +# +# VERSION=1.2.3 scripts/build-app.sh +set -euo pipefail + +cd "$(dirname "$0")/.." + +VERSION="${VERSION:-0.0.0-dev}" +VERSION="${VERSION#v}" +APP=dist/xWinAmp.app +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT + +rm -rf "$APP" dist/xWinAmp-macos.zip +mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" + +echo "Building binaries..." +for arch in arm64 amd64; do + GOOS=darwin GOARCH=$arch CGO_ENABLED=1 \ + go build -trimpath -ldflags "-s -w" -o "$WORK/xwinamp-$arch" ./cmd/xwinamp +done +lipo -create -output "$APP/Contents/MacOS/xwinamp" "$WORK/xwinamp-arm64" "$WORK/xwinamp-amd64" + +echo "Building icon..." +go run ./tools/mkicon -size 1024 -o "$WORK/icon.png" +ICONSET="$WORK/xwinamp.iconset" +mkdir "$ICONSET" +for size in 16 32 128 256 512; do + sips -z $size $size "$WORK/icon.png" --out "$ICONSET/icon_${size}x${size}.png" >/dev/null + sips -z $((size * 2)) $((size * 2)) "$WORK/icon.png" --out "$ICONSET/icon_${size}x${size}@2x.png" >/dev/null +done +iconutil -c icns -o "$APP/Contents/Resources/xwinamp.icns" "$ICONSET" + +cat >"$APP/Contents/Info.plist" < + + + + CFBundleName + xWinAmp + CFBundleDisplayName + xWinAmp + CFBundleIdentifier + io.github.rooty.xwinamp + CFBundleExecutable + xwinamp + CFBundleIconFile + xwinamp + CFBundlePackageType + APPL + CFBundleShortVersionString + ${VERSION} + CFBundleVersion + ${VERSION} + LSMinimumSystemVersion + 11.0 + LSApplicationCategoryType + public.app-category.music + NSHighResolutionCapable + + + +PLIST +plutil -lint "$APP/Contents/Info.plist" >/dev/null + +# Ad-hoc signature: required for arm64 binaries; not a Developer ID signature, +# so Gatekeeper still asks on first launch (right click -> Open). +codesign --force --deep --sign - "$APP" + +ditto -c -k --keepParent "$APP" dist/xWinAmp-macos.zip +echo "Built $APP ($VERSION) and dist/xWinAmp-macos.zip" diff --git a/tools/mkicon/main.go b/tools/mkicon/main.go new file mode 100644 index 0000000..d60e399 --- /dev/null +++ b/tools/mkicon/main.go @@ -0,0 +1,111 @@ +// Command mkicon draws the xWinAmp app icon and writes it as a PNG. +// +// go run ./tools/mkicon -size 1024 -o icon.png +package main + +import ( + "flag" + "image" + "image/color" + "image/png" + "log" + "math" + "os" +) + +var ( + colBg = color.RGBA{0x2a, 0x2a, 0x3a, 0xff} + colBorder = color.RGBA{0x5a, 0x5a, 0x78, 0xff} + colScreen = color.RGBA{0x00, 0x00, 0x00, 0xff} + colLCD = color.RGBA{0x00, 0xe0, 0x00, 0xff} +) + +func main() { + size := flag.Int("size", 1024, "icon size in pixels") + out := flag.String("o", "icon.png", "output PNG file") + flag.Parse() + + f, err := os.Create(*out) + if err != nil { + log.Fatal(err) + } + if err := png.Encode(f, draw(*size)); err != nil { + log.Fatal(err) + } + if err := f.Close(); err != nil { + log.Fatal(err) + } +} + +// draw renders the icon: a rounded dark body like the player window with a +// black screen and a green play triangle, in the macOS icon grid (the body +// covers about 80% of the canvas). +func draw(size int) *image.RGBA { + img := image.NewRGBA(image.Rect(0, 0, size, size)) + s := float64(size) + margin := s * 0.1 + body := rect{margin, margin, s - margin, s - margin} + screen := body.inset(s * 0.09) + tri := screen.inset(s * 0.14) + + for y := range size { + for x := range size { + // Sample at the pixel centre with 4x4 supersampling for smooth edges. + var r, g, b, a float64 + for sy := range 4 { + for sx := range 4 { + px := float64(x) + (float64(sx)+0.5)/4 + py := float64(y) + (float64(sy)+0.5)/4 + c, ok := sample(px, py, s, body, screen, tri) + if ok { + r += float64(c.R) + g += float64(c.G) + b += float64(c.B) + a += 255 + } + } + } + if a > 0 { + // Premultiplied: colours are summed only where covered. + img.SetRGBA(x, y, color.RGBA{uint8(r / 16), uint8(g / 16), uint8(b / 16), uint8(a / 16)}) + } + } + } + return img +} + +func sample(x, y, s float64, body, screen, tri rect) (color.RGBA, bool) { + radius := s * 0.18 + if !body.containsRounded(x, y, radius) { + return color.RGBA{}, false + } + if !body.inset(s*0.02).containsRounded(x, y, radius*0.9) { + return colBorder, true + } + if !screen.containsRounded(x, y, s*0.04) { + return colBg, true + } + // Play triangle pointing right, centred in the screen. + t := tri + if x >= t.x0+t.w()*0.08 && math.Abs(y-t.cy())*2 <= t.h()*(1-(x-t.x0-t.w()*0.08)/(t.w()*0.84)) { + return colLCD, true + } + return colScreen, true +} + +type rect struct{ x0, y0, x1, y1 float64 } + +func (r rect) w() float64 { return r.x1 - r.x0 } +func (r rect) h() float64 { return r.y1 - r.y0 } +func (r rect) cy() float64 { return (r.y0 + r.y1) / 2 } + +func (r rect) inset(d float64) rect { return rect{r.x0 + d, r.y0 + d, r.x1 - d, r.y1 - d} } + +func (r rect) containsRounded(x, y, rad float64) bool { + if x < r.x0 || x > r.x1 || y < r.y0 || y > r.y1 { + return false + } + cx := math.Max(r.x0+rad, math.Min(x, r.x1-rad)) + cy := math.Max(r.y0+rad, math.Min(y, r.y1-rad)) + return math.Hypot(x-cx, y-cy) <= rad +}