name: release-app # The normal way to release is to start this workflow by hand (`plan2code-publish` does it) with # the version and the release notes. It builds first and creates the release LAST, so the vX.Y.Z # tag, which is what the app's update check looks for, only appears once every file is attached # and nobody is offered an upgrade that has no binary yet. A release published by hand, or a v* # tag pushed ahead of one, still starts it as a fallback; the tag then exists before the files. # # Builds the desktop app on four systems and attaches one file per system, named # plan2code-app---[.exe], plus one checksum file # (plan2code-app--SHA256SUMS.txt). install.js fetches the matching file and checks it # against that list. Linux ships the plain binary, not an AppImage: docs/desktop-app.md documents # its WebKitGTK 4.1 dependency instead. The app is not code-signed: docs/desktop-app.md says # how to allow it. on: workflow_dispatch: inputs: version: description: 'Version to release, without the v (it must match CHANGELOG.md, version.json and package.json)' required: true type: string title: description: 'Release title (defaults to the tag)' required: false type: string notes: description: 'Release notes (Markdown)' required: false type: string release: types: [published] push: tags: ['v*'] # Read-only by default: the build jobs run dependency install scripts and build scripts, so # only the publish job holds a write token. permissions: contents: read # A release published after its tag push starts a second run for the same tag: queue it behind # the first so two builds never upload over each other. concurrency: group: release-app-${{ github.event.release.tag_name || (inputs.version && format('v{0}', inputs.version)) || github.ref_name }} cancel-in-progress: false env: # The release tag: the published release's, the version a manual run was given, or the pushed tag. TAG: ${{ github.event.release.tag_name || (inputs.version && format('v{0}', inputs.version)) || github.ref_name }} jobs: build: name: build (${{ matrix.label }}) runs-on: ${{ matrix.runner }} strategy: fail-fast: false matrix: include: - { runner: windows-latest, label: windows-x64, built: plan2code-app.exe, suffix: .exe } - { runner: macos-latest, label: macos-arm64, built: plan2code-app, suffix: '' } - { runner: macos-15-intel, label: macos-x64, built: plan2code-app, suffix: '' } - { runner: ubuntu-latest, label: linux-x64, built: plan2code-app, suffix: '' } defaults: run: shell: bash steps: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - uses: actions/setup-node@v7.1.0 with: node-version: 22 cache: npm cache-dependency-path: plan2code-app/package-lock.json - name: Check the versions agree with the release tag run: node scripts/check-versions.mjs --tag "$TAG" - name: Install the pinned Rust toolchain working-directory: plan2code-app run: rustup toolchain install "$(grep channel rust-toolchain.toml | cut -d '"' -f2)" --profile minimal - name: Cache the Cargo registry and build output uses: actions/cache@v6.1.0 with: path: | ~/.cargo/registry ~/.cargo/git plan2code-app/target key: cargo-release-${{ matrix.label }}-${{ hashFiles('plan2code-app/Cargo.lock') }} restore-keys: | cargo-release-${{ matrix.label }}- - name: Name this week for the apt cache if: runner.os == 'Linux' id: week run: echo "week=$(date +%G-%V)" >> "$GITHUB_OUTPUT" - name: Cache the Linux system packages # Keep the downloaded .deb files (the WebKit packages are hundreds of MB, and the runner's # mirror is sometimes slow), as app.yml does. The key rolls over weekly. if: runner.os == 'Linux' uses: actions/cache@v6.1.0 with: path: ~/apt-archives key: apt-tauri-release-${{ runner.os }}-${{ steps.week.outputs.week }} restore-keys: | apt-tauri-release-${{ runner.os }}- - name: Install Linux system packages if: runner.os == 'Linux' run: | mkdir -p "$HOME/apt-archives/partial" sudo apt-get update sudo apt-get -o Dir::Cache::archives="$HOME/apt-archives" install -y libwebkit2gtk-4.1-dev build-essential libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev # apt ran as root: hand the folder back so the cache step can read and save it. sudo chown -R "$(id -u):$(id -g)" "$HOME/apt-archives" - name: Install the app's packages working-directory: plan2code-app run: npm ci # One plain executable per system: the web page is built into it, so it needs no installer. - name: Build working-directory: plan2code-app run: npm run tauri -- build --no-bundle - name: Name the file run: | VERSION="$(node -p "require('./plan2code-app/src-tauri/tauri.conf.json').version")" mkdir -p dist cp "plan2code-app/target/release/${{ matrix.built }}" "dist/plan2code-app-${VERSION}-${{ matrix.label }}${{ matrix.suffix }}" - uses: actions/upload-artifact@v7.0.2 with: name: app-${{ matrix.label }} path: dist/* if-no-files-found: error publish: name: attach to the release needs: build runs-on: ubuntu-latest permissions: contents: write env: GH_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - uses: actions/download-artifact@v8.0.2 with: path: dist pattern: app-* merge-multiple: true - name: Verify every system's file is here run: | VERSION="$(node -p "require('./plan2code-app/src-tauri/tauri.conf.json').version")" cd dist missing=0 for name in "plan2code-app-${VERSION}-windows-x64.exe" "plan2code-app-${VERSION}-macos-arm64" "plan2code-app-${VERSION}-macos-x64" "plan2code-app-${VERSION}-linux-x64"; do if [ ! -f "$name" ]; then echo "::error::missing release asset $name" missing=1 fi done [ "$missing" -eq 0 ] - name: Write the checksum file run: | VERSION="$(node -p "require('./plan2code-app/src-tauri/tauri.conf.json').version")" cd dist sha256sum plan2code-app-* > "plan2code-app-${VERSION}-SHA256SUMS.txt" cat "plan2code-app-${VERSION}-SHA256SUMS.txt" - name: Attach to the release, creating it last env: RELEASE_TITLE: ${{ inputs.title }} RELEASE_NOTES: ${{ inputs.notes }} # No release yet (a manual run, or a bare tag push): create it as a DRAFT with every file # attached, then publish it, so the tag appears only when the files are already there. # A release that already exists (published by hand) just gets the files. A draft left # by an earlier failed run is reused. Releases made with the workflow's own token do not # start another run. run: | state="$(gh release list --limit 100 --json tagName,isDraft -q ".[] | select(.tagName==\"$TAG\") | .isDraft")" if [ -z "$state" ]; then notes_file="$(mktemp)" if [ -n "$RELEASE_NOTES" ]; then printf '%s' "$RELEASE_NOTES" > "$notes_file" notes_args=(--notes-file "$notes_file") else notes_args=(--generate-notes) fi gh release create "$TAG" dist/* --draft --target "$GITHUB_SHA" --title "${RELEASE_TITLE:-$TAG}" "${notes_args[@]}" state=true else gh release upload "$TAG" dist/* --clobber fi if [ "$state" = "true" ]; then gh release edit "$TAG" --draft=false fi - name: Publish the slim install refs # The README's first install is `npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git#release`, so new users # get the newest release and never a half-finished main, and exact updates fetch the # immutable `install-vX.Y.Z` tag. scripts/publish-install-refs.mjs builds one synthetic # commit holding only the runtime payload (install.js, package.json, version.json, LICENSE, NOTICE, src/) # and a manifest binding it to this tag, then pushes it to both refs in one atomic push. # Last step, after the release is public: a failure earlier leaves both refs on the # previous release. Fast-forward only (no --force), and an existing install tag is never # overwritten, so a bad run fails loudly instead of rewinding what people install. env: GIT_AUTHOR_NAME: github-actions[bot] GIT_AUTHOR_EMAIL: 41898099+github-actions[bot]@users.noreply.github.com GIT_COMMITTER_NAME: github-actions[bot] GIT_COMMITTER_EMAIL: 41898099+github-actions[bot]@users.noreply.github.com run: | # The push authenticates with the workflow token through an askpass helper: the helper # script contains no secret, the token itself stays only in this step's process # environment, and actions/checkout does not persist it into .git/config. cat > "$RUNNER_TEMP/p2c-git-askpass.sh" <<'EOF' #!/bin/sh case "$1" in *Username*) printf '%s\n' x-access-token ;; *) printf '%s\n' "$GH_TOKEN" ;; esac EOF chmod +x "$RUNNER_TEMP/p2c-git-askpass.sh" export GIT_ASKPASS="$RUNNER_TEMP/p2c-git-askpass.sh" export GIT_TERMINAL_PROMPT=0 export GCM_INTERACTIVE=never git config credential.helper "" git config credential.username x-access-token # The checkout is shallow, and the publisher needs the release branch's old tip as the # new commit's parent and to check the move is a fast-forward. if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then git fetch --no-tags --unshallow origin fi git fetch --no-tags origin "refs/tags/${TAG}:refs/tags/${TAG}" if git ls-remote --exit-code --heads origin release > /dev/null; then git fetch --no-tags origin "+refs/heads/release:refs/remotes/origin/release" fi # The release branch already exists. A fork or first migration without one # intentionally fails here rather than guessing; bootstrap it locally with the # publisher's explicit --allow-missing-release-branch. node scripts/publish-install-refs.mjs --tag "$TAG" --repo "$GITHUB_WORKSPACE"