From 397020d2ddc7401fae772a366e5fc1acf424c211 Mon Sep 17 00:00:00 2001 From: akumar Date: Wed, 17 Apr 2024 10:50:06 +0200 Subject: [PATCH] chore: automate release --- .github/workflows/approve-merge.yaml | 24 ++++++++++++++ .github/workflows/build.yaml | 30 +++++++---------- .github/workflows/pr-lint.yaml | 20 ++++++++++++ .github/workflows/release-pr.yaml | 46 ++++++++++++++++++++++++++ .github/workflows/release.yaml | 49 ++++++++++++++++++++++++++++ .husky | 12 +++++++ .nvmrc | 1 + package-lock.json | 14 +------- package.json | 2 +- 9 files changed, 165 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/approve-merge.yaml create mode 100644 .github/workflows/pr-lint.yaml create mode 100644 .github/workflows/release-pr.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .husky create mode 100644 .nvmrc diff --git a/.github/workflows/approve-merge.yaml b/.github/workflows/approve-merge.yaml new file mode 100644 index 0000000..afee9fe --- /dev/null +++ b/.github/workflows/approve-merge.yaml @@ -0,0 +1,24 @@ +name: Merge Release PR + +on: + pull_request_review: + types: [submitted] + +jobs: + pr_approved: + if: ${{ github.event.review.state == 'approved' && github.event.pull_request.base.ref == 'master' && github.event.pull_request.head.ref == 'next' }} + runs-on: ubuntu-latest + steps: + - name: Clone git repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Merge PR + run: | + git checkout master + git merge --ff origin/next + git push -u origin master + - uses: peter-evans/repository-dispatch@v3 + with: + event-type: release_master \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9cc2f87..4a53bdd 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,18 +1,16 @@ -name: build +name: Build on: push jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Setup NodeJS - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '20.8.0' + node-version-file: '.nvmrc' - name: Install Dependencies run: npm ci @@ -21,21 +19,16 @@ jobs: run: npm run build test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: build steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Setup NodeJS - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '20.8.0' + node-version-file: '.nvmrc' - - name: Setup System - uses: restorecommerce/setup-system-action@v1 - with: - backing-only: true + - uses: restorecommerce/setup-system-action@v1 - name: Install Dependencies run: npm ci @@ -43,7 +36,6 @@ jobs: - name: Test run: npm run test && npm run lcov-report - - name: Coveralls - uses: coverallsapp/github-action@master + - uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-lint.yaml b/.github/workflows/pr-lint.yaml new file mode 100644 index 0000000..462366a --- /dev/null +++ b/.github/workflows/pr-lint.yaml @@ -0,0 +1,20 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + lint: + name: pr-lint + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-pr.yaml b/.github/workflows/release-pr.yaml new file mode 100644 index 0000000..c956960 --- /dev/null +++ b/.github/workflows/release-pr.yaml @@ -0,0 +1,46 @@ +name: Release PR + +on: + push: + branches: + - next + +permissions: + contents: read + +jobs: + release_pr: + permissions: + issues: write + pull-requests: write + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + - name: Install Dependencies + run: npm clean-install + + - name: Generate Changes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -ex + echo '# Release Changes' > changes.md + npx semantic-release@22.0.12 -d -p '@semantic-release/release-notes-generator' -b next | grep -v semantic-release | tee -a changes.md + printf '\n---\n\n### Approve this PR to release above packages!' >> changes.md + - name: Create PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -ex + export PR_NUMBER=$(gh pr list -B master -H next --json number | jq -r '.[0].number') + if [[ "$(git rev-parse origin/master)" == "$(git rev-parse origin/next)" ]]; then exit 0; fi + if [[ "$PR_NUMBER" == "null" ]]; then gh pr create -B master -H next -t "chore: release" -F changes.md; fi + if [[ "$PR_NUMBER" != "null" ]]; then gh pr edit $PR_NUMBER -F changes.md; fi diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2aa4c96 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,49 @@ +name: Release + +on: + push: + branches: + - master + workflow_dispatch: + types: [release_master] + +jobs: + release: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: master + + - name: Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + - name: Install Dependencies + run: npm clean-install + + - name: Git Config + run: | + git config --global user.email "bot@restorecommerce.io" + git config --global user.name "Restorecommerce Bot" + + - name: Build + run: npm run build --verbose + + - name: NPM Token + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" > .npmrc + + - name: Release + run: npx publish --no-verify-access --no-private --conventional-commits --yes --loglevel debug + + - name: Sync next branch + run: | + git checkout next + git merge master + git push -u origin next diff --git a/.husky b/.husky new file mode 100644 index 0000000..3dbc0ec --- /dev/null +++ b/.husky @@ -0,0 +1,12 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [ "$BRACH" = "main" ] +then + echo "committing directly to main is blocked" + exit 1 +fi + +./node_modules/.bin/commitlint -e $1 \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..726a201 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.11.1 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e76673f..ffbc75e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "typescript": "^5.4.5" }, "engines": { - "node": ">= 18.8.0" + "node": ">= 20.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -5235,18 +5235,6 @@ "nice-grpc": "^2.1.8" } }, - "node_modules/nice-grpc/node_modules/@grpc/grpc-js": { - "version": "1.9.14", - "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.9.14.tgz", - "integrity": "sha512-nOpuzZ2G3IuMFN+UPPpKrC6NsLmWsTqSsm66IRfnBt1D4pwTqE27lmbpcPM+l2Ua4gE7PfjRHI6uedAy7hoXUw==", - "dependencies": { - "@grpc/proto-loader": "^0.7.8", - "@types/node": ">=12.12.47" - }, - "engines": { - "node": "^8.13.0 || >=10.10.0" - } - }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", diff --git a/package.json b/package.json index 30646df..1a52246 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,6 @@ "build": "npm-run-all lint build:clean build:tsc" }, "engines": { - "node": ">= 18.8.0" + "node": ">= 20.0.0" } }