Skip to content

Release Only on New Commits ​

In scheduled CI jobs (such as daily or weekly automatic releases) or path-triggered pipelines, when there are no new commits since the last release you usually do not want to publish an empty version, and you do not want the CI job to show a red failure because there are "no new commits".

Basic Configuration ​

Enable git.requireCommits in release.config.ts and set git.requireCommitsFail to false:

ts
import { defineConfig } from '@neosjs/release'

export default defineConfig({
  git: {
    requireCommits: true,
    requireCommitsFail: false
  }
})

What happens when it runs:

  • During the git.init stage, the tool runs git rev-list <latestTag>..HEAD --count to count the new commits.
  • When the number of new commits is greater than 0, the release flow proceeds as usual.
  • When the number of new commits is 0:
    • The initialization of the remaining plugins and all release steps are aborted.
    • It prints "Nothing to release / No new commits, nothing to release!".
    • The process exits normally with exit code 0, so the CI job stays green.

If you would rather have the script fail and stop (exit code 1) when there are no new commits, keep the default git.requireCommitsFail: true.

Watching Only a Specific Directory (git.commitsPath) ​

If you care only about changes in the core code directory (for example, changes to documentation or configuration files should not trigger a release), use git.commitsPath to specify the path to count:

ts
import { defineConfig } from '@neosjs/release'

export default defineConfig({
  git: {
    requireCommits: true,
    requireCommitsFail: false,
    commitsPath: 'src'
  }
})

The count command then becomes the equivalent of git rev-list <latestTag>..HEAD --count -- src: the release proceeds only when there are new commits under the src/ directory.

Scheduled GitHub Actions Example ​

yaml
name: Scheduled Release

on:
  schedule:
    # Check whether a release is needed every Monday at 02:00 UTC
    - cron: '0 2 * * 1'
  workflow_dispatch:

permissions:
  contents: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm
          registry-url: https://registry.npmjs.org
      - run: pnpm install --frozen-lockfile
      - name: Release if there are new commits
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          pnpm release --ci --git.requireCommits --no-git.requireCommitsFail --npm.publish --github.release