Skip to content

Commit

Permalink
feat: semantic release (#227)
Browse files Browse the repository at this point in the history
* feat: semantic-release

Add semantic-release configuration
Install the version-controlled dependencies from `package.json` and `yarn.lock`
- commit some assets as part of the version bump:
  - `CHANGELOG.md`
  - `**/package.json`
  - `yarn.lock`
- specify conventionalcommits style

Directly use `lerna publish` to push out a release

* build(deps): add semantic-release to package.json and yarn.lock

Version these dependencies

* build(lerna): lerna conventional commits

Tell Lerna to use conventional commits for changelog and versioning.

* build(commitlint): conventional commit should allow semantic-release commit messages

Allow conventional commit message format.

* docs(CONTRIBUTING): update Contributing guide

- update stale links
- modernize release steps

* docs(README): add semantic-release badge

Add a badge to advertise the semantic-release feature.
  • Loading branch information
jasonschroeder-sfdc authored Oct 20, 2022
1 parent f4813d4 commit 6b7a180
Show file tree
Hide file tree
Showing 8 changed files with 1,134 additions and 202 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: CI

on:
push:
branches: [master]
branches: [master, alpha, beta]
pull_request:
branches: [master]

Expand Down Expand Up @@ -36,3 +36,34 @@ jobs:
- run: yarn test:ci

- uses: codecov/codecov-action@v3
release:
name: Release
needs: lint-build-test # previous job MUST pass to make a release!
runs-on: ubuntu-latest

# Skip running release workflow on forks
if: github.repository_owner == 'salesforce' && github.event_name == 'push'

permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Need all git history & tags to determine next release version.
persist-credentials: false
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'

- run: yarn install --frozen-lockfile
- run: yarn run semantic-release --dryRun --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # used by setup-node@v3 action
32 changes: 32 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# yaml-language-server: $schema=https://json.schemastore.org/semantic-release.json
---
branches:
- master
- name: alpha
prerelease: true
channel: alpha

plugins:
- - '@semantic-release/commit-analyzer'
- preset: conventionalcommits
releaseRules:
- type: docs
scope: README
release: patch

- '@semantic-release/release-notes-generator'
- - '@semantic-release/changelog'
- changelogTitle: "# Changelog\n\nAll notable changes to this project will be documented in this file."
- - '@semantic-release/exec'
- publishCmd: yarn lerna publish --no-git-tag-version --no-git-reset --no-push --yes --dist-tag=${nextRelease.channel} --exact ${nextRelease.version}
- - '@semantic-release/git'
- assets:
- 'CHANGELOG.md'
- 'package.json'
- 'packages/*/package.json'
- 'yarn.lock'
- '@semantic-release/github'

debug: true
dryRun: true
preset: conventionalcommits
69 changes: 21 additions & 48 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ We want to encourage the developer community to contribute to Sa11y. This guide
- [Unit Testing](#unit-testing)
- [Integration Testing](#integration-testing)
- [Release](#release)
- [Making a pre-release](#making-a-pre-release)
- [Upgrade dependencies](#upgrade-dependencies)
- [Use local npm registry for testing](#use-local-npm-registry-for-testing)
- [Editor Configurations](#editor-configurations)
- [Types](#types)
- [ESLint](#eslint)
Expand All @@ -30,7 +30,6 @@ We want to encourage the developer community to contribute to Sa11y. This guide
- [Check your submission](#check-your-submission)
- [Lint your changes](#lint-your-changes)
- [Run tests](#run-tests)
- [Test CI config](#test-ci-config)
- [Create a pull request](#create-a-pull-request)
- [Pull Request Title](#pull-request-title)
- [Update the pull request](#update-the-pull-request)
Expand Down Expand Up @@ -63,7 +62,7 @@ Before you start, it helps to be familiar with [Web Accessibility](https://trail

## Requirements

- [Node](https://nodejs.org/) >= 14
- [Node](https://nodejs.org/) >= 16
- [Yarn](https://yarnpkg.com/) >= 1.22

## Installation
Expand Down Expand Up @@ -139,44 +138,25 @@ Your test should now be running in the Chrome debugger. You get your handy conso

## Release

- Generate Changelog
- `yarn release:changelog`
- Cleanup `CHANGELOG` to remove references to squashed commits and replace them with references to corresponding PRs where possible
- `yarn release:version` to bump versions interactively
- `yarn release:version:auto` to automatically determine version bump based on commits
- To publish packages to npm
- `npm config get registry`
- ensure the correct OSS public registry is selected
- `npm login`
- `yarn release:publish`
- `npm view <pkg>`
- check meta-data about published packages
- Create a release in github
- Bump `version` in root `package.json` to reflect the changes to the packages since last release
- Use that root `version` for the github release
- Add release notes to reflect Changelog since last release
- If you couldn't make these changes in the last PR that went into master, you can make a separate PR for release
- Create a `release` branch from `master`
- Commit changes to versions, changelog
- Changes should be limited to non-source code changes (docs, config)
- Push the `release` branch and create a pull request against `master`
- with PR title of the format `chore(release): ...`
- Merge to the default branch. This project uses `semantic-release`, so your changes will be released immediately. The version bump comes from the conventional commit type:

| Type | Release type | Trigger a release |
|-----------------|--------------|-------------------|
| breaking change | major | Yes |
| `feat` | minor | yes |
| `fix` | patch | yes |
| `perf` | patch | yes |
| `docs(README)` | patch | yes |

### Making a pre-release

- Merge to the `alpha` branch. It will always publish with the NPM `@alpha` tag.

#### Upgrade dependencies

- `yarn install:update`
- Select dependencies to update
- Check for CircleCI Orb updates
- [circleci/node](https://circleci.com/developer/orbs/orb/circleci/node)
- [circleci/browser-tools](https://circleci.com/developer/orbs/orb/circleci/browser-tools)
- update CircleCI config file
- [Test CI config](#test-ci-config)

#### Use local npm registry for testing

- Use [verdaccio](https://github.com/verdaccio/verdaccio) to spin-up a local npm registry
- Packages can be published to it by overriding the `registry` option
- e.g. `yarn release:publish --registry http://localhost:4873/`
- Check for GitHub Action updates

## Editor Configurations

Expand Down Expand Up @@ -285,13 +265,6 @@ Test your change by running [the unit tests and integration tests](#testing).

- `yarn test`

#### Test CI config

**Optionally** test any changes to CI config locally by using [the CircleCI local CLI](https://circleci.com/docs/2.0/local-cli/)

- `circleci config validate`
- `circleci local execute --job build-and-test`

### Create a pull request

If you've never created a pull request before, follow [these
Expand Down Expand Up @@ -348,7 +321,7 @@ The **header** is mandatory, and the **scope** of the header is optional.
Any line of the commit message cannot be longer 100 characters! This allows the message to be easier
to read on GitHub as well as in various git tools.

Footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any.
Footer should contain a [closing reference to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) if any.

Samples: (even more [samples](https://github.com/salesforce/sa11y/pulls))

Expand Down Expand Up @@ -408,8 +381,8 @@ The footer should contain any information about **Breaking Changes** and is also

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

[fork-a-repo]: https://help.github.com/en/articles/fork-a-repo
[configuring-a-remote-for-a-fork]: https://help.github.com/en/articles/configuring-a-remote-for-a-fork
[setup-github-ssh]: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
[creating-a-pull-request]: https://help.github.com/articles/creating-a-pull-request/
[fork-a-repo]: https://docs.github.com/en/get-started/quickstart/fork-a-repo
[configuring-a-remote-for-a-fork]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/configuring-a-remote-for-a-fork
[setup-github-ssh]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
[creating-a-pull-request]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
[eslint-integrations]: http://eslint.org/docs/user-guide/integrations
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Automated Accessibility Testing Libraries and Tools ([@sa11y packages](https://w

![Sa11y](https://github.com/salesforce/sa11y/workflows/Node.js%20CI/badge.svg)
[![Code Coverage](https://codecov.io/gh/salesforce/sa11y/branch/master/graph/badge.svg)](https://codecov.io/gh/salesforce/sa11y)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat)](https://github.com/semantic-release/semantic-release)
[![License](https://img.shields.io/npm/l/@sa11y/common)](./LICENSE.txt)
[![NPM downloads per month of @sa11y/common package](https://img.shields.io/npm/dm/@sa11y/common)](https://www.npmtrends.com/@sa11y/common)
[![Known Vulnerabilities](https://snyk.io/test/github/salesforce/sa11y/badge.svg?targetFile=package.json)](https://snyk.io/test/github/salesforce/sa11y?targetFile=package.json)
Expand Down
4 changes: 4 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

/* This is the pattern from semantic-release */
const automaticCommitPattern = /^chore\(release\):.*\[skip ci\]/;

/** @type {import('@commitlint/types').UserConfig} */
module.exports = {
extends: ['@commitlint/config-conventional'],
ignores: [(commitMsg) => automaticCommitPattern.test(commitMsg)],
};
9 changes: 8 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"command": {
"publish": {
"registry": "https://registry.npmjs.org/"
},
"version": {
"conventionalCommits": true
}
}
},
"changelogPreset": {
"name": "conventional-changelog-conventionalcommits"
},
"conventional-commits": true
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"@babel/preset-typescript": "7.18.6",
"@commitlint/cli": "17.1.2",
"@commitlint/config-conventional": "17.1.0",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/exec": "6.0.3",
"@semantic-release/git": "10.0.1",
"@tsconfig/node14": "1.0.3",
"@types/jest": "28.1.8",
"@types/node": "15.14.1",
Expand Down Expand Up @@ -99,6 +102,7 @@
"package-dependency-graph": "1.14.3",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"semantic-release": "19.0.5",
"ts-node": "10.9.1",
"typescript": "4.8.4",
"vertioner": "1.0.6",
Expand Down
Loading

0 comments on commit 6b7a180

Please sign in to comment.