Automated Package Publishing with GitHub Actions

You received a pull-request. You're grateful, but you need to release a new version.

by Ray Zane

You received a pull-request. You're grateful, but sigh... now you need to release a new version.

Here are all of the things you're supposed to do:

  1. Clone the repository.
  2. Run the tests one last time. Try not to forget this step!
  3. Bump and commit a version change.
  4. Create a new git tag.
  5. Create a new GitHub Release describing what changed.

This is a bit of a chore, so I wanted to automate this entire process with GitHub Actions.

But first, a few notes about my ideal solution:

  • I want publishing a release to be a single step.
  • I want this solution to be language agnostic, because I maintain packages in a few different languages.
  • I don't want to use structured commit messages.

The Workflow

Without further ado, this is the workflow that I came up with. It lives in .github/workflows/action.yml.

name: Publish
    types: [published]
    runs-on: ubuntu-latest
      - name: Checkout
        uses: actions/[email protected]

      - name: Setup Node.js
        uses: actions/setup-[email protected]
          node-version: 12

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Test
        run: yarn test --ci --coverage

      - name: Version
        run: yarn version --new-version "${GITHUB_REF:11}" --no-git-tag-version

      - name: Publish
        run: yarn publish --access public
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Now, creating a release is as simple as creating a new GitHub release:


Most open source projects commit their current version to a source file. With this automated workflow, I'd recommend not doing that.

Instead, just set your version to 0.0.0. Then, when you build your package, set the version based on the current git tag.

In the example above, $GITHUB_REF will reflect the git tag associated with your GitHub Release:

$ echo "$GITHUB_REF"

You can extract the version number from this git tag like so:

$ echo "${GITHUB_REF:11}"

For NPM packages, you can set the version using the following command:

$ yarn version --new-version "${GITHUB_REF:11}" --no-git-tag-version

But, for other types of packages, a find and replace should do the trick:

$ perl -pe -i "s/0\.0\.0/${GITHUB_REF:11}/" lib/mylib/version.rb


The "Publish" step will vary based on your language. GitHub provides a few examples for this step:

Good luck and keep releasing!

We'd love to keep in touch!

Opt in for occasional updates from us. Privacy Policy