From 904446ba47e23653885678ce02e5713c916b61cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=C3=A1nh=20Ho=C3=A0ng?= Date: Wed, 28 Feb 2024 09:33:46 +0700 Subject: [PATCH] chore(build): Implement semantic release automation Automated semantic release process for better version control. Created new workflows for releasing and publishing, added `@semantic-release/*` plugins in the new `.releaserc.json` file. The package and deno versions are now determined during release, not at development stage. --- .github/workflows/publish.yml | 34 +++++++++++++++++++++++++++++----- .github/workflows/tests.yml | 19 +++++++++++++++++-- .releaserc.json | 10 ++++++++++ deno.json | 2 +- package.json | 2 ++ src/read/NumberReader.ts | 24 ++++++++++++------------ 6 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 .releaserc.json diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index db75c33..706c6d5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,5 @@ name: Publish + on: push: branches: @@ -9,16 +10,39 @@ jobs: name: Test uses: ./.github/workflows/tests.yml secrets: inherit - publish: - name: Publish - runs-on: ubuntu-latest + release: + name: Release needs: test + runs-on: ubuntu-latest permissions: - contents: read + contents: write + issues: write + pull-requests: write id-token: write steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install Deno uses: denoland/setup-deno@v1 - - name: Publish package + - name: Install jq + uses: dcarbone/install-jq-action@v2 + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: latest + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + cache: 'pnpm' + - name: Release on GitHub + run: pnpm --package conventional-changelog-conventionalcommits --package semantic-release dlx semantic-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Update version in deno.json + run: + jq '.version = "${{ github.event.release.tag_name }}"' deno.json > deno.json.tmp + mv deno.json.tmp deno.json + - name: Publish package to JSR run: deno publish diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f34a3f5..ecfedb5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,13 +18,18 @@ jobs: version: 8 - uses: actions/setup-node@v4 with: + node-version: 'lts/*' cache: 'pnpm' - name: Install dependencies run: pnpm install - name: Prettier check run: pnpm test:prettier - test: - name: Unit tests + - name: Checks for known security issues with the installed packages + run: pnpm audit + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: pnpm npm audit signatures + node: + name: Node tests needs: lints runs-on: ubuntu-latest strategy: @@ -45,3 +50,13 @@ jobs: run: pnpm install - name: Run unit tests run: pnpm test + deno: + name: Deno test + needs: lints + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Deno + uses: denoland/setup-deno@v1 + - name: Type-check the dependencies + run: deno check src/index.ts diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..b91e9df --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,10 @@ +{ + "branches": ["main"], + "tagFormat": "${version}", + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/npm", + "@semantic-release/github" + ] +} diff --git a/deno.json b/deno.json index a9572d5..060abc5 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@hckhanh/vn-number", - "version": "1.6.0", + "version": "0.0.0-development", "exports": "./src/index.ts", "exclude": [ ".github/", diff --git a/package.json b/package.json index 000fade..3048f8f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { "name": "@hckhanh/vn-number", + "version": "0.0.0-development", "description": "A bunch of utility functions that work with number in Vietnamese language", "type": "module", + "private": true, "sideEffects": false, "scripts": { "test": "vitest related src/**/*.ts", diff --git a/src/read/NumberReader.ts b/src/read/NumberReader.ts index 6b5fee4..7fc7d38 100644 --- a/src/read/NumberReader.ts +++ b/src/read/NumberReader.ts @@ -1,8 +1,8 @@ -import Numbers from '~/read/Numbers.ts' -import Billion from '~/read/Billion.ts' -import Thousand from '~/read/Thousand.ts' -import Million from '~/read/Million.ts' -import { InvalidNumberTypeError } from '~/read/Utils.ts' +import Numbers from './Numbers.ts' +import Thousand from './Thousand.ts' +import Million from './Million.ts' +import Billion from './Billion.ts' +import { InvalidNumberTypeError } from './Utils.ts' enum NumberType { Numbers, @@ -15,6 +15,13 @@ enum NumberType { * A number reader in Vietnamese language helper */ export default class NumberReader { + private static readonly NumberClasses = { + [NumberType.Numbers]: Numbers, + [NumberType.Thousand]: Thousand, + [NumberType.Million]: Million, + [NumberType.Billion]: Billion + } + /** * Read a number in Vietnamese language * @@ -71,13 +78,6 @@ export default class NumberReader { return s.match(/.{1,3}(?=(.{3})*$)/g) || [] } - private static readonly NumberClasses = { - [NumberType.Numbers]: Numbers, - [NumberType.Thousand]: Thousand, - [NumberType.Million]: Million, - [NumberType.Billion]: Billion - } - /** * Map a number in string to a {@link Numbers} object *