GitHub Action
Node Draft Releaser
Automatically publish an existing Draft Release when the "package.json"
version changes.
This Action pairs exquisitely well with Release Drafter.
It is also a great addition to any workflows that culminate in publishing a Node package to an NPM Registry such as the GitHub Package Registry.
In addition to a handful of the standard environment variables provided during a GitHub Actions workflow run, this Action also expects the following Secret(s) to be provided:
GITHUB_TOKEN
(required)- The
GITHUB_TOKEN
Secret is a GitHub App installation token scoped to a repository. GitHub creates theGITHUB_TOKEN
secret for you by default, but you must include it in your workflow file in order for this Action to use it.
- The
This Action can react to the following inputs:
allow_unmatched_draft_tag
(optional)- Should this Action be allowed to publish an existing Draft Release that is not slated to create a Tag matching the new version number?
- Valid values:
'true'
or'false'
(as a string) - Defaults to
'true'
.
This Action provides the following outputs:
-
version
- The new version number that was released, e.g.
1.0.0-beta.2
- The new version number that was released, e.g.
-
release_id
- The ID of the Release
-
release_url
- The URL to view the published Release page in the GitHub UI
In one of your GitHub Actions V2 workflow YAML files:
name: 'Publish Draft Release'
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
# file paths to consider in the event; optional, defaults to all
paths:
- package.json
jobs:
publish_draft_release_on_version_bump:
runs-on: ubuntu-latest
steps:
# Does a checkout of your repository at the pushed commit SHA
- uses: actions/checkout@v1
# Checks for a version bump to publish an existing Draft Release
- uses: JamesMGreene/node-draft-releaser@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
allow_unmatched_draft_tag: 'false' # default value = 'true'
Setting up your GitHub Actions workflow to also use Release Drafter is a great combination with this Action! 💪
IMPORTANT: To enable Release Drafter, you must also include a .github/release-drafter.yml
configuration file in your repository.
name: 'Draft Releases & Release Drafts'
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
jobs:
update_draft_release:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: toolmantim/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish_draft_release_on_version_bump:
needs: [update_draft_release]
runs-on: ubuntu-latest
steps:
# Does a checkout of your repository at the pushed commit SHA
- uses: actions/checkout@v1
# Checks for a version bump to publish an existing Draft Release
- id: github_release
uses: JamesMGreene/node-draft-releaser@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Show the Release URL, just for fun
- run: echo "Released at $RELEASE_URL"
env:
RELEASE_URL: ${{ steps.github_release.outputs.release_url }}
Another great chaining opportunity is following this Action with one to publish the new version to the GitHub Package Registry.
name: 'Release Management'
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
jobs:
update_draft_release:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: toolmantim/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish_draft_release_on_version_bump:
needs: [update_draft_release]
runs-on: ubuntu-latest
steps:
# Does a checkout of your repository at the pushed commit SHA
- uses: actions/checkout@v1
# Checks for a version bump to publish an existing Draft Release
- id: github_release
uses: JamesMGreene/node-draft-releaser@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Show the Release URL, just for fun
- run: echo "Released at $RELEASE_URL"
env:
RELEASE_URL: ${{ steps.github_release.outputs.release_url }}
publish_package_to_gpr:
needs: [publish_draft_release_on_version_bump]
runs-on: ubuntu-latest
steps:
# Does a checkout of your repository at the pushed commit SHA
- uses: actions/checkout@v1
# Set up the local Node environment for the NPM CLI
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
# Install dependencies in case there are any publish-related scripts
- run: npm install
# Publish the new version to GPR
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MIT License (c) 2019 James M. Greene