loading...

Automatically Create a Release When The package.json Version Changes

justincy profile image Justin ・1 min read

My Workflow

Automatic GitHub Release: Automatically generate a release when the package.json version changes.

It's currently being used to manage releases of itself. I created it to help manage releases of some private packages I'm working on.

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code

GitHub logo justincy / github-action-npm-release

Automatically generate a release when the package.json version changes

Automatic GitHub Release

Automatically generate a release when the package.json version changes. The release name and tag will match the new version. If no releases yet exist, this action will create the first release.

The release notes will contain a change log generated from git history in the following format:

- f0d91bd Making progress
- 275e3e2 Initial commit

Assumptions

This action makes a few assumptions:

  • actions/checkout@v2 with fetch-depth: 0 is used before this action runs. That allows this action to have all the information it needs to generate the change log from the git history.
  • You are only releasing from one branch
  • It is only used during push

Usage Example

name: Release
on
  push
    branches
      - master
jobs:
  build:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Release
        uses

Additional Resources / Info

What I learned:

  • Debugging is rough. act makes it easier but it's not a perfect solution.
  • The first gotcha I ran into was that steps need an ID in order to reference their output. For some reason can't reference steps by their name.
  • Actions can't depend on other actions. My original plan was to create a few small actions and stitch them together into a larger composite action but it's not possible.
  • Use @actions/core, even if you think your script will be small. It makes input, output, errors, etc much easier. Chances are your script will become quite a bit more complex when you start handling errors.
  • You must bundle all code that your actions needs, including dependencies. The best solution is to use @vercel/ncc.

Posted on by:

Discussion

pic
Editor guide