From a528aba64f3040d8163f2ea5d72f3457acf5dfa0 Mon Sep 17 00:00:00 2001 From: njuguna-n <141340177+njuguna-n@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:40:24 +0300 Subject: [PATCH] feat: add versioning and releases * feat: add release and conventional-commits GHA workflows * feat: tag docker release with release and do not publish to npm --- .github/workflows/build.yml | 22 +++++++++++++----- .github/workflows/conventional-commits.yml | 26 ++++++++++++++++++++++ .github/workflows/release.yml | 25 +++++++++++++++++++++ .releaserc | 22 ++++++++++++++++++ commitlint.config.js | 5 +++++ package.json | 3 ++- 6 files changed, 97 insertions(+), 6 deletions(-) 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/build.yml b/.github/workflows/build.yml index 28bc774..8d08dea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,10 @@ name: Build cht-sync containers on: - push: - branches: - - 'main' + workflow_run: + workflows: ["release"] + types: + - completed jobs: build: @@ -18,13 +19,24 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Get the latest release tag + id: get_latest_release + uses: actions/github-script@v6 + with: + script: | + const latestRelease = await github.repos.getLatestRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + return latestRelease.data.tag_name; + - name: Build and push couch2pg uses: docker/build-push-action@v4 with: context: ./couch2pg file: ./couch2pg/Dockerfile push: true - tags: medicmobile/cht-sync-couch2pg:latest + tags: medicmobile/cht-sync-couch2pg:${{ steps.get_latest_release.outputs.result }} - name: Build and push dataemon uses: docker/build-push-action@v4 @@ -32,4 +44,4 @@ jobs: context: ./dbt file: ./dbt/Dockerfile push: true - tags: medicmobile/dataemon:latest + tags: medicmobile/dataemon:${{ steps.get_latest_release.outputs.result }} diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml new file mode 100644 index 0000000..e0c5c39 --- /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 0000000..aefb82d --- /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 0000000..39bbe6f --- /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/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..304c404 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,5 @@ +export default { + extends: [ + '@commitlint/config-conventional' + ] +}; diff --git a/package.json b/package.json index 1d01b0a..e829428 100644 --- a/package.json +++ b/package.json @@ -36,5 +36,6 @@ "pouchdb-core": "^8.0.1", "sinon": "^18.0.0", "uuid": "^9.0.1" - } + }, + "private": true }