DEV Community

Justin
Justin

Posted on

5 1

Automatically Create a Release When The package.json Version Changes

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay