From 52cf12a50083a1f343a138cb4c5e1e5166644d7a Mon Sep 17 00:00:00 2001 From: njuguna-n <141340177+njuguna-n@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:53:08 +0300 Subject: [PATCH] feat(#148): add automatic releases and versioning (#152) * feat: add new GH action and semantic release configs * chore: update Readme to add release process and release on the main branch * feat: Lint PR titles --- .github/workflows/conventional-commits.yml | 26 ++++++++++++++++++++++ .github/workflows/release.yml | 25 +++++++++++++++++++++ .releaserc | 22 ++++++++++++++++++ README.md | 16 +++++++++++++ commitlint.config.js | 2 ++ 5 files changed, 91 insertions(+) create mode 100644 .github/workflows/conventional-commits.yml create mode 100644 .github/workflows/release.yml create mode 100644 .releaserc create mode 100644 commitlint.config.js diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml new file mode 100644 index 00000000..e0c5c398 --- /dev/null +++ b/.github/workflows/conventional-commits.yml @@ -0,0 +1,26 @@ +name: Conventional commits +on: + pull_request: + types: + - opened + - edited + - synchronize + - reopened + +jobs: + lint_pr_title: + name: Lint PR title + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + - name: Install commitlint + run: | + npm install @commitlint/config-conventional + npm install commitlint@latest + - name: Lint title + run: npx --no -- commitlint <<< "${{ github.event.pull_request.title }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..aefb82d5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release +on: + push: + branches: + - main + +jobs: + release: + name: Release + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + persist-credentials: false + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + - name: Install Semantic Release and plugins + run: npm install -g semantic-release @semantic-release/git @semantic-release/changelog @semantic-release/github @semantic-release/commit-analyzer @semantic-release/release-notes-generator + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} + run: npx semantic-release diff --git a/.releaserc b/.releaserc new file mode 100644 index 00000000..39bbe6fe --- /dev/null +++ b/.releaserc @@ -0,0 +1,22 @@ +{ + "branches": ["main"], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md" + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "CHANGELOG.md" + ] + } + ], + "@semantic-release/github" + ] +} diff --git a/README.md b/README.md index 813cc892..95cdd917 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,19 @@ Follow the instructions in [the Local CHT Sync Setup documentation](https://docs # set environment variables, install dbt dependencies, seed data, run dbt, run test ./run_dbt_tests.sh ``` + +## Release Process +This repo has an automated release process where each feature/bug fix will be released immediately after it is merged to `main`. The release type is determined by the commit message format. Have a look at the development workflow in the [Contributor Handbook](https://docs.communityhealthtoolkit.org/contribute/code/workflow/) for more information. + +### Commit message format + +The commit format should follow the convention outlined in the [CHT docs](https://docs.communityhealthtoolkit.org/contribute/code/workflow/#commit-message-format). +Examples are provided below. + +| Type | Example commit message | Release type | +|-------------|-----------------------------------------------------------------------------------------------------|--------------| +| Bug fixes | fix(#123): rename column names | patch | +| Performance | perf(#789): add new indexes | patch | +| Features | feat(#456): add new model | minor | +| Non-code | chore(#123): update README | none | +| Breaking | perf(#2): remove data_record model
BREAKING CHANGE: form models should now read from new_model| major | diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000..7493774b --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,2 @@ +module.exports = { extends: ['@commitlint/config-conventional'] }; +