README
Semantic-release shareable configuration
Semantic-release shareable configuration to publish GitHub projects.
Daniel Bannert's open source work is supported by the community on GitHub Sponsors
Install
npm install --dev-save @anolilab/semantic-release-preset
Plugins
This shareable configuration uses the following plugins:
- @semantic-release/changelog
- @semantic-release/commit-analyzer
- @semantic-release/exec
- @semantic-release/git
- @semantic-release/github
- @semantic-release/npm (optional)
- @semantic-release/release-notes-generator
Summary
This shareable configuration performs the following actions:
- Analyze commits (@semantic-release/commit-analyzer)
- Generate changelog content (@semantic-release/release-notes-generator)
- Create or update a changelog file generated by step 2 (@semantic-release/changelog)
- Update the package version to the next release version
- Commit release assets to the project’s git repository with the commit message chore(release): ${nextRelease.version} [skip ci] ${nextRelease.notes}.
- Publish a npm release (@semantic-release/npm) (optional)
- Publish a GitHub release and comment on released Pull Requests/Issues (@semantic-release/github)
Usage
When installing this package for the first time, the following shareable configuration (.releaserc.json) is automatically added to your project root folder:
With npm:
{
"extends": "@anolilab/semantic-release-preset"
}
Without npm:
{
"extends": "@anolilab/semantic-release-preset/.releaserc-without-npm.json"
}
File content:
{
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"successComment": false,
"failComment": false
}
],
[
"@semantic-release/git",
{
"message": "chore(release): ${nextRelease.gitTag} [skip ci]\\n\\n${nextRelease.notes}"
}
]
]
}
Commitizen
AddAdd cz
to your package.json scripts
"scripts": {
"commit": "cz"
}
Environment Variables Configuration
Ensure that your CI configuration has the following environment variables set:
- GITHUB_TOKEN: A GitHub personal access token
- NPM_TOKEN: A npm personal access token
You can test your config with a dry run:
npx semantic-release --dry-run
What you’ll want to do next is configure a GitHub workflow to run your tests and publish new versions automatically.
Here’s an example workflow configuration that runs your tests and publishes a new version for new commits on main
branch:
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Semantic Release"
on: # yamllint disable-line rule:truthy
push:
branches:
- "([0-9])?(.{+([0-9]),x}).x"
- "main"
- "next"
- "next-major"
- "alpha"
- "beta"
jobs:
test:
name: "Semantic Release"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
with:
fetch-depth: 0
persist-credentials: false
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Use Node.js 12.x"
uses: "actions/setup-node@v2"
with:
node-version: "12.x"
- name: "Get yarn cache directory path"
id: "yarn-cache-dir-path"
run: "echo \"::set-output name=dir::$(yarn config get cacheFolder)\""
- uses: "actions/cache@v2"
id: "yarn-cache" # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "${{ steps.yarn-cache-dir-path.outputs.dir }}"
key: "${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}"
restore-keys: |
${{ runner.os }}-yarn-
- name: "install"
run: "yarn install --immutable"
- name: "Build packages"
run: "yarn build"
- name: "test"
run: "yarn run test"
semantic-release:
name: "Semantic Release"
runs-on: "ubuntu-latest"
needs: ["test"]
steps:
- uses: "actions/checkout@v2"
with:
fetch-depth: 0
persist-credentials: false
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Use Node.js 12.x"
uses: "actions/setup-node@v2"
with:
node-version: "12.x"
- name: "Get yarn cache directory path"
id: "yarn-cache-dir-path"
run: "echo \"::set-output name=dir::$(yarn config get cacheFolder)\""
- uses: "actions/cache@v2"
id: "yarn-cache" # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "${{ steps.yarn-cache-dir-path.outputs.dir }}"
key: "${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}"
restore-keys: |
${{ runner.os }}-yarn-
- name: "install"
run: "yarn install --immutable"
- name: "Build packages"
run: "yarn build"
- name: "Semantic Release"
if: "success()"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
NPM_TOKEN: "${{ secrets.NPM_AUTH_TOKEN }}"
GIT_AUTHOR_NAME: "github-actions-shell"
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
GIT_COMMITTER_NAME: "github-actions-shell"
GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
run: "yarn run semantic-release"
Note on GitHub protected branches
If you’re releasing a GitHub protected branch you need to change the git committer to an owner/admin and allow repo admins to bypass the branch protection (make sure "include administrators" is disabled in the branch protection rules.)
If your repo is under an organisation, you can create a bot account and give it admin rights on the repo. If your repo is under a personal account, you have no choice to make the repo owner the commiter for the release.
Either way, you have to create a GitHub personal access token for the committer account and give it the "repo" access rights. Then set it to the GH_TOKEN secret in your GitHub repository.
Note: GitHub secrets not shared with forks and pull requests, so no one that doesn’t have write access to your repo can use of them.
Supported Node.js Versions
Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.
Contributing
If you would like to help take a look at the list of issues and check our Contributing guild.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Credits
License
The anolilab javascript-style-guide is open-sourced software licensed under the MIT license