From 739b6237103f69c91a1f08a818edf2d991b322e8 Mon Sep 17 00:00:00 2001 From: Dima Vyshniakov Date: Sat, 20 Apr 2024 20:23:29 +0200 Subject: [PATCH] fix(semantic-release): add semantic release and commitlint --- .github/workflows/merge-jobs.yml | 29 +++++++++++++++---------- .github/workflows/pull-request-jobs.yml | 6 ++--- package.json | 3 ++- release.config.cjs | 18 +++++++++++++++ tsconfig.linter.json | 1 + 5 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 release.config.cjs diff --git a/.github/workflows/merge-jobs.yml b/.github/workflows/merge-jobs.yml index fb88968..add6391 100644 --- a/.github/workflows/merge-jobs.yml +++ b/.github/workflows/merge-jobs.yml @@ -1,7 +1,7 @@ # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions -name: Post-merge tasks +name: Release on: push: @@ -11,16 +11,23 @@ jobs: build-publish: 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 + # id-token: write # to enable use of OIDC for npm provenance steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cancel Workflow Action uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Read .nvmrc run: echo ::set-output name=NVMRC::$(cat .nvmrc) id: nvm @@ -31,7 +38,7 @@ jobs: node-version: ${{ steps.nvm.outputs.NVMRC }} - name: Install pnpm - uses: pnpm/action-setup@v3 + uses: pnpm/action-setup@v2 with: version: 8 run_install: false @@ -48,11 +55,11 @@ jobs: restore-keys: | ${{ runner.os }}-pnpm-store- - - name: Run merge tasks + - name: Build and publish NPM package + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | pnpm install - -# - name: Publish NPM package -# uses: JS-DevTools/npm-publish@v3 -# with: -# token: ${{ secrets.NPM_TOKEN }} + pnpm run build + pnpm run semantic-release diff --git a/.github/workflows/pull-request-jobs.yml b/.github/workflows/pull-request-jobs.yml index a3724a8..2365740 100644 --- a/.github/workflows/pull-request-jobs.yml +++ b/.github/workflows/pull-request-jobs.yml @@ -13,14 +13,14 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cancel Workflow Action uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} + - name: Checkout + uses: actions/checkout@v4 + - name: Read .nvmrc run: echo ::set-output name=NVMRC::$(cat .nvmrc) id: nvm diff --git a/package.json b/package.json index a4ad0e7..0d208a1 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "test": "jest", "preview": "vite preview", "prepare": "is-ci || husky", - "lint-staged": "lint-staged" + "lint-staged": "lint-staged", + "commitlint": "commitlint" }, "peerDependencies": { "react": ">=18.2.0", diff --git a/release.config.cjs b/release.config.cjs new file mode 100644 index 0000000..2160919 --- /dev/null +++ b/release.config.cjs @@ -0,0 +1,18 @@ +/** + * @type {import('semantic-release').GlobalConfig} + */ +module.exports = { + branches: ['master'], + plugins: [ + '@semantic-release/commit-analyzer', + '@semantic-release/release-notes-generator', + '@semantic-release/npm', + [ + '@semantic-release/git', + { + message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}', + }, + ], + '@semantic-release/github', + ], +}; diff --git a/tsconfig.linter.json b/tsconfig.linter.json index 561bdbc..67b7d20 100644 --- a/tsconfig.linter.json +++ b/tsconfig.linter.json @@ -5,6 +5,7 @@ "**/*.stories.ts", "*.config.ts", "*.config.js", + "release.config.cjs", "src", ".eslintrc.cjs", "templates/**/*.ts",