@immediate_media/semantic-release-gh-actions-config
v1.1.0
Published
A shareable semantic release configuration, designed for use with GitHub Actions.
Maintainers
Keywords
Readme
Semantic Release GH Actions Config
A shareable Semantic Release configuration, designed for use with GitHub Actions.
This repository enforces semantic commit messages. For more details and examples see the Conventional Commits Specification.
Installation
Install the package:
yarn add @immediate_media/semantic-release-gh-actions-config -DInstall semantic-release:
yarn add semantic-release -DUsage
To use the default configuration add the following to your
semantic-release configuration file
(e.g. .releaserc.json):
{
"extends": "@immediate_media/semantic-release-gh-actions-config"
}Alternatively, we can specify options by using a .releaserc.js file:
const { config } = require('@immediate_media/semantic-release-gh-actions-config');
module.exports = config({
gitAssets: [],
githubAssets: [],
})Packages
By default this configuration uses the npm plugin to publish your code as a package.
If you do not want to release your code as a package add "private": true to
your package.json. This can be useful when we have a service (e.g. a website
or API) where we still want to take advantage of the tagging behaviour provided
by semantic release, just not deploy the code as an NPM or GitHub package.
Commit linting
This package is best used alongside commitlint and husky, in order to enforce the required commit message structure.
Install these packages with:
yarn add @commitlint/cli @commitlint/config-conventional husky -DCreate a file at commitlint.config.js with the following contents:
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: { 'body-max-line-length': [0] },
};And a file at .husky/commit-msg with the following contents:
npx --no -- commitlint --edit $1And add a prepare script to your package.json:
npm pkg set scripts.prepare="husky"GitHub Actions
Workflow
A sample GitHub Actions workflow might look something like this:
name: Release
on:
push:
branches:
- main
- canary/*
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install
run: yarn install --frozen-lockfile --non-interactive
- name: Release
run: yarn run semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_DEPLOY_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Output
The configuration sets previous-version and next-version
variables as
GitHub Actions outputs,
which can be useful for defining complex workflows.
