Skip to content
Merged
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
216 changes: 216 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
name: Nightly

# Builds, signs and notarizes main once a night and publishes it as the
# rolling `nightly` pre-release, for anyone who picks Settings → Actions →
# Update channel → Nightly. A night when main hasn't moved is skipped, and
# "Run workflow" builds one on demand.
#
# Nothing here reaches anyone else. The Stable channel, and every app from
# before channels existed, reads /releases/latest, which never returns a
# pre-release.
#
# A build is named <next>-nightly.<n>, a semver pre-release of the release it
# leads up to: next is the version release-please's open release PR proposes
# (a patch bump of the last release when there's none), and n is main's commit
# count, so a later build always has the larger number (UpdateOffer compares
# them).
#
# The build, sign and notarize steps mirror release.yml's. Keep them in step.

on:
schedule:
# 02:00 UTC: 2am in UK winter, 3am in summer. GitHub's cron has no zones.
- cron: '0 2 * * *'
workflow_dispatch:

# A build already running finishes; a second request waits for it.
concurrency:
group: nightly
cancel-in-progress: false

jobs:
prepare:
name: Point the nightly release at this commit
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
base: ${{ steps.version.outputs.base }}
build: ${{ steps.version.outputs.build }}
changed: ${{ steps.changed.outputs.changed }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
fetch-depth: 0 # the commit count is the build number
persist-credentials: false

# Nothing to build when the nightly tag is already this commit, unless
# someone asked for one by hand.
- name: Check main has moved
id: changed
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
built=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/nightly" --jq .object.sha 2>/dev/null || true)
if [[ "$built" == "$GITHUB_SHA" && "$GITHUB_EVENT_NAME" == "schedule" ]]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "main is still ${GITHUB_SHA}, already built"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Work out the version
if: steps.changed.outputs.changed == 'true'
id: version
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
last=$(jq -r '."."' .release-please-manifest.json)
# release-please recomputes its release PR from the commits on every
# push to main, so its title is the next version.
base=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --label "autorelease: pending" \
--json title --jq '.[0].title // ""' \
| sed -n 's/^chore(main): release \([0-9.]*\)$/\1/p')
if [[ -z "$base" ]]; then
base=$(awk -F. '{ printf "%d.%d.%d", $1, $2, $3 + 1 }' <<<"$last")
fi
build=$(git rev-list --count HEAD)
echo "base=$base" >> "$GITHUB_OUTPUT"
echo "build=$build" >> "$GITHUB_OUTPUT"
echo "Nightly ${base}-nightly.${build} from ${GITHUB_SHA}"

# The tag moves with every build, and the release is made on the first
# run. Never marked latest, so /releases/latest keeps returning the last
# stable release.
- name: Move the tag and update the release
if: steps.changed.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.base }}-nightly.${{ steps.version.outputs.build }}
run: |
set -euo pipefail
repo="$GITHUB_REPOSITORY"
gh api -X PATCH "repos/$repo/git/refs/tags/nightly" -f sha="$GITHUB_SHA" -F force=true >/dev/null \
|| gh api -X POST "repos/$repo/git/refs" -f ref=refs/tags/nightly -f sha="$GITHUB_SHA" >/dev/null
notes="Built from ${GITHUB_SHA} on main. Not a release: this is what Settings → Actions → Update channel → Nightly installs, rebuilt each night main has moved. Changes since the last release: https://github.com/${repo}/compare/v$(jq -r '."."' .release-please-manifest.json)...${GITHUB_SHA}"
if gh release view nightly --repo "$repo" >/dev/null 2>&1; then
gh release edit nightly --repo "$repo" --prerelease --latest=false \
--title "Nightly ${VERSION}" --notes "$notes"
else
gh release create nightly --repo "$repo" --verify-tag --prerelease --latest=false \
--title "Nightly ${VERSION}" --notes "$notes"
fi

build:
name: Build, sign, notarize (${{ matrix.arch }})
needs: prepare
if: needs.prepare.outputs.changed == 'true'
runs-on: macos-15
permissions:
contents: write
strategy:
matrix:
arch: [arm64, x86_64]
fail-fast: false

env:
STACKNUDGE_BUNDLE_VENV: "1"
KEYCHAIN: build-stack-nudge.keychain
BASE: ${{ needs.prepare.outputs.base }}
BUILD: ${{ needs.prepare.outputs.build }}

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
ref: ${{ github.sha }}
persist-credentials: false

# The release it leads up to, plus the build number the app compares
# (BuildVersion.current reads StackNudgeNightlyBuild).
- name: Stamp the nightly version
run: |
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $BASE" panel/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD" panel/Info.plist
/usr/libexec/PlistBuddy -c "Add :StackNudgeNightlyBuild string $BUILD" panel/Info.plist

- name: Set up signing identity
env:
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
MACOS_KEYCHAIN_PWD: ${{ secrets.MACOS_KEYCHAIN_PWD }}
run: |
set -euo pipefail
echo "$MACOS_CERTIFICATE" | base64 --decode > /tmp/cert.p12
security create-keychain -p "$MACOS_KEYCHAIN_PWD" "$KEYCHAIN"
security default-keychain -s "$KEYCHAIN"
security unlock-keychain -p "$MACOS_KEYCHAIN_PWD" "$KEYCHAIN"
security set-keychain-settings -lut 7200 "$KEYCHAIN"
security import /tmp/cert.p12 -k "$KEYCHAIN" \
-P "$MACOS_CERTIFICATE_PWD" \
-T /usr/bin/codesign \
-T /usr/bin/security
security set-key-partition-list \
-S apple-tool:,apple:,codesign: \
-s -k "$MACOS_KEYCHAIN_PWD" "$KEYCHAIN"
IDENTITY=$(
security find-identity -v -p codesigning "$KEYCHAIN" \
| awk -F'"' '/"Developer ID Application/ {print $2; exit}'
)
if [[ -z "$IDENTITY" ]]; then
echo "::error::No Developer ID Application identity found in keychain after import"
exit 1
fi
echo "STACKNUDGE_SIGN_IDENTITY=$IDENTITY" >> "$GITHUB_ENV"
rm -f /tmp/cert.p12

- name: Build ${{ matrix.arch }}
run: bash build.sh ${{ matrix.arch }}

- name: Notarize ${{ matrix.arch }}
env:
MACOS_NOTARY_API_KEY: ${{ secrets.MACOS_NOTARY_API_KEY }}
MACOS_NOTARY_API_KEY_ID: ${{ secrets.MACOS_NOTARY_API_KEY_ID }}
MACOS_NOTARY_API_ISSUER_ID: ${{ secrets.MACOS_NOTARY_API_ISSUER_ID }}
run: |
set -euo pipefail
echo "$MACOS_NOTARY_API_KEY" | base64 --decode > /tmp/notary-key.p8
ditto -c -k --keepParent build/StackNudge.app /tmp/notarize.zip
xcrun notarytool submit /tmp/notarize.zip \
--key /tmp/notary-key.p8 \
--key-id "$MACOS_NOTARY_API_KEY_ID" \
--issuer "$MACOS_NOTARY_API_ISSUER_ID" \
--wait
xcrun stapler staple build/StackNudge.app
spctl -a -vv build/StackNudge.app || true
rm -f /tmp/notary-key.p8 /tmp/notarize.zip

- name: Package ${{ matrix.arch }}
run: |
set -euo pipefail
ARTIFACT="stack-nudge-${BASE}-nightly.${BUILD}-macos-${{ matrix.arch }}.tar.gz"
tar czf "$ARTIFACT" -C build StackNudge.app
shasum -a 256 "$ARTIFACT" | awk -v name="$ARTIFACT" '{print $1 " " name}' \
> "$ARTIFACT.sha256"
echo "ARTIFACT=$ARTIFACT" >> "$GITHUB_ENV"
ls -la "$ARTIFACT" "$ARTIFACT.sha256"

# Upload first, then drop this arch's older build, so the release is
# never without one. The app reads its version from the artifact's name.
- name: Publish ${{ matrix.arch }}
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
repo="$GITHUB_REPOSITORY"
gh release upload nightly --repo "$repo" --clobber "$ARTIFACT" "$ARTIFACT.sha256"
gh release view nightly --repo "$repo" --json assets --jq '.assets[].name' \
| grep -E -- "-macos-${{ matrix.arch }}\.tar\.gz(\.sha256)?$" \
| grep -v -F -x -e "$ARTIFACT" -e "$ARTIFACT.sha256" \
| while read -r old; do gh release delete-asset nightly "$old" --repo "$repo" --yes; done

- name: Cleanup keychain
if: always()
run: |
security delete-keychain "$KEYCHAIN" || true
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ final class ExtensionInstallerTests: XCTestCase {
_ = ExtensionInstaller.releaseJSON(http: { asked = $0; return Data("{}".utf8) }, gh: { _ in nil })
XCTAssertEqual(asked?.absoluteString,
"https://api.github.com/repos/StackOneHQ/stack-nudge-extensions-marketplace/releases/latest")
XCTAssertNotEqual(asked, UpdateChecker.latestReleaseURL)
XCTAssertNotEqual(asked, UpdateChannel.stable.releaseURL)
}

// The CLI is the fallback, not the first choice — it spawns a process.
Expand Down
107 changes: 107 additions & 0 deletions Tests/StackNudgePanelCoreTests/UpdateChannelTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import XCTest

@testable import StackNudgePanelCore

// Stable follows tagged releases; Nightly follows the rolling `nightly`
// pre-release that nightly.yml rebuilds from main each night.
@MainActor
final class UpdateChannelTests: XCTestCase {

// MARK: - Versions

func testAVersionReadsAsAReleaseOrANightly() {
XCTAssertEqual(BuildVersion("2.10.1"), BuildVersion(base: "2.10.1"))
XCTAssertEqual(BuildVersion("2.10.0-nightly.812"), BuildVersion(base: "2.10.0", nightly: 812))
XCTAssertEqual(BuildVersion("2.10.0-nightly.x"), BuildVersion(base: "2.10.0-nightly.x"),
"a nightly needs a number")
XCTAssertEqual(BuildVersion(base: "2.10.0", nightly: 812).string, "2.10.0-nightly.812")
XCTAssertEqual(BuildVersion(base: "2.10.0", nightly: 812).display, "2.10.0 (nightly 812)")
XCTAssertEqual(BuildVersion(base: "2.10.0").display, "2.10.0")
}

func testTheVersionComesFromThisArchsArtifact() {
XCTAssertEqual(BuildVersion.fromArtifact("stack-nudge-2.10.0-nightly.812-macos-arm64.tar.gz", arch: "arm64"),
BuildVersion(base: "2.10.0", nightly: 812))
XCTAssertNil(BuildVersion.fromArtifact("stack-nudge-2.10.0-nightly.812-macos-x86_64.tar.gz", arch: "arm64"))
XCTAssertNil(BuildVersion.fromArtifact("stack-nudge-2.10.0-nightly.812-macos-arm64.tar.gz.sha256", arch: "arm64"))
XCTAssertNil(BuildVersion.fromArtifact("extension-away-1.1.1.tar.gz", arch: "arm64"))
}

private func release(tag: String, assets: [String]) -> [String: Any] {
["tag_name": tag, "assets": assets.map { ["name": $0] }]
}

// A nightly's tag is just "nightly", and each arch's upload replaces its
// own files, so the arm64 and x86_64 builds can briefly differ.
func testANightlyIsReadFromItsArtifactNotItsTag() {
let json = release(tag: "nightly", assets: [
"stack-nudge-2.10.0-nightly.813-macos-arm64.tar.gz",
"stack-nudge-2.10.0-nightly.813-macos-arm64.tar.gz.sha256",
"stack-nudge-2.10.0-nightly.812-macos-x86_64.tar.gz",
])
XCTAssertEqual(BuildVersion.offered(by: json, channel: .nightly, arch: "arm64"),
BuildVersion(base: "2.10.0", nightly: 813))
XCTAssertEqual(BuildVersion.offered(by: json, channel: .nightly, arch: "x86_64"),
BuildVersion(base: "2.10.0", nightly: 812))
XCTAssertNil(BuildVersion.offered(by: release(tag: "nightly", assets: []), channel: .nightly, arch: "arm64"))
XCTAssertEqual(BuildVersion.offered(by: release(tag: "v2.11.0", assets: []), channel: .stable, arch: "arm64"),
BuildVersion(base: "2.11.0"))
}

// MARK: - What each channel offers

// Semver: 2.10.1-nightly.812 comes before 2.10.1.
func testStableOffersANewerReleaseIncludingTheOneANightlyLedUpTo() {
let offer = { UpdateOffer.shouldOffer(BuildVersion($0), to: BuildVersion($1), on: .stable) }
XCTAssertTrue(offer("2.11.0", "2.10.0"))
XCTAssertFalse(offer("2.10.0", "2.10.0"))
// Back on Stable, a nightly waits for the release it was heading for
// rather than stepping back to the one before it.
XCTAssertFalse(offer("2.10.0", "2.10.1-nightly.812"))
XCTAssertTrue(offer("2.10.1", "2.10.1-nightly.812"))
XCTAssertTrue(offer("2.11.0", "2.10.1-nightly.812"))
XCTAssertFalse(offer("2.10.1-nightly.900", "2.10.0"), "the stable channel offers releases only")
}

func testNightlyOffersALaterBuildOrMovesAReleaseOnToTheNextVersion() {
let offer = { UpdateOffer.shouldOffer(BuildVersion($0), to: BuildVersion($1), on: .nightly) }
XCTAssertTrue(offer("2.10.1-nightly.813", "2.10.1-nightly.812"))
XCTAssertFalse(offer("2.10.1-nightly.812", "2.10.1-nightly.812"))
XCTAssertFalse(offer("2.10.1-nightly.811", "2.10.1-nightly.812"))
// A feat landing moves the next version from a patch to a minor.
XCTAssertTrue(offer("2.11.0-nightly.815", "2.10.1-nightly.812"))
// After 2.10.0 the nightlies lead up to 2.10.1, which is ahead of it.
XCTAssertTrue(offer("2.10.1-nightly.812", "2.10.0"))
// A nightly of the release that's running comes before it.
XCTAssertFalse(offer("2.10.1-nightly.812", "2.10.1"))
XCTAssertFalse(offer("2.11.0", "2.10.0"), "the nightly channel offers nightlies only")
}

// MARK: - The setting

func testAnythingButNightlyIsStable() {
XCTAssertEqual(UpdateChannel.from(config: nil), .stable)
XCTAssertEqual(UpdateChannel.from(config: " Nightly "), .nightly)
XCTAssertEqual(UpdateChannel.from(config: "beta"), .stable)
}

func testTheChannelIsAValueRowUnderActions() {
let nav = PanelNav()
XCTAssertTrue(nav.rows(in: .actions).contains(.updateChannel))
nav.settingsCategory = .actions
nav.settingsDetailFocused = true
nav.selectedSettingIndex = nav.index(of: .updateChannel)
XCTAssertTrue(nav.selectedRowIsPicker)
nav.cycleForward()
XCTAssertEqual(nav.updateChannel, .stable, "arrows do nothing until a pick starts")
}

// An offer from the other channel no longer applies, so switching drops
// it and asks again. setUpdateChannel writes the real config, so this
// stops short of calling it and checks the pieces it relies on.
func testTheChannelsReleasesAreDifferentEndpoints() {
XCTAssertTrue(UpdateChannel.stable.releaseURL.path.hasSuffix("/releases/latest"))
XCTAssertTrue(UpdateChannel.nightly.releaseURL.path.hasSuffix("/releases/tags/nightly"))
XCTAssertEqual(UpdateChannel.nightly.releaseGHPath, "repos/StackOneHQ/stack-nudge/releases/tags/nightly")
}
}
2 changes: 1 addition & 1 deletion docs/panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Reachable from the tab strip, `Cmd+,`, or the last `Cmd`-number. A sidebar of ca
| **Extensions** | What's installed, then **Browse extensions** (see [Extensions](#extensions)) |
| **Panel** | Hotkey, Pin panel, Keep open when empty, Launch at login, Name from tab titles |
| **Events** | History per session, Event history, Clear event history |
| **Actions** | Edit phrases, Check permissions, Open config file, View release notes, Check for updates, Uninstall, Quit |
| **Actions** | Edit phrases, Check permissions, Open config file, View release notes, Update channel (Stable or Nightly, see [Nightly builds](setup.md#nightly-builds)), Check for updates, Uninstall, Quit |
| **About** | The version and hook-script status, and a link to this repo |

An extension that asks for a Settings page gets one under Extensions. A pending update, an extension update, a missing permission, or an agent whose hooks aren't wired yet shows as a row above every category. An app or extension update also puts a dot on the Settings tab.
Expand Down
6 changes: 6 additions & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Because the swap replaces only the bundle, the hook script the agents invoke (`~

No source clone, no swiftc rebuild on the user's machine — the new bundle is the already-signed-and-notarized artifact from CI. Updates are fast and don't disturb the user's Xcode CLT or Python install (or lack thereof).

### Nightly builds

**Settings → Actions → Update channel** picks which builds the updater offers. **Stable**, the default, is the tagged releases above. **Nightly** follows `main`: at 02:00 UTC each night `main` has moved, it's built, signed and notarized like a release (`.github/workflows/nightly.yml`, which can also be run by hand from Actions) and published as the rolling [`nightly` pre-release](https://github.com/StackOneHQ/stack-nudge/releases/tag/nightly), so the update row offers it within a couple of hours (or straight away from **Check for updates…**). A nightly is a semver pre-release of the release `main` is heading for, `<next>-nightly.<n>`: the version release-please's open release PR proposes (a patch bump when there isn't one) and `main`'s commit count, so Settings → About shows `2.10.1 (nightly 812)`. Switching back to Stable doesn't step back: the release your nightly was leading up to is offered when it ships. The channel is `STACKNUDGE_UPDATE_CHANNEL` (`stable` or `nightly`) in `~/.stack-nudge/config`. Nightlies are pre-releases, which GitHub's latest-release endpoint never returns, so nobody on Stable, and no app from before channels existed, is offered one.

To grab one by hand: `gh release download nightly --repo StackOneHQ/stack-nudge --pattern "stack-nudge-*-macos-$(uname -m).tar.gz*"`.

## Uninstall

### macOS — in-app
Expand Down
6 changes: 6 additions & 0 deletions notify.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ STACKNUDGE_FLOATING_WIDGET=companion
# Default: true
#STACKNUDGE_GITHUB_USE_GH=false

# Which builds the in-app updater offers: stable (tagged releases) or nightly
# (main, rebuilt each night it has moved, as the rolling `nightly`
# pre-release). Also Settings → Actions → Update channel.
# Default: stable
#STACKNUDGE_UPDATE_CHANNEL=nightly

# Fair-usage budget for pi, in tokens per day, per lane. pi enforces no quota
# of its own — API models bill per token against your keys, local models are
# free — so these are your own allowances and nothing cuts you off at them. The
Expand Down
1 change: 1 addition & 0 deletions panel/Panel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,7 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,

updateChecker = UpdateChecker(nav: nav)
updateChecker?.start()
nav.onUpdateChannelChanged = { [weak self] in self?.updateChecker?.check() }
startExtensionUpdateChecks()
updater = Updater(nav: nav)

Expand Down
Loading
Loading