changesets / action

653 stars 230 forks source link

Custom Pull request title with tag version #303

Open AdisonCavani opened 1 year ago

AdisonCavani commented 1 year ago

I'd like to get a customized Pull request title / commit message like this: release: v0.0.1.

I know there is ability to customize the title:

      - name: Changesets PR or publish
        uses: changesets/action@v1
        with:
          title: My Custom PR title

But I want to also get a tag name, so the naming in more specific. Is this possible?

denizdogan commented 1 year ago

Did you figure this out? I'm looking for the same thing.

lakardion commented 11 months ago

I would love to know as well how I can add the version to the PR title

r115 commented 9 months ago

I have a customized hack for it. There is a PR somewhere here for adding a --dry-run flag which should solve this. Anyway, here's my hack;

Context

Steps

Create helper file at project root

release-helper.js

const config = require('./release.json');
const {unlink} = require('fs')

const commit_message = `v${config.releases[0].newVersion} of ${config.releases[0].name}`
unlink('./release.json', () => {})

console.log(commit_message)

Add a step to generate changeset

steps:
  ...
  - name: Prep commit message
     id: prep_commit_message
     run: |
       MESSAGE=$(pnpm changeset status --output=./release.json && node release-helper.js | tail -n 1)
       echo "message=${MESSAGE}" >> $GITHUB_OUTPUT

profit

steps:
  ...
  - name: Create Release Pull Request
     uses: changesets/action@v1
     with:
       title: ${{ steps.prep_commit_message.outputs.message }}
       commit: "release version ${{ steps.prep_commit_message.outputs.message }}"
     env:
       GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This stuff can possibly be knocked out with a one liner using jq. Just didn't want to jump through the hoops until the solution works over some time.

hollandjake commented 7 months ago

Incase you are ever interested in the jq version - @r115

It creates a release.json file temporarily extracts the version using jq and then removes the file (this is due to an outstanding feature request https://github.com/changesets/changesets/issues/1020)

steps:
  ...
  - name: Prep commit message
    run: |
      echo "NEW_VERSION=$(pnpm changeset status --output=release.json && jq -r '.releases[0].newVersion' release.json && rm release.json)" >> "$GITHUB_ENV"
  - name: Create Release Pull Request or Publish
    id: changesets
    uses: changesets/action@v1
    with:
      title: "Release v${{env.NEW_VERSION}}"
      commit: "Release v${{env.NEW_VERSION}}"
      publish: pnpm run release
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
dcroote commented 6 months ago

@hollandjake this is excellent, thanks