diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9f83a07 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +# Dependabot opens a pull request when a dependency or an action has a new +# version, and right away when one has a security fix. +version: 2 +updates: + - package-ecosystem: npm + directory: / + schedule: + interval: weekly + groups: + # One pull request for the tools the library is built and tested with. + development: + dependency-type: development + # A change to a runtime dependency gets a pull request of its own. + open-pull-requests-limit: 5 + ignore: + # Node's types follow the Node in .node-version, not the newest one. + - dependency-name: "@types/node" + update-types: ["version-update:semver-major"] + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5aedcfe..ce39c18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,11 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: .node-version cache: pnpm @@ -43,15 +45,17 @@ jobs: matrix: node: ["22.12", "24"] steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: .node-version cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm build - - uses: actions/setup-node@v7 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node }} - run: node --version diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ac80585..603cbb2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,42 +1,92 @@ -# Publishes to npm when a version tag (v1.3.1) is pushed. npm's trusted +# Publishes to npm when a version tag (v1.0.0) is pushed. npm's trusted # publishing authenticates this workflow through OIDC, so no token is stored, # and the package gets a provenance statement. The package's trusted # publisher on npmjs.com must name this repository and this file. +# +# Three jobs, each with only the permission it needs: the one that runs the +# toolchain (the build, the lint, the tests) can neither publish nor write to +# the repository, and the one that can publish runs no code of the project's. name: Publish on: push: tags: ["v*"] -permissions: - # contents: write lets the job create the GitHub release. - contents: write - id-token: write +permissions: {} jobs: - publish: - name: Publish to npm + build: + name: Check and pack runs-on: ubuntu-latest timeout-minutes: 10 + permissions: + contents: read steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # The whole history, to see that the tag is on main. + fetch-depth: 0 + persist-credentials: false + - name: Check the tag is a commit of main + run: git merge-base --is-ancestor "$GITHUB_SHA" origin/main + - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: .node-version - registry-url: https://registry.npmjs.org cache: pnpm - run: pnpm install --frozen-lockfile - name: Check the tag matches the package version run: test "v$(node -p 'require("./package.json").version')" = "$GITHUB_REF_NAME" - # prepublishOnly runs every check, the tests, the build and the - # package checks first. - - run: npm publish - - name: Create the GitHub release from the changelog - env: - GH_TOKEN: ${{ github.token }} + # Every check, the tests, the build and the package checks. + - run: pnpm run prepublishOnly + - run: pnpm pack --pack-destination release + - name: Take the release notes from the changelog run: | version="${GITHUB_REF_NAME#v}" - awk -v heading="## ${version}" '$0 == heading { found = 1; next } found && /^## / { exit } found { print }' CHANGELOG.md > notes.md - test -s notes.md - gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes-file notes.md + awk -v heading="## ${version}" '$0 == heading { found = 1; next } found && /^## / { exit } found { print }' CHANGELOG.md > release/notes.md + test -s release/notes.md + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: release + path: release + if-no-files-found: error + + publish: + name: Publish to npm + needs: build + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + # For npm's trusted publishing, and nothing else. + id-token: write + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: release + path: release + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + # The tarball the first job packed, as it is: no script of the + # package's runs here. + # The path starts with ./ so npm reads it as a file: "release/x.tgz" + # alone is its shorthand for a GitHub repository. + - run: npm publish ./release/*.tgz --ignore-scripts + + release: + name: Create the GitHub release + needs: publish + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: release + path: release + - env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes-file release/notes.md diff --git a/AGENTS.md b/AGENTS.md index ecbbad2..c252e2a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,4 +26,4 @@ Every change reaches `main` through a pull request, merged with a squash once CI ## Releases -Bump `version` in `package.json` and add its entry to `CHANGELOG.md`, then push a `vX.Y.Z` tag that matches. `.github/workflows/publish.yml` publishes it with npm's trusted publishing and a provenance statement; no token is stored anywhere. A breaking change to what any function accepts is a major version. +Bump `version` in `package.json` and add its entry to `CHANGELOG.md`, then push a `vX.Y.Z` tag that matches. `.github/workflows/publish.yml` publishes it with npm's trusted publishing and a provenance statement; no token is stored anywhere. The workflow has three jobs with one permission each: the job that runs the toolchain can't publish, and the job that publishes runs none of the project's code. Every action in a workflow is pinned to a full commit SHA, with its version in a comment; Dependabot moves them. A breaking change to what any function accepts is a major version.