Reusable workflows and actions
github is the source of truth for code AND releases. Get the version/tag/release right on github, then publish to npm based on that.
- work on a feature branch, commiting with conventional-commits
- merge to main
- A push to main produces (if your commits have
fix:orfeat:) a bumped package.json and a tagged github release viagithubRelease - A release cause
npmPublishto run.
creates a github release based on conventional commit prefixes. Using commits like
fix: etc(patch version) andfeat: wow(minor version). A commit whose body (not the title) containsBREAKING CHANGES:will cause the action to update the packageVersion to the next major version, produce a changelog, tag and release.
name: create-github-release
on:
push:
branches: [main]
jobs:
release:
uses: SimplySF/github-workflows/.github/workflows/create-github-release.yml@main
secrets: inherit
# you can also pass in values for the secrets
# secrets:
# PERSONAL_ACCESS_TOKEN: gh_pat00000000main will release to latest. Other branches can create github prereleases and publish to other npm dist tags.
You can create a prerelease one of two ways:
- Create a branch with the
prerelease/**prefix. Exampleprerelease/my-fix- Once a PR is opened, every commit pushed to this branch will create a prerelease
- The default prerelease tag will be
dev. If another tag is desired, manually set it in yourpackage.json. Example:1.2.3-beta.0
- Manually run the
create-github-releaseworkflow in the Actions tab- Click
Run workflow- Select the branch you want to create a prerelease from
- Enter the desired prerelease tag:
dev,beta, etc
- Click
Note
Since conventional commits are used, there is no need to manually remove the prerelease tag from your package.json. Once the PR is merged into main, conventional commits will bump the version as expected (patch for fix:, minor for feat:, etc)
Setup:
- Configure the branch rules for wherever you want to release from
- Modify your release and publish workflows like the following
name: create-github-release
on:
push:
branches:
- main
# point at specific branches, or a naming convention via wildcard
- prerelease/**
tags-ignore:
- '*'
workflow_dispatch:
inputs:
prerelease:
type: string
description: 'Name to use for the prerelease: beta, dev, etc. NOTE: If this is already set in the package.json, it does not need to be passed in here.'
jobs:
release:
uses: SimplySF/github-workflows/.github/workflows/create-github-release.yml@main
secrets: inherit
with:
prerelease: ${{ inputs.prerelease }}
# If this is a push event, we want to skip the release if there are no semantic commits
# However, if this is a manual release (workflow_dispatch), then we want to disable skip-on-empty
# This helps recover from forgetting to add semantic commits ('fix:', 'feat:', etc.)
skip-on-empty: ${{ github.event_name == 'push' }}Write unit tests to tests units of code (a function/method).
Write not-unit-tests to tests larger parts of code (a command) against real environments/APIs.
Run the UT first (faster, less expensive for infrastructure/limits).
name: tests
on:
push:
branches-ignore: [main]
workflow_dispatch:
jobs:
unit-tests:
uses: SimplySF/github-workflows/.github/workflows/unitTest.yml@main
nuts:
needs: unit-tests
uses: SimplySF/github-workflows/.github/workflows/nut.yml@main
secrets: inherit
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
fail-fast: false
with:
os: ${{ matrix.os }}