From f65e323053be5774e75f3566d7b76fc4ec5c0f53 Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Sat, 11 May 2024 20:03:44 +0800 Subject: [PATCH] ci: use release-it (#747) --- .github/workflows/build.yml | 65 ------------------------ .github/workflows/changelog.yml | 24 --------- .github/workflows/ci.yml | 43 +++++++++++++--- .github/workflows/release-it.yml | 55 +++++++++++++++++++++ .github/workflows/release.yml | 85 -------------------------------- .release-it.json | 23 +++++++++ knip.json | 3 ++ package.json | 5 +- 8 files changed, 122 insertions(+), 181 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/release-it.yml delete mode 100644 .github/workflows/release.yml create mode 100644 .release-it.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index f4b93846..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Build - -on: - push: - branches: - # The branch where the project source code resides - # 项目源代码所在的分支 - - main - - dev - paths-ignore: - # Changes involving the following path files will not trigger the workflow - # 涉及以下路径文件的更改不会触发工作流 - - LICENSE - - README-cmn_CN.md - - README-cmn_TW.md - - README-jyut.md - - docs/** - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4.1.2 - - uses: pnpm/action-setup@v3.0.0 - - uses: actions/setup-node@v4.0.2 - with: - node-version: lts/* - cache: pnpm - - - name: Install - run: pnpm install - - - name: Lint - run: pnpm run lint - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4.1.2 - - uses: pnpm/action-setup@v3.0.0 - - uses: actions/setup-node@v4.0.2 - with: - node-version: lts/* - cache: pnpm - - - name: Install - run: pnpm install - - - name: Build Extension - run: pnpm build - - - name: Upload Zip - uses: actions/upload-artifact@v4.3.1 - with: - name: BewlyBewly Zip - path: extension - - - name: Build Extension-Firefox - run: pnpm build-firefox - - - name: Upload Zip - uses: actions/upload-artifact@v4.3.1 - with: - name: BewlyBewly-Firefox Zip - path: extension-firefox diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index 08665ddb..00000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: ChangeLog - -on: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - - steps: - - uses: GoogleCloudPlatform/release-please-action@v3 - with: - token: ${{ secrets.RELEASE_TOKEN }} - release-type: node - package-name: release-please-action - release-as: 0.18.4 - signoff: 'github-actions <41898282+github-actions[bot]@users.noreply.github.com>' - changelog-types: '[{"type":"types","section":"Types","hidden":false},{"type":"revert","section":"Reverts","hidden":false},{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"improvement","section":"Feature Improvements","hidden":false},{"type":"docs","section":"Docs","hidden":false},{"type":"i18n","section":"I18n","hidden":true},{"type":"style","section":"Style Changes","hidden":false},{"type":"ci","section":"CI","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":true},{"type":"contributor","section":"New Contributors","hidden":false},{"type":"notice","section":"Notices","hidden":false}]' - default-branch: main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5225b4a..d47f5da1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,13 +3,29 @@ name: CI on: push: branches: + # The branch where the project source code resides + # 项目源代码所在的分支 - dev - main + paths-ignore: + # Changes involving the following path files will not trigger the workflow + # 涉及以下路径文件的更改不会触发工作流 + - LICENSE + - README-cmn_CN.md + - README-cmn_TW.md + - README-jyut.md + - docs/** pull_request: branches: - dev - main + paths-ignore: + - LICENSE + - README-cmn_CN.md + - README-cmn_TW.md + - README-jyut.md + - docs/** jobs: test: @@ -42,12 +58,7 @@ jobs: - name: Type check if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - pnpm run build - pnpm run typecheck - - - name: Build - run: pnpm run build + run: pnpm run typecheck - name: Test run: pnpm run test @@ -55,3 +66,23 @@ jobs: - name: Knip if: ${{ matrix.os == 'ubuntu-latest' }} run: pnpm run knip + + - name: Build Extension + run: pnpm build + + - name: Upload Zip + if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == 'lts/*' && github.ref_name == 'main' }} + uses: actions/upload-artifact@v4.3.1 + with: + name: BewlyBewly Zip + path: extension + + - name: Build Extension-Firefox + run: pnpm build-firefox + + - name: Upload Zip + if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == 'lts/*' && github.ref_name == 'main' }} + uses: actions/upload-artifact@v4.3.1 + with: + name: BewlyBewly-Firefox Zip + path: extension-firefox diff --git a/.github/workflows/release-it.yml b/.github/workflows/release-it.yml new file mode 100644 index 00000000..3c35ab01 --- /dev/null +++ b/.github/workflows/release-it.yml @@ -0,0 +1,55 @@ +name: Release + +permissions: + contents: write + id-token: write + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Git config + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Set node + uses: actions/setup-node@v4 + with: + node-version: lts/* + registry-url: 'https://registry.npmjs.org' + + - name: Install pnpm + uses: pnpm/action-setup@v3 + with: + run_install: | + - args: [--frozen-lockfile] + + - name: Release + run: npx release-it --verbose + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }} + CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }} + CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }} + CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }} + FIREFOX_EXTENSION_ID: ${{ secrets.FIREFOX_EXTENSION_ID }} + FIREFOX_JWT_ISSUER: ${{ secrets.FIREFOX_JWT_ISSUER }} + FIREFOX_JWT_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }} + + - name: Upload assets to a Release + uses: meeDamian/github-release@v2.0.3 + with: + files: | + extension.zip + extension-firefox.zip + token: ${{ secrets.RELEASE_TOKEN }} + allow_override: true + gzip: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 95112860..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v*' - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - cache: pnpm - - - name: Install - run: pnpm install - - - name: Lint - run: pnpm run lint - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - cache: pnpm - - - name: Install - run: pnpm install - - - name: Build - run: | - pnpm build - pnpm build-firefox - - - name: Build Extension - run: | - pnpm pack:zip - pnpm pack:zip-firefox - - - name: Upload assets to a Release - uses: meeDamian/github-release@v2.0.3 - with: - files: | - extension.zip - extension-firefox.zip - token: ${{ secrets.RELEASE_TOKEN }} - allow_override: true - gzip: false - - submit: - needs: [build, lint] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - cache: pnpm - - name: Install dependencies - run: pnpm install - - name: Submit Extension - run: | - pnpm build - pnpm pack:zip - pnpm wxt submit --chrome-zip ./extension.zip - pnpm build-firefox - pnpm pack:zip-firefox - pnpm wxt submit --firefox-zip ./extension-firefox.zip --firefox-sources-zip ./extension-firefox-sources.zip - env: - CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }} - CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }} - CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }} - CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }} - FIREFOX_EXTENSION_ID: ${{ secrets.FIREFOX_EXTENSION_ID }} - FIREFOX_JWT_ISSUER: ${{ secrets.FIREFOX_JWT_ISSUER }} - FIREFOX_JWT_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }} diff --git a/.release-it.json b/.release-it.json new file mode 100644 index 00000000..7eb60354 --- /dev/null +++ b/.release-it.json @@ -0,0 +1,23 @@ +{ + "plugins": { + "release-it-pnpm": { + "inFile": "CHANGELOG.md", + "publishCommand": "pnpm run submit" + } + }, + "git": { + "commitMessage": "chore: release v${version}", + "tagName": "v${version}" + }, + "hooks": { + "before:init": [ + "pnpm run build", + "pnpm run build-firefox", + "pnpm run pack:zip", + "pnpm run pack:zip-firefox", + "pnpm run lint", + "pnpm run typecheck", + "pnpm run test --run" + ] + } +} diff --git a/knip.json b/knip.json index f75d571d..0cdac28f 100644 --- a/knip.json +++ b/knip.json @@ -11,6 +11,9 @@ "ignoreDependencies": [ "@iconify/json", "uno.css", "lint-staged" ], + "ignoreBinaries": [ + "release-it" + ], "rules": { "types": "off", "enumMembers": "off", diff --git a/package.json b/package.json index 51f025a2..dbeb2ef4 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,10 @@ "test": "vitest test", "typecheck": "vue-tsc", "postinstall": "npx simple-git-hooks", - "knip": "knip" + "knip": "knip", + "submit": "run-p submit:*", + "submit:chrome": "pnpm wxt submit --chrome-zip ./extension.zip", + "submit:firefox": "pnpm wxt submit --firefox-zip ./extension-firefox.zip --firefox-sources-zip ./extension-firefox-sources.zip" }, "dependencies": { "@types/md5": "^2.3.5",