This GitHub action uses the semantic-release project to automatically analyze commits since the previous release and increment the package version according to semantic versioning rules. If it's determined that a release should be created:
- Release notes will be generated
- The version in
package.jsonwill be incremented - A GitHub Release will be created
- Optionally, the package will be published to NPM
Typically this action is triggered from a workflow that runs on your main branch after each commit or pull request merge.
Here's a sample release workflow:
name: Release
on:
push:
branches:
- main
- '[0-9]+.x'
- '[0-9]+.[0-9]+.x'
jobs:
release:
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: Brightspace/third-party-actions@actions/checkout
with:
persist-credentials: false
- name: Setup Node
uses: Brightspace/setup-node@main
- name: Semantic Release
uses: BrightspaceUI/actions/semantic-release@main
with:
GITHUB_TOKEN: ${{ secrets.D2L_RELEASE_TOKEN }}Options:
aws-access-key-id: Access key id for the role that will read release info, required for MINOR_RELEASE_WITH_LMSaws-secret-access-key: Access key secret for the role that will read release info, required for MINOR_RELEASE_WITH_LMSaws-session-token: Session token for the role that will read release info, required for MINOR_RELEASE_WITH_LMSDEFAULT_BRANCH(default:"main"): name of the default release branchDRY_RUN(default:false): Runs semantic-release with the--dry-runflag to simulate a release but not actually do oneGITHUB_TOKEN: Token to use to update version in 'package.json' and create GitHub release -- see section below on the release token for more detailsMINOR_RELEASE_WITH_LMS(default:false): Automatically perform a minor release whenever the LMS release changes (requiresaws-access-key-id,aws-secret-access-keyandaws-session-tokento be passed)NPM(default:false): Whether or not to release as an NPM package (see "NPM Package Deployment" below for more info)NPM_TOKEN(optional ifNPMisfalseor publishing to CodeArtifact): Token to publish to NPM (see "NPM Package Deployment" below for more info)
Outputs:
VERSION: will contain the new version number if a release occurred, empty otherwise
Notes:
- This action currently requires Node v16+ or v14.17+ (Node v15 is not supported).
- If you have additional release validation steps (e.g. build step, validation tests), run them after the "Setup Node" step and before the "Semantic Release" step.
- This example will release only from
mainand maintenance branches (e.g.1.15.xor2.x) -- see more info about maintenance branches below.
The release step will fail to write to package.json because of the org-level rule requiring pull requests, as well as any rulesets you may have defined requiring PRs or status checks to pass. To get around this, we use a special rotating D2L_RELEASE_TOKEN.
Learn how to set up the D2L_RELEASE_TOKEN...
If you'd like the action to deploy your package to NPM, set the NPM option to true.
To publish to CodeArtifact, first configure your repo's repo-settings.
In your release workflow, ensure that prior to running the semantic-release step that the add-registry and the get-authorization-token steps have been run.
- name: Semantic Release
uses: BrightspaceUI/actions/semantic-release@main
with:
NPM: trueSimply pass through the NPM_TOKEN secret.
- name: Semantic Release
uses: BrightspaceUI/actions/semantic-release@main
with:
NPM: true
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}NPM_TOKEN is available as a shared organization secret in the Brightspace, BrightspaceUI, BrightspaceUILabs and BrightspaceHypermediaComponents organizations.
If your package is being published under the @brightspace-ui or @brightspace-ui-labs NPM organizations, ensure that it has the proper configuration in its package.json:
"publishConfig": {
"access": "public"
}Also ensure that "private": true is not present.
Recall the semantic versioning rules:
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards compatible manner, and
- PATCH version when you make backwards compatible bug fixes.
Releases occur based on the commit messages since the previous release. Our semantic-release configuration uses the Angular convention when analyzing commits.
- Commits which are prefixed with
fixorperfwill trigger apatchrelease. Example:fix: validate input before using - Commits which are prefixed with
feat:will trigger aminorrelease. Example:feat: add toggle() method - Other suggested prefixes which will NOT trigger a release:
build,ci,docs,style,refactorandtest. Example:docs: adding README for new component
To revert a change, add the revert prefix to the original commit message. This will cause the reverted change to not appear in release notes. Example: revert: fix: validate input before using.
To trigger a MAJOR release, include BREAKING CHANGE: with a space or two newlines in the footer of the commit message. On GitHub, this can be done by including the message in the "optional extended description" field:
Occasionally you'll want to backport a feature or bug fix to an older release. semantic-release refers to these as maintenance branches.
You will have to create a new branch from the Tag you want to update. git checkout -b 2.22.x v2.22.0 Note that the Tag has a v in the name, but the branch should not.
Maintenance branch names should be of the form: +([0-9])?(.{+([0-9]),x}).x.
Regular expressions are complicated, but this essentially means branch names should look like:
1.15.xfor patch releases on top of the1.15release (after version1.16exists)2.xfor feature releases on top of the2release (after version3exists)
Once you have your branch, you can make a PR targeting that branch with your changes. Merge it and provided the branch name is correct, and the correct semantic versioning keyword is in the PR, this should result in a new release Tag with your updates.
When the LMS version changes -- for example from 20.22.6 to 20.22.7 -- it can be desireable for your project to ignore semantic versioning rules and automatically do a minor release.
This ensures that if a patch is required for the previous LMS version in the future, there's room in the version scheme to fit it in.
To enable this feature, set the MINOR_RELEASE_WITH_LMS input to true and pass aws-access-key-id, aws-secret-access-key and aws-session-token.
The workflow will then add a .lmsrelease file to source control. When the value in that file differs from the current active LMS release, a minor release will automaticaly occur.
