Skip to content

Commit

Permalink
ci: setup conventional commits & release automation (#673)
Browse files Browse the repository at this point in the history
## Purpose of the changes

In order to improve the maintainability and velocity of this project, I
suggested we implement an automatic release pipeline.

To support this automation feature, I've set up the repository to follow
the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) formatting
standard. This allows any commit to be parsed programmatically, and the
release type (major, minor, patch) associated with a group of new
commits to be determined automatically.

For more information on the different commit types and their associated
releases, please check [the table listing from the configuration
preset](https://github.com/insurgent-lab/conventional-changelog-preset#commit-types).

Once those changes are merged to `master`:
- new commits on `master` will automatically be linted (locally with a
pre-commit hook) to ensure they follow the formatting standard.
- commits on other branches won't be linted, instead, the PR title will
be linted (removing overhead for contributors). If the PR title isn't
compliant, an explanation message will automatically be posted on the
PR.
- any commit pushed to the `master` branch will trigger a Test & Release
workflow (unless `[skip ci]` is present in the commit title) that will
analyze the commits since the last version, automatically determine the
necessary version bump, and handle the whole release process (updating
`package.json` & `package-lock.json`, generating new `CHANGELOG.md`
entries, publishing Github tag & release, then publishing the new
version to npm).

## Todo before merging the PR:

- [x] create a git tag for v2.3.1 (pointing to
988f7f2)
- [x] only allow squash merging PRs (cf screenshot below)
- go to
https://github.com/kelektiv/node-cron/settings#merge-button-settings
- check "Allow squash merging" and set the below dropdown to "Default to
pull request title"
  - uncheck "Allow merge commits" & "Allow rebase merging"
- [x] setup branch protection for `master` (cf screenshot below)
- go to https://github.com/kelektiv/node-cron/settings/branches and
create/update branch protection for `master` with (at least) the
following options:
    - "Require a pull request before merging"
    - "Dismiss stale pull request approvals when new commits are pushed"
    - "Require status checks to pass before merging"
- "Require branches to be up to date before merging" > then find and
select all "lint-and-test" workflows (should be 9 of them + "Lint PR
title" + "security/snyk").
    - "Require conversation resolution before merging"
    - "Require linear history"
- make sure "Do not allow bypassing the above settings" is
**unchecked**, else the automatic release commits won't work
- [x] setup Github PAC for the repository (required because of
[limitations with the default access token when branch protection is
enabled](semantic-release/github#175))
  - go to https://github.com/settings/personal-access-tokens/new
  - set Expiration in one year (custom)
  - select the right resource owner (should be "kelektiv")
- under "Repository" access, select "Only select repositories" and
select only "node-cron"
- under "Permissions", set "Contents", "Issues" and "Pull requests" to
"Read and write"
  - the "Overview" section should look like this (cf screenshot below)
- copy the generated token to a new `CI_GITHUB_TOKEN` repository secret
on the Github repository
- [x] setup npm token for the package
  - go to https://www.npmjs.com/settings/{NPM_USERNAME}/tokens
  - "Generate New Token" > "Granular Access Token"
  - set Expiration to "365 days"
- set Permissions to "Read and write", then click on "Only select
packages and scopes" and select only "cron"
- copy the generated token to a new `NPM_TOKEN` repository secret on the
Github repository

## Screenshots
<details>
<summary>disable merge commits in PR, only allow squash
merging</summary>
  

![image](https://github.com/kelektiv/node-cron/assets/11234273/96e8eb3e-125a-4ce5-9a45-8289a0cdfc19)
</details>

<details>
<summary>setup branch protection for `master` *(required checks are not
exactly the same in the screenshot)*</summary>
  

![image](https://github.com/kelektiv/node-cron/assets/11234273/bdb712b0-9a62-4391-a85b-6ee762797232)
</details>

<details>
<summary>Github PAC > the "Overview" section should look like
this</summary>
  

![image](https://github.com/kelektiv/node-cron/assets/11234273/0fb4b9ef-8674-42c2-af4a-bf89776239a4)
</details>


## Notes
- The "Squash and Merge" button should be the only one available when
trying to merge this PR.
  • Loading branch information
sheerlox committed Jul 20, 2023
1 parent efc3e26 commit c6f39ff
Show file tree
Hide file tree
Showing 11 changed files with 17,760 additions and 5,540 deletions.
5 changes: 5 additions & 0 deletions .commitlintrc
@@ -0,0 +1,5 @@
{
"extends": [
"@insurgentlab/commitlint-config"
]
}
38 changes: 38 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,38 @@
<!--- Provide a general summary of your changes in the Title above (following the Conventional Commits standard) -->
<!-- More infos: https://www.conventionalcommits.org -->
<!-- Commit types: https://github.com/insurgent-lab/conventional-changelog-preset#commit-types-->

## Description
<!--- Describe your changes in detail -->

## Related Issue
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] If my change introduces a breaking change, I have added a `!` after the type/scope in the title (see the Conventional Commits standard).
45 changes: 45 additions & 0 deletions .github/workflows/lint_pr_title.yml
@@ -0,0 +1,45 @@
name: 'Lint PR title'

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: write

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.
Details:
```
${{ steps.lint_pr_title.outputs.error_message }}
```
# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
39 changes: 0 additions & 39 deletions .github/workflows/nodejs.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,35 @@
name: Test & Release

on:
push:
branches:
- main

jobs:
lint-and-test:
uses: ./.github/workflows/test.yml
secrets: inherit

release:
needs: lint-and-test

runs-on: ubuntu-latest
env:
node-version: 18.x

steps:
- name: Checkout project
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
- name: Install packages
run: npm ci
- name: Run Semantic Release
run: npm run release
env:
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,31 @@
name: Lint & Test

on:
workflow_call:
pull_request:
branches:
- master

jobs:
lint-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: [14.x, 16.x, 18.x]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout project
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Install packages
run: npm ci
- name: Check codestyle compliance
run: npm run lint
- name: Run tests
run: npm run test
env:
CI: true
11 changes: 11 additions & 0 deletions .husky/commit-msg
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

# https://typicode.github.io/husky/guide.html#disable-husky-in-ci-docker-prod
[ -n "$CI" ] && exit 0

# only run commitlint on master (for admins pushing directly to branch)
[ "$(git rev-parse --abbrev-ref HEAD)" != "master" ] && exit 0

. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
41 changes: 41 additions & 0 deletions .releaserc
@@ -0,0 +1,41 @@
{
"repositoryUrl": "git@github.com:kelektiv/node-cron.git",
"branches": [
"master"
],
"tagFormat": "v${version}",
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"config": "@insurgentlab/conventional-changelog-preset",
"releaseRules": "@insurgentlab/conventional-changelog-preset/release-rules"
}
],
[
"@semantic-release/release-notes-generator",
{
"config": "@insurgentlab/conventional-changelog-preset"
}
],
"@semantic-release/npm",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md",
"package.json",
"package-lock.json"
],
"message": "Release v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
]
}
22 changes: 11 additions & 11 deletions CHANGELOG.md
@@ -1,4 +1,4 @@
## [v2.3.1]
## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)

### Added

Expand All @@ -9,7 +9,7 @@

- Linting issues

## [v2.3.0]
## [v2.3.0](https://github.com/kelektiv/node-cron/compare/v2.2.0...v2.3.0) (2023-03-14)

### Fixed

Expand All @@ -19,38 +19,38 @@

- Refactored get next date function

## [v2.2.0]
## [v2.2.0](https://github.com/kelektiv/node-cron/compare/v2.1.0...v2.2.0) (2023-01-09)

### Changed

- Updated Luxon dependency
- Updated unit tests to be compatible with new Luxon version

## [v2.1.0]
## [v2.1.0](https://github.com/kelektiv/node-cron/compare/v2.0.0...v2.1.0) (2022-07-14)

### Changed

- "Maximum iterations" will direct the user to refer to a single canonical issue instead of creating a new one

## [v2.0.0] - 2022-05-03
## [v2.0.0](https://github.com/kelektiv/node-cron/compare/v1.8.2...v2.0.0) (2022-05-03)
- Upgrade vulnerable dependencies
- Move from moment.js to luxon (breaking change)

## [v1.8.2] - 2020-01-24
## [v1.8.2](https://github.com/kelektiv/node-cron/compare/v1.8.1...v1.8.2) (2020-01-24)
- Fix syntax parsing bug

## [v1.8.1] - 2020-01-19
## [v1.8.1](https://github.com/kelektiv/node-cron/compare/v1.8.0...v1.8.1) (2020-01-19)
- Revert TS definition defaulting to DefinitelyTyped definitions.

## [v1.8.0] - 2020-01-19
## [v1.8.0](https://github.com/kelektiv/node-cron/compare/v1.7.1...v1.8.0) (2020-01-19)
- GH-454 - Range upper limit should default to highest value when step is provided by Noah May <noahmouse2011@gmail.com> in d36dc9581f9f68580a2016b368f8002a9f1e357d

## [v1.7.1] - 2019-04-26
## [v1.7.1](https://github.com/kelektiv/node-cron/compare/v1.7.0...v1.7.1) (2019-04-26)
- GH-416 - Fix issue where next execution time is incorrect in some cases in Naoya Inada <naoina@kuune.org> in c08522ff80b3987843e9930c307b76d5fe38b5dc

## [v1.7.0] - 2019-03-19
## [v1.7.0](https://github.com/kelektiv/node-cron/compare/v1.6.0...v1.7.0) (2019-03-19)
- GH-408 - DST issue by Shua Talansky <shua@bitbean.com> in 1e971fd6dfa6ba4b0469d99dd64e6c31189d17d3 and 849a2467d16216a9dfa818c57cc26be6b6d0899b

## [v1.6.0] - 2018-11-15
## [v1.6.0](https://github.com/kelektiv/node-cron/compare/v1.5.1...v1.6.0) (2018-11-15)
- GH-393, GH-394 - Remove hard limit on max iters in favor of a timeout by Nick Campbell <nicholas.j.campbell@gmail.com> in 57632b0c06c56e82f40b740b8d7986be43842735
- GH-390 - better handling of real dates which are in the past by Nick Campbell <nicholas.j.campbell@gmail.com> in 7cbcc984aea6ec063e38829f68eb9bc0dfb1c775

0 comments on commit c6f39ff

Please sign in to comment.