Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
runs-on: macos-latest
timeout-minutes: 30
permissions:
contents: write # create the GitHub Release on version tags
contents: read
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -160,9 +160,24 @@ jobs:
build/*.dmg
if-no-files-found: error

# sign_update from the Sparkle release the app embeds (Package.swift pins the same version).
publish-release:
needs: build-app
if: startsWith(github.ref, 'refs/tags/v')
runs-on: macos-latest
timeout-minutes: 15
permissions:
contents: write
concurrency:
group: howler-release
cancel-in-progress: false
queue: max
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: Howler
path: build
- name: Fetch Sparkle tools
if: startsWith(github.ref, 'refs/tags/v')
run: |
curl -sSfL -o "$RUNNER_TEMP/sparkle.tar.xz" \
https://github.com/sparkle-project/Sparkle/releases/download/2.10.0/Sparkle-2.10.0.tar.xz
Expand All @@ -171,40 +186,17 @@ jobs:
echo "SIGN_UPDATE=$RUNNER_TEMP/sparkle/bin/sign_update" >> "$GITHUB_ENV"

- name: Publish release
if: startsWith(github.ref, 'refs/tags/v')
env:
GH_TOKEN: ${{ github.token }}
SPARKLE_ED_PRIVATE_KEY: ${{ secrets.SPARKLE_ED_PRIVATE_KEY }}
run: |
source app.config
if [[ "$GITHUB_REF_NAME" != "v$VERSION" ]]; then
echo "error: tag $GITHUB_REF_NAME does not match VERSION=$VERSION in app.config" >&2
exit 1
fi
# The appcast installed copies poll (SUFeedURL). It is built before anything is published
# and goes up with the zip and dmg, so the latest release never lacks one.
if [[ -z "$SPARKLE_ED_PRIVATE_KEY" ]]; then
echo "error: SPARKLE_ED_PRIVATE_KEY is not set; installed copies won't be offered this update" >&2
exit 1
fi
# The release page and the in-app update panel use the same authored notes.
NOTES="docs/releases/$VERSION.md"
if [[ ! -s "$NOTES" ]] || ! grep -Eq '^[*-] [^[:space:]]' "$NOTES"; then
echo "error: add user-facing release notes to $NOTES before publishing" >&2
exit 1
fi
./scripts/appcast.sh "$NOTES"
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
gh release edit "$GITHUB_REF_NAME" --notes-file "$NOTES"
gh release upload "$GITHUB_REF_NAME" build/*.zip build/*.dmg build/appcast.xml --clobber
else
gh release create "$GITHUB_REF_NAME" build/*.zip build/*.dmg build/appcast.xml \
--title "$APP_NAME $GITHUB_REF_NAME" --notes-file "$NOTES" --latest
fi
export APP_NAME BUNDLE_ID VERSION BUILD_NUMBER SPARKLE_FEED_URL
python3 scripts/release.py

# Keep the protected-branch check present on content-only PRs and detector failures.
build:
needs: [changes, build-app]
needs: [changes, build-app, publish-release]
if: always()
runs-on: ubuntu-latest
permissions:
Expand All @@ -215,13 +207,20 @@ jobs:
CHANGES: ${{ needs.changes.result }}
APP_REQUIRED: ${{ needs.changes.outputs.app }}
APP: ${{ needs.build-app.result }}
RELEASE_REQUIRED: ${{ startsWith(github.ref, 'refs/tags/v') }}
RELEASE: ${{ needs.publish-release.result }}
run: |-
test "$CHANGES" = success
if [ "$APP_REQUIRED" = true ]; then
test "$APP" = success
else
test "$APP" = skipped
fi
if [ "$RELEASE_REQUIRED" = true ]; then
test "$RELEASE" = success
else
test "$RELEASE" = skipped
fi

homebrew:
needs: build
Expand Down
107 changes: 9 additions & 98 deletions Tests/HowlerAppTests/ReleaseNotesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,19 @@ import Foundation
import XCTest

final class ReleaseNotesTests: XCTestCase {
private struct Result {
let status: Int32
let appcast: String
let publishedNotes: String
let calls: String
}

/// Run the real publish step with local gh/signing substitutes, without contacting GitHub.
private func publish(existing: Bool, includeNotes: Bool = true) throws -> Result {
func testReleaseWorkflowWithMockGitHubAndSigningTools() throws {
let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
.deletingLastPathComponent().deletingLastPathComponent()
let workflow = try String(contentsOf: root.appendingPathComponent(".github/workflows/build.yml"))
let step = try XCTUnwrap(workflow.components(separatedBy: " - name: Publish release").last)
let body = try XCTUnwrap(step.components(separatedBy: " run: |\n").last)
.components(separatedBy: "\n")
.prefix { $0.isEmpty || $0.hasPrefix(" ") }
.map { String($0.dropFirst(10)) }.joined(separator: "\n")
let directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
defer { try? FileManager.default.removeItem(at: directory) }
for path in ["scripts", "build", "bin", "docs/releases"] {
try FileManager.default.createDirectory(at: directory.appendingPathComponent(path), withIntermediateDirectories: true)
}
func write(_ text: String, _ path: String, executable: Bool = false) throws {
let url = directory.appendingPathComponent(path)
try text.write(to: url, atomically: true, encoding: .utf8)
if executable { try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: url.path) }
}
try write("""
APP_NAME="Howler"
VERSION="0.1.99"
BUILD_NUMBER="99"
MIN_MACOS="14.0"
SPARKLE_FEED_URL="https://example.invalid/releases/latest/download/appcast.xml"
""", "app.config")
try write("fixture archive", "build/Howler.zip")
let notes = "## What's Changed\n\n* A visible reminder for available updates.\n* Install and restart from one Update button.\n"
if includeNotes { try write(notes, "docs/releases/0.1.99.md") }
try write(try String(contentsOf: root.appendingPathComponent("scripts/appcast.sh")), "scripts/appcast.sh", executable: true)
try write("""
#!/bin/bash
cat >/dev/null
echo 'sparkle:edSignature="fixture-signature" length="15"'
""", "bin/sign-update", executable: true)
try write("""
#!/bin/bash
echo "$*" >> "$FIXTURE_ROOT/calls"
if [[ "$1 $2" == "release view" ]]; then
[[ "$FIXTURE_EXISTING" == 1 ]] || exit 1
echo '* feat: old technical title'
elif [[ "$1" == api ]]; then
echo '* feat: generated technical title'
else
while [[ $# -gt 0 ]]; do
if [[ "$1" == --notes-file ]]; then
cp "$2" "$FIXTURE_ROOT/published-notes"
break
fi
shift
done
fi
""", "bin/gh", executable: true)
let process = Process()
process.executableURL = URL(fileURLWithPath: "/bin/bash")
process.arguments = ["-e", "-u", "-o", "pipefail", "-c", body]
process.currentDirectoryURL = directory
process.environment = ["PATH": directory.appendingPathComponent("bin").path + ":/usr/bin:/bin",
"FIXTURE_ROOT": directory.path, "FIXTURE_EXISTING": existing ? "1" : "0",
"GITHUB_REF_NAME": "v0.1.99", "GITHUB_REPOSITORY": "fixture/howler", "RUNNER_TEMP": directory.path,
"SPARKLE_ED_PRIVATE_KEY": "fixture-only",
"SIGN_UPDATE": directory.appendingPathComponent("bin/sign-update").path]
process.standardOutput = Pipe()
process.standardError = Pipe()
let output = Pipe()
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
process.arguments = ["python3", root.appendingPathComponent("Tests/ReleaseWorkflowTests.py").path, "-v"]
process.currentDirectoryURL = root
process.standardOutput = output
process.standardError = output
try process.run()
let data = output.fileHandleForReading.readDataToEndOfFile()
process.waitUntilExit()
func read(_ path: String) -> String { (try? String(contentsOf: directory.appendingPathComponent(path))) ?? "" }
return Result(status: process.terminationStatus, appcast: read("build/appcast.xml"),
publishedNotes: read("published-notes"), calls: read("calls"))
}

func testNewReleaseAndUpdaterUseTheSameAuthoredNotes() throws {
let result = try publish(existing: false)
XCTAssertEqual(result.status, 0)
XCTAssertTrue(result.appcast.contains("A visible reminder for available updates."))
XCTAssertTrue(result.appcast.contains("Install and restart from one Update button."))
XCTAssertTrue(result.publishedNotes.contains("A visible reminder for available updates."))
XCTAssertFalse(result.appcast.contains("technical title"))
XCTAssertFalse(result.calls.contains("generate-notes"))
}

func testRerunningReleaseRefreshesBothSurfacesFromAuthoredNotes() throws {
let result = try publish(existing: true)
XCTAssertEqual(result.status, 0)
XCTAssertTrue(result.appcast.contains("Install and restart from one Update button."))
XCTAssertTrue(result.publishedNotes.contains("Install and restart from one Update button."))
XCTAssertFalse(result.appcast.contains("technical title"))
}

func testMissingNotesStopsBeforeAnyGitHubMutation() throws {
let result = try publish(existing: false, includeNotes: false)
XCTAssertNotEqual(result.status, 0)
XCTAssertFalse(result.calls.contains("release create"))
XCTAssertFalse(result.calls.contains("release upload"))
XCTAssertFalse(result.calls.contains("release edit"))
XCTAssertEqual(process.terminationStatus, 0, String(decoding: data, as: UTF8.self))
}
}
Loading
Loading