diff --git a/.github/scripts/release-source.mjs b/.github/scripts/release-source.mjs new file mode 100644 index 0000000..77eaeef --- /dev/null +++ b/.github/scripts/release-source.mjs @@ -0,0 +1,3 @@ +if (process.env.GITHUB_REF !== 'refs/heads/main') { + throw new Error('Publish only from main after the reviewed changes have been merged.'); +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8e377e2..c6a1f77 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,7 @@ name: Publish package on: push: - tags: ['v*'] + branches: [main] workflow_dispatch: permissions: contents: read @@ -24,8 +24,8 @@ jobs: node-version: 24 registry-url: https://registry.npmjs.org package-manager-cache: false - - name: Verify release tag - run: node --input-type=module -e 'import fs from "node:fs"; const p = JSON.parse(fs.readFileSync("package.json")); if (process.env.GITHUB_REF !== `refs/tags/v${p.version}`) throw new Error("Publish from the matching version tag");' + - name: Verify release source + run: node .github/scripts/release-source.mjs - name: Check an existing release id: registry run: node .github/scripts/published.mjs diff --git a/docs/deployment.md b/docs/deployment.md index 9dad714..616f8b8 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -46,7 +46,11 @@ Every list/read/delete includes an account filter. The previous link, token and ## 3. Publish or activate the extension -Deploying the backend does not replace an installed npm package. Publish an appropriately versioned package through the normal release process, or explicitly configure the reviewed local checkout for testing. Do not overwrite a user's package installation or change their settings implicitly. +Deploying the backend does not replace an installed npm package. Merge the reviewed version bump to `main`: the `Publish package` workflow checks and publishes that version automatically. Tags are not required. An already-published version is skipped; manual workflow retries must also target `main`. + +The npm package must authorize GitHub trusted publishing for owner `prjct-app`, repository `pi-sync`, workflow `publish.yml`, without an environment name, and allow direct `npm publish`. The workflow uses OIDC and provenance, not a personal npm login or a stored npm token. GitHub repository access alone does not grant npm publishing permission. + +For local testing, explicitly configure the reviewed checkout. Do not overwrite a user's package installation or change their settings implicitly. The user experience is then only: `/sync` → Back up this machine; on another machine, `/sync` → select the dated backup → Restore → one confirmation. Packages install and Pi reloads automatically. diff --git a/tests/release.test.ts b/tests/release.test.ts new file mode 100644 index 0000000..1b65c76 --- /dev/null +++ b/tests/release.test.ts @@ -0,0 +1,19 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import { test } from 'node:test'; + +const verify = (ref: string) => spawnSync(process.execPath, ['.github/scripts/release-source.mjs'], { + env: { ...process.env, GITHUB_REF: ref }, encoding: 'utf8', +}); + +test('publication accepts the main branch used after a merge', () => { + assert.equal(verify('refs/heads/main').status, 0); +}); + +test('publication rejects tags, feature branches, pull requests, and missing refs', () => { + for (const ref of ['refs/tags/v0.3.0', 'refs/heads/feature', 'refs/pull/1/merge', '']) { + const result = verify(ref); + assert.notEqual(result.status, 0); + assert.match(result.stderr, /Publish only from main/); + } +});