Skip to content

Instantly share code, notes, and snippets.

@TClark1011
Last active January 27, 2022 08:08
Show Gist options
  • Select an option

  • Save TClark1011/a797c5c12f83e08004603895ac3d3158 to your computer and use it in GitHub Desktop.

Select an option

Save TClark1011/a797c5c12f83e08004603895ac3d3158 to your computer and use it in GitHub Desktop.
CI (JS/TS) - Auto Versioning/Release CI Workflow

Auto Versioning/Release CI Workflow

This workflow uses standard-version to automatically handle version bumping and changelog generation.

Installation

  • Put release.yaml inside .github/workflows/
  • (Optional) If you want to be able to manually set what type of release will be performed create the following labels (as in the labels that can be applied to issues and PRs) in your repo:
    • force-release:patch
    • force-release:minor
    • force-release:major
    • force-release:none

Adaptations

You may want to/be required to make adaptations to this workflow based on the following:

  • yarn: This workflow uses yarn, you may want to change it to use a different package manager
  • npx: We use npx to run the standard-version script without having to install it. If you want you can instead choose to install it as a dev dependency and run it like that
  • credentials: Currently this workflow configures git to use my email thomassiclark@gmail.com when committing and pushing the changes made by it. You may want to change this to use a different email address.
name: release
on:
pull_request:
types:
- closed
branches:
- main
jobs:
release:
if: github.event.pull_request.merged == true && !contains(github.event.pull_request.labels.*.name, 'force-release:none')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- run: git config --global user.email "thomassiclark@gmail.com"
- run: git config --global user.name "version bot"
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: yarn install
- run: npx standard-version
if: "!contains(github.event.pull_request.labels.*.name, 'force-release:patch') && !contains(github.event.pull_request.labels.*.name, 'force-release:minor') && !contains(github.event.pull_request.labels.*.name, 'force-release:major')"
- run: npx standard-version --release-as patch
if: "contains(github.event.pull_request.labels.*.name, 'force-release:patch')"
- run: npx standard-version --release-as minor
if: "contains(github.event.pull_request.labels.*.name, 'force-release:minor')"
- run: npx standard-version --release-as major
if: "contains(github.event.pull_request.labels.*.name, 'force-release:major')"
- run: git push --follow-tags origin main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment