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
15 changes: 11 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ jobs:
- name: Validate package
run: npm run check

- name: Verify release tag matches package version
- name: Derive package version from release tag
id: version
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
shell: bash
run: |
package_version="$(node --print 'require("./package.json").version')"
if [[ "$GITHUB_REF_NAME" != "v$package_version" ]]; then
echo "Release tag $GITHUB_REF_NAME does not match package version $package_version" >&2
set -euo pipefail
if [[ ! "$RELEASE_TAG" =~ ^v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)$ ]]; then
echo "Release tag $RELEASE_TAG is not of the form v<semver>" >&2
exit 1
fi
echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"

- name: Verify build did not modify the checkout
shell: bash
Expand All @@ -51,13 +55,16 @@ jobs:

- name: Create immutable package artifact from committed source
id: package
env:
PACKAGE_VERSION: ${{ steps.version.outputs.version }}
shell: bash
run: |
set -euo pipefail
package_dir="$RUNNER_TEMP/package-source"
mkdir -p "$package_dir"
git archive "$GITHUB_SHA" | tar -x -C "$package_dir"
cd "$package_dir"
npm version "$PACKAGE_VERSION" --no-git-tag-version --allow-same-version --ignore-scripts
npm pack --ignore-scripts --json > npm-pack.json
package_file="$(node --input-type=module -e '
import { readFileSync } from "node:fs";
Expand Down
14 changes: 4 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,10 @@ Use `npm install` when adding, removing, or upgrading dependencies, and commit b

Releases are published to npm through GitHub Actions and npm trusted publishing.

1. Update `package.json` and `package-lock.json` together:

```bash
npm version <version> --no-git-tag-version
```

2. Open and merge the version pull request after CI passes.
3. Publish a GitHub Release whose tag exactly matches `v<version>`.
4. Verify the `Publish to npm` workflow succeeds.
5. Verify the published version and distribution tags:
1. Publish a GitHub Release whose tag is `v<version>` (for example `v0.7.0` or `v1.0.0-rc.1`). The tag must be valid semver with a `v` prefix.
2. The `Publish to npm` workflow takes the version from the tag and writes it into the packaged `package.json`, so you do not need a version bump pull request. The `version` in the repository's `package.json` is not used for publishing.
3. Verify the `Publish to npm` workflow succeeds.
4. Verify the published version and distribution tags:

```bash
npm view @mozilla-ai/pi-otari version dist-tags --json
Expand Down
Loading