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
243 changes: 209 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,154 @@
name: build
name: Build desktop release

on: workflow_dispatch
on:
workflow_dispatch:
inputs:
renderer_ref:
description: "Approved Showcode commit SHA (blank uses master)"
required: false
default: ""

jobs:
release:
runs-on: ${{ matrix.os }}
permissions:
contents: read

permissions:
contents: write
concurrency:
group: desktop-release
cancel-in-progress: false

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.prepare.outputs.version }}
commit: ${{ steps.commit.outputs.sha }}
steps:
- uses: actions/create-github-app-token@v2
id: app
with:
app-id: ${{ vars.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: showcode-app
permission-contents: write
- uses: actions/checkout@v5
with:
ref: master
submodules: recursive
fetch-depth: 0
token: ${{ steps.app.outputs.token }}
- uses: actions/setup-node@v5
with:
node-version: 22
cache: npm
cache-dependency-path: |
package-lock.json
showcode/package-lock.json
- name: Pin the approved renderer
env:
RENDERER_REF: ${{ inputs.renderer_ref }}
run: |
mkdir -p .release
git rev-parse HEAD:showcode > .release/previous-ref
git -C showcode fetch origin master
if [ -z "$RENDERER_REF" ]; then
RENDERER_REF=$(git -C showcode rev-parse origin/master)
fi
[[ "$RENDERER_REF" =~ ^[0-9a-f]{40}$ ]] || { echo 'Use a full Showcode commit SHA.'; exit 1; }
git -C showcode merge-base --is-ancestor "$RENDERER_REF" origin/master
git -C showcode checkout --detach "$RENDERER_REF"
printf '%s' "$RENDERER_REF" > .release/renderer-ref
- name: Read approved release notes
run: |
npm ci --prefix showcode
node showcode/scripts/releases/catalog.mjs json > .release/metadata.json
- name: Update desktop version
id: prepare
run: node scripts/releases/prepare.mjs "$(cat .release/previous-ref)" "$(cat .release/renderer-ref)"
- name: Refuse to rebuild a published release
uses: actions/github-script@v7
env:
RELEASE_VERSION: ${{ steps.prepare.outputs.version }}
with:
script: |
try {
const {data} = await github.rest.repos.getReleaseByTag({
...context.repo, tag: `v${process.env.RELEASE_VERSION}`,
});
if (!data.draft) throw new Error('This version is already published. Prepare a new version.');
} catch (error) {
if (error.status !== 404) throw error;
}
- name: Record the desktop release commit and tag
id: commit
env:
RELEASE_VERSION: ${{ steps.prepare.outputs.version }}
run: |
git config user.name 'Showcode Release Bot'
git config user.email 'release-bot@users.noreply.github.com'
git add package.json package-lock.json showcode
if ! git diff --cached --quiet; then
git commit -m "Release Showcode $RELEASE_VERSION"
fi
RELEASE_COMMIT=$(git rev-parse HEAD)
RELEASE_TAG="v$RELEASE_VERSION"
if git show-ref --verify --quiet "refs/tags/$RELEASE_TAG"; then
test "$(git rev-parse "$RELEASE_TAG^{commit}")" = "$RELEASE_COMMIT"
else
git tag "$RELEASE_TAG" "$RELEASE_COMMIT"
fi
git push --atomic origin HEAD:master "refs/tags/$RELEASE_TAG"
echo "sha=$RELEASE_COMMIT" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: release-notes
path: |
.release/metadata.json
.release/notes.md
include-hidden-files: true

build:
needs: prepare
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- name: Check out Git repository
uses: actions/checkout@v5
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.commit }}
submodules: recursive

- name: Setup Node
uses: actions/setup-node@v5
- uses: actions/setup-node@v5
with:
node-version: 22

- uses: actions/cache@v5
cache: npm
cache-dependency-path: |
package-lock.json
showcode/package-lock.json
- uses: actions/download-artifact@v4
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}

- name: Install Showcode Dependencies
run: (cd ./showcode && npm install)

- name: Generate Showcode
run: (cd ./showcode && npm run generate)
name: release-notes
path: .release
- name: Install dependencies
shell: bash
run: |
npm ci --prefix showcode
npm ci
- name: Test renderer
if: runner.os == 'Linux'
working-directory: showcode
run: |
npx nuxi prepare
npm run test:releases
npx vitest run
- name: Generate renderer
working-directory: showcode
run: npm run generate
env:
IS_DESKTOP: true
NODE_OPTIONS: --max-old-space-size=4096

- name: Install App Dependencies
run: npm install

- name: Test App
- name: Test desktop app
run: npm test

- name: Import macOS signing certificate
if: startsWith(matrix.os, 'macos')
env:
Expand All @@ -68,21 +172,92 @@ jobs:
echo "CSC_KEYCHAIN=$SIGNING_KEYCHAIN_PATH" >> "$GITHUB_ENV"
rm "$SIGNING_CERTIFICATE_PATH"

- name: Build & Publish Application
- name: Package application without publishing
shell: bash
run: |
if [[ "$RUNNER_OS" == "macOS" ]]; then
unset CSC_LINK
npx electron-builder --publish always --config.forceCodeSigning=true
unset CSC_LINK
npx electron-builder --publish never --config.forceCodeSigning=true -c.releaseInfo.releaseNotesFile=.release/notes.md
else
npx electron-builder --publish always
npx electron-builder --publish never -c.releaseInfo.releaseNotesFile=.release/notes.md
fi
env:
RELEASE: true
NODE_ENV: production
CSC_LINK: ${{ secrets.CSC_LINK }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
- uses: actions/upload-artifact@v4
with:
name: installers-${{ runner.os }}
if-no-files-found: error
compression-level: 0
path: |
dist/*.dmg
dist/*.zip
dist/*.exe
dist/*.AppImage
dist/*.blockmap
dist/latest*.yml

draft:
needs: [prepare, build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.commit }}
- uses: actions/setup-node@v5
with:
node-version: 22
cache: npm
- run: npm ci --ignore-scripts
- uses: actions/download-artifact@v4
with:
pattern: installers-*
path: dist
merge-multiple: true
- uses: actions/download-artifact@v4
with:
name: release-notes
path: .release
- name: Verify all installers and updater manifests
env:
RELEASE_VERSION: ${{ needs.prepare.outputs.version }}
run: node scripts/releases/artifacts.mjs dist "$RELEASE_VERSION"
- name: Create or update the draft release
uses: actions/github-script@v7
env:
RELEASE_VERSION: ${{ needs.prepare.outputs.version }}
RELEASE_COMMIT: ${{ needs.prepare.outputs.commit }}
with:
script: |
const fs = require('node:fs');
const notes = fs.readFileSync('.release/notes.md', 'utf8');
const tag = `v${process.env.RELEASE_VERSION}`;
let release;
try {
release = (await github.rest.repos.getReleaseByTag({...context.repo, tag})).data;
} catch (error) {
if (error.status !== 404) throw error;
}
if (release && !release.draft) throw new Error('Refusing to modify a published release.');
const options = {
...context.repo, name: `Showcode ${process.env.RELEASE_VERSION}`,
body: notes, draft: true, prerelease: false,
};
if (release) await github.rest.repos.updateRelease({...options, release_id: release.id});
else await github.rest.repos.createRelease({
...options, tag_name: tag, target_commitish: process.env.RELEASE_COMMIT,
});
- name: Upload verified assets
env:
GH_TOKEN: ${{ github.token }}
RELEASE_VERSION: ${{ needs.prepare.outputs.version }}
run: |
gh release upload "v$RELEASE_VERSION" dist/* --clobber
printf '## Showcode %s is ready for review\n\nAll platform builds and updater manifests passed. Download an installer from the draft release, test it, then click **Publish release**. No rebuild is required.\n' "$RELEASE_VERSION" >> "$GITHUB_STEP_SUMMARY"
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on:
pull_request:
push:
branches: [master]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
cache: npm
- run: npm ci --ignore-scripts
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ yarn-debug.log*
# Electron build artifacts
out/
release/
.release/
48 changes: 48 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Desktop releases

The release starts in [Showcode's Prepare release workflow](https://github.com/stevebauman/showcode/actions/workflows/prepare-release.yml). Follow the full [release guide](https://github.com/stevebauman/showcode/blob/master/docs/releases.md) for the release entry format and GitHub App setup.

After the Showcode release PR merges, **Build desktop release** receives its exact commit SHA. It:

1. Verifies that the renderer SHA belongs to Showcode master and that its notes match its package version.
2. Updates the submodule, this repository's `package.json`, and both version fields in `package-lock.json`.
3. Commits those changes to master and creates `vVERSION` at the desktop commit. Existing tags must point to that same commit.
4. Builds macOS arm64/x64, Windows x64, and Linux x64 from that immutable commit. macOS signing and notarization use the existing Apple credentials.
5. Verifies required files, updater versions, and the size/SHA-512 of files referenced by updater manifests, and creates `SHA256SUMS.txt`.
6. Uploads installers, updater files, checksums, and the approved notes to a **draft** release after every build succeeds.

Download and test the draft installer, then publish it in GitHub. This makes the existing binaries available to users without rebuilding them. The workflow never publishes automatically.

## GitHub setup

Both repositories need the Actions variable `RELEASE_APP_ID` and Actions secret `RELEASE_APP_PRIVATE_KEY`. The GitHub App must be installed on both repositories with Contents, Pull requests, and Actions read/write permissions. In this repository, allow its mechanical pushes to master and `v*` tag creation under any branch/tag rules. See the upstream guide for the exact scope and rollout order.

Keep these existing Actions secrets here:

- `APPLE_ID`
- `APPLE_ID_PASSWORD`
- `APPLE_TEAM_ID`
- `CSC_LINK` (base64 P12)
- `CSC_KEY_PASSWORD`

Merge this automation before the Showcode automation. The existing 3.0.0 version is intentionally unchanged by this setup.

## Local preview

```sh
npm run release:local
```

This uses the currently checked-out renderer, installs locked dependencies, generates the UI, runs the desktop tests, packages a local app for the host architecture (ad-hoc signed on macOS), and opens it on macOS/Windows. On Linux it prints the executable path. For packaging without opening the app:

```sh
npm run release:local -- --no-open
```

The package has a `-local.0` suffix and disables automatic update checks. It never uses distribution signing, notarizes, publishes, or changes tracked versions/submodule references. For production-like signed installers, use the CI draft release.

## Retry a release

Prefer **Re-run failed jobs** on the original workflow run. To manually start the workflow, supply the same approved full Showcode SHA in `renderer_ref`. Leaving it blank selects Showcode master, which must already contain prepared release notes and a matching version.

The same version can be retried only with the same renderer SHA; changes require a new version. Published releases are never overwritten. Runs are serialized to avoid two releases changing master or tags at the same time.
4 changes: 3 additions & 1 deletion main/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ async function promptToInstall() {
}

export async function checkForUpdates({notifyIfCurrent = false} = {}) {
if (app.getVersion().includes("-local.")) return;

if (updateReady) {
if (notifyIfCurrent) await promptToInstall();
return;
Expand Down Expand Up @@ -141,7 +143,7 @@ function resumeChecks() {
}

app.whenReady().then(() => {
if (!app.isPackaged) return;
if (!app.isPackaged || app.getVersion().includes("-local.")) return;

scheduleCheck(startupDelay);
powerMonitor.on("resume", resumeChecks);
Expand Down
Loading
Loading