From ec42e18d541eb8b35c189ba4f6cd2d55b8d92f5b Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Wed, 11 Oct 2023 15:47:31 +0000 Subject: [PATCH] ci: add commit lint and semantic-release process See added CONTRIBUTING.md for details. The purpose is to have 1-click release process done via GitHub actions. This is achieved via semantic-release which does the whole release process. Version bump is derived from commit messages using semantic versioning. That requires commit messages to follow a specific structure and thus commit lint is added to ensure that all commits follow the structure. Signed-off-by: Petr Vobornik --- .github/workflows/commitlint.yml | 31 +++++++ .github/workflows/release.yml | 38 +++++++++ .gitignore | 1 + .releaserc | 43 ++++++++++ CONTRIBUTING.md | 139 +++++++++++++++++++++++++++++++ Makefile | 15 ++++ README.md | 4 + commitlint.config.js | 1 + 8 files changed, 272 insertions(+) create mode 100644 .github/workflows/commitlint.yml create mode 100644 .github/workflows/release.yml create mode 100644 .releaserc create mode 100644 CONTRIBUTING.md create mode 100644 commitlint.config.js diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..614b887 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,31 @@ +name: CI + +on: [push, pull_request] + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "lts/*" + - name: Print versions + run: | + git --version + node --version + npm --version + - name: Install commitlint + run: | + npm install @commitlint/config-conventional@latest commitlint@latest + - name: Validate current commit (last commit) with commitlint + if: github.event_name == 'push' + run: npx commitlint --from HEAD~1 --to HEAD --verbose + + - name: Validate PR commits with commitlint + if: github.event_name == 'pull_request' + run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..eb55213 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +# Release process that runs on on manual request (workflow_dispatch) + +# How it works: +# 1. Prepares env to be able to run semantic-release +# 2. Runs semantic-release which does the whole release process + +# See CONTRIBUTING.md for more information how the semantic-release works + +--- +name: Release +on: workflow_dispatch + +permissions: + contents: read # for checkout + +jobs: + release: + name: Release + runs-on: ubuntu-latest + 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: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "lts/*" + - name: Install dependencies + run: npm install semantic-release @semantic-release/{exec,git,github,changelog} + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: npx semantic-release diff --git a/.gitignore b/.gitignore index 07374e8..5866bab 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ coverage.* # Binary host-metering dist/host-metering +node_modules diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..7141bfe --- /dev/null +++ b/.releaserc @@ -0,0 +1,43 @@ +{ + "branches": [ + "main" + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/exec", + { + "prepareCmd": "make version-update NEXT_VERSION=${nextRelease.version} ;", + "publishCmd": "make tarball" + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md" + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "version/version.go", + "CHANGELOG.md" + ], + "message": "build(release): ${nextRelease.version}\n\n${nextRelease.notes}" + } + ], + [ + "@semantic-release/github", + { + "assets": [ + { + "path": "dist/*.tar.gz", + "label": "Tarball" + } + ] + } + ] + ] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3abde5c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,139 @@ +# Contributing + +Open a pull request to contribute a change. + +The project is using +- [Semantic Versioning](https://semver.org/) +- [Semantic Release](https://semantic-release.gitbook.io/semantic-release/) +- [Conventional Commits](https://www.conventionalcommits.org) +## Commit message format +Is defined by [Conventional Commits](https://www.conventionalcommits.org). +Commit lint enforces the formatting rules on commit messages. + +The format is (source [Angular](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format) +project): + +Each commit message consists of a **header**, a **body**, and a **footer**. + +``` +
+ + + +