パッケージの詳細

@sanity/semantic-release-preset

sanity-io6kMIT5.0.0

Recommended setup for releasing semantically using GitHub Actions workflows

.releaserc.json, automation, changelog, conventional-changelog

readme

@sanity/semantic-release-preset

npm (scoped) Lint CI

Features

Table of contents

Usage

npm i -D @sanity/semantic-release-preset

If your package manager don't auto install peer dependencies make sure to install semantic-release:

npm i -D semantic-release

Setup the release config

Create a .releaserc.json:

{
  "extends": "@sanity/semantic-release-preset",
  "branches": ["main"]
}

The branches array is mandatory, and in most repositories you should put the default git branch here (main, or master if it's an older repository).

Optional: Configure prerelease branches

If you have stable releases going out from the git branch main, and want commits on the branch beta to result in only being installable with the npm dist-tag beta:

npm i package-name@beta

But not on:

npm i package-name # or npm i package-name@latest

Then use this config:

{
  "extends": "@sanity/semantic-release-preset",
  "branches": ["main", {"name": "beta", "prerelease": true}]
}

Minimal GitHub Release workflow

This is the bare minimum required steps to trigger a new release. This will push a new release every time an eliglible commit is pushed to git. Check the opinionated flow to see how to trigger releases manually. Create .github/workflows/ci.yml:

---
name: CI

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          # Need to fetch entire commit history to
          # analyze every commit since last release
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          cache: npm
          node-version: lts/*
      - run: npm ci
      - run: npm test --if-present
      # Branches that will release new versions are defined in .releaserc.json
      # @TODO uncomment after verifying with --dry-run we're ready to go
      # - run: npx semantic-release
      - run: npx semantic-release --dry-run
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

It's important that you use --dry-run in the npx semantic-release command until you've verified that semantic-release is setup correctly and is able to detect your release branches and published version numbers. If you don't you may accidentally release a wrong version on npm, know that you can't simply unpublish accidents so it's best to be safe.

You need two secrets, secrets.GITHUB_TOKEN is always provided to GitHub actions, but if you try to --dry-run locally you'll need to create a token. It's easiest to just push commits and inspect the workflow output. You can add --debug to the npx semantic-release command to see more verbose logs if there's a tricky error.

The secrets.NPM_PUBLISH_TOKEN is provided on our GitHub org. If you're outside it you'll need to create it with auth-only 2FA and add it to the repository secrets.

If you're unable to make it work chances are your issue is documented in the semantic-release troubleshooting docs

Once you've confirmed with --dry-run that everything is looking good and semantic-release will perform the actions you expect it to, go ahead and edit .github/workflows/release.yml:

---
name: CI

on:
  # Build on pushes branches that have a PR (including drafts)
  pull_request:
  # Build on commits pushed to branches without a PR if it's in the allowlist
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          # Need to fetch entire commit history to
          # analyze every commit since last release
          fetch-depth: 0
      - uses: actions/setup-node@v3
        with:
          cache: npm
          node-version: lts/*
      - run: npm ci
      - run: npm test --if-present
      # Branches that will release new versions are defined in .releaserc.json
      - run: npx semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

If this is on a brand new package that haven't published to npm yet, make a commit like this:

git add .github/workflows/release.yml
git commit -m "feat: initial release"
git push

If you're onboarding a package that already has a published version history:

git add .github/workflows/release.yml
git commit -m "fix: use semantic-release"
git push

Check the Release Workflow docs for more information.

Opinionated GitHub Release workflow

  1. This flow runs a build task for linting and things that only need to run once.
  2. Runs test, which runs a matrix of operating systems and Node.js versions.
  3. FInally, runs release, if the workflow started from a workflow_dispatch, it is skipped on push.

TODO more docs are coming, we're actively exploring the optimal setup

Next steps, for even more automation

更新履歴

📓 Changelog

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

5.0.0 (2024-06-10)

⚠ BREAKING CHANGES

  • require semantic-release v24 (#128)

Bug Fixes

4.1.8 (2024-06-03)

Bug Fixes

  • deps: update dependency conventional-changelog-conventionalcommits to v8 (#124) (1dfce8e)
  • deps: update dependency semantic-release to v24 (#126) (e6e5594)
  • deps: update non-major (#118) (9a6695d)

4.1.7 (2024-02-26)

Bug Fixes

  • deps: update dependency semantic-release to v23 (#112) (b475f0b)

4.1.6 (2023-10-24)

Bug Fixes

  • deps: update dependency semantic-release to v22 (e67b045)

4.1.5 (2023-10-23)

Bug Fixes

  • deps: Update dependency conventional-changelog-conventionalcommits to v7 (#104) (2614d5c)
  • deps: update dependency semantic-release to v22 (#106) (0439f36)

4.1.4 (2023-08-24)

Bug Fixes

  • add provenance (cf35960)
  • turn off success comments for now (ebf2846)
  • use tagFormat for monorepos (81edfff)

4.1.3 (2023-08-07)

Bug Fixes

  • turn successComment on github release back on (5660189)

4.1.2 (2023-07-13)

Bug Fixes

  • deps: update dependency conventional-changelog-conventionalcommits to v6 (#90) (0d58fdb)
  • deps: update non-major (#92) (3397e42)

4.1.1 (2023-04-12)

Bug Fixes

4.1.0 (2023-03-26)

Features

  • deps: update dependency semantic-release to v21 (#74) (35024d4)

4.0.2 (2023-03-20)

Bug Fixes

4.0.1 (2023-03-20)

Bug Fixes

  • deps: update dependency semantic-release-license to ^1.0.3 (#71) (286960d)
  • deps: update semantic-release monorepo (6f2956e)
  • make prettier PRs (fe45bd9)

4.0.0 (2023-01-20)

⚠ BREAKING CHANGES

  • if your package manager don't auto install peers add semantic-release manually: npm install --save-dev semantic-release

Code Refactoring

  • semantic-release is now a peer dep (bcc84e7)

3.0.2 (2023-01-08)

Bug Fixes

  • deps: update dependency semantic-release to v20.0.2 (#48) (3a9554d)

3.0.1 (2023-01-08)

Bug Fixes

  • deps: update dependency semantic-release to v20.0.1 (#47) (c46e5a3)

3.0.0 (2023-01-07)

⚠ BREAKING CHANGES

  • deps: Drops support for Node v16 and older

Bug Fixes

  • deps: update dependency semantic-release to v20 (#40) (8dd50d9)

2.0.5 (2023-01-01)

Bug Fixes

2.0.4 (2022-12-16)

Bug Fixes

2.0.3 (2022-12-06)

Bug Fixes

  • deps: update dependency @semantic-release/changelog to ^6.0.2 (1d53742)

2.0.2 (2022-10-06)

Bug Fixes

  • update readme CI example (1e8a5a2)

2.0.1 (2022-08-24)

Bug Fixes

  • deps: update dependency semantic-release to ^19.0.5 (3479eae)

2.0.0 (2022-08-17)

⚠ BREAKING CHANGES

  • this preset used the angular commit convention previously, from now on it's conventional commits so we match our commitlint and other semantic release setups.

Features

  • switch to conventional commits (#9) (195fdcf)

Bug Fixes

  • add note in TODO about docs (0b6ecdc)

1.1.4 (2022-08-17)

Bug Fixes

1.1.3 (2022-08-17)

Bug Fixes

  • changelog title formatting (b87a365)

1.1.2 (2022-08-17)

Bug Fixes

  • run prettier on changelog (0191f99)

1.1.1 (2022-08-17)

Bug Fixes

  • disable markdownlint in changelog (76b81f2)

1.1.0 (2022-08-17)

Features

  • add semantic-release-license (#6) (588fa26)

1.0.3 (2022-08-17)

Bug Fixes

  • deps: update dependency semantic-release to ^19.0.3 (287d8d0)

1.0.2 (2022-08-17)

Bug Fixes

  • no release commit body to pass commitlint (4e29fc5)

1.0.1 (2022-08-16)

Bug Fixes

  • README: add link to gitlab preset (329fa8c)

1.0.0 (2022-08-16)

Features