From 93ad05af0c997bde8b2135e1266808ce59476cb2 Mon Sep 17 00:00:00 2001 From: sheepzh Date: Sun, 23 Mar 2025 14:13:23 +0800 Subject: [PATCH] ci: add publish pipeline (#428) --- .commitlintrc.ts | 47 +++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 43 ++++++++++++++++++++++++++++++ .husky/commit-msg | 1 + package.json | 5 +++- webpack/webpack.prod.firefox.ts | 4 +++ webpack/webpack.prod.ts | 4 +++ 6 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 .commitlintrc.ts create mode 100644 .github/workflows/publish.yml create mode 100644 .husky/commit-msg diff --git a/.commitlintrc.ts b/.commitlintrc.ts new file mode 100644 index 000000000..eaf00cf7f --- /dev/null +++ b/.commitlintrc.ts @@ -0,0 +1,47 @@ +import { + RuleConfigCondition, + RuleConfigSeverity, + TargetCaseType +} from "@commitlint/types" + +export default { + rules: { + "body-leading-blank": [RuleConfigSeverity.Error, "always"] as const, + "body-max-line-length": [RuleConfigSeverity.Error, "always", 100] as const, + "footer-leading-blank": [RuleConfigSeverity.Warning, "never"] as const, + "footer-max-line-length": [ + RuleConfigSeverity.Error, + "always", + 100, + ] as const, + "header-max-length": [RuleConfigSeverity.Error, "always", 100] as const, + "header-trim": [RuleConfigSeverity.Error, "always"] as const, + "subject-case": [ + RuleConfigSeverity.Error, + "never", + ["sentence-case", "start-case", "pascal-case", "upper-case"], + ] as [RuleConfigSeverity, RuleConfigCondition, TargetCaseType[]], + "subject-empty": [RuleConfigSeverity.Error, "never"] as const, + "subject-full-stop": [RuleConfigSeverity.Error, "never", "."] as const, + "type-case": [RuleConfigSeverity.Error, "always", "lower-case"] as const, + "type-empty": [RuleConfigSeverity.Error, "never"] as const, + "type-enum": [ + RuleConfigSeverity.Error, + "always", + [ + "build", + "chore", + "ci", + "docs", + "feat", + "fix", + "perf", + "refactor", + "revert", + "style", + "test", + ], + ] satisfies [RuleConfigSeverity, RuleConfigCondition, string[]], + }, + prompt: {}, +} \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..0a7cfecfc --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,43 @@ +name: Publish to extension/addon store +on: + push: + branches: + - "release" +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + uses: actions/setup-node@v1 + with: + node-version: "v20.11.0" + - run: npm install + - name: Build for MV3 + run: npm run build + - name: Build for Firefox + run: npm run build:firefox + - name: Upload to chrome webstore + uses: mnao305/chrome-extension-upload@v5.0.0 + with: + file-path: market_packages/target.zip + extension-id: dkdhhcbjijekmneelocdllcldcpmekmm + client-id: ${{ secrets.CHROME_CLIENT_ID }} + client-secret: ${{ secrets.CHROME_CLIENT_SECRET }} + refresh-token: ${{ secrets.CHROME_REFRESH_TOKEN }} + # publish: false # Not to publish + - name: Upload to Edge addon store + uses: wdzeng/edge-addon@v2 + with: + zip-path: market_packages/target.zip + product-id: 2a99ae83-5ec8-4ad2-aa63-9a276fc708ce + client-id: ${{ secrets.EDGE_CLIENT_ID }} + api-key: ${{ secrets.EDGE_API_KEY}} + upload-only: true # Not to publish + - name: Upload to Firefox addon store + uses: cardinalby/webext-buildtools-firefox-addons-action@v1 + with: + extensionId: '{7b312f5e-9680-436b-acc1-9b09f60e8aaa}' + zipFilePath: market_packages/target.firefox.zip + jwtIssuer: ${{ secrets.FIREFOX_API_KEY }} + jwtSecret: ${{ secrets.FIREFOX_API_SECRET }} \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 000000000..0a4b97de5 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no -- commitlint --edit $1 diff --git a/package.json b/package.json index 8ddff3b25..e1ffd8e4f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "analyze": "webpack --config=webpack/webpack.analyze.ts", "test": "jest --env=jsdom test/", "test-c": "jest --coverage --reporters=jest-junit --env=jsdom test/", - "test-e2e": "jest test-e2e/ --runInBand" + "test-e2e": "jest test-e2e/ --runInBand", + "prepare": "husky" }, "author": { "name": "zhy", @@ -43,6 +44,7 @@ "@types/webpack": "^5.28.5", "@vue/babel-plugin-jsx": "^1.4.0", "babel-loader": "^10.0.0", + "commitlint": "^19.8.0", "copy-webpack-plugin": "^13.0.0", "css-loader": "^7.1.2", "decompress": "^4.2.1", @@ -50,6 +52,7 @@ "filemanager-webpack-plugin": "^8.0.0", "generate-json-webpack-plugin": "^2.0.0", "html-webpack-plugin": "^5.6.3", + "husky": "^9.1.7", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-junit": "^16.0.0", diff --git a/webpack/webpack.prod.firefox.ts b/webpack/webpack.prod.firefox.ts index 401e31b0f..b7e208a6c 100644 --- a/webpack/webpack.prod.firefox.ts +++ b/webpack/webpack.prod.firefox.ts @@ -10,6 +10,7 @@ const outputPath = path.resolve(__dirname, '..', 'dist_prod_firefox') const marketPkgPath = path.resolve(__dirname, '..', 'market_packages') const normalZipFilePath = path.resolve(marketPkgPath, `${name}-${version}.firefox.zip`) +const targetZipFilePath = path.resolve(marketPkgPath, 'target.firefox.zip') const sourceCodePath = path.resolve(__dirname, '..', 'market_packages', `${name}-${version}-src.zip`) const readmeForFirefox = path.join(__dirname, '..', 'doc', 'for-fire-fox.md') // Temporary directory for source code to archive on Firefox @@ -28,6 +29,9 @@ const filemanagerWebpackPlugin = new FileManagerWebpackPlugin({ archive: [{ source: outputPath, destination: normalZipFilePath, + }, { + source: outputPath, + destination: targetZipFilePath, }] }, // Archive source code for FireFox diff --git a/webpack/webpack.prod.ts b/webpack/webpack.prod.ts index 87dd1b345..9e620ca5a 100644 --- a/webpack/webpack.prod.ts +++ b/webpack/webpack.prod.ts @@ -10,6 +10,7 @@ const outputPath = path.resolve(__dirname, '..', 'dist_prod') const marketPkgPath = path.resolve(__dirname, '..', 'market_packages') const normalZipFilePath = path.resolve(marketPkgPath, `${name}-${version}.mv3.zip`) +const targetZipFilePath = path.resolve(marketPkgPath, `target.zip`) const filemanagerWebpackPlugin = new FileManagerWebpackPlugin({ events: { @@ -22,6 +23,9 @@ const filemanagerWebpackPlugin = new FileManagerWebpackPlugin({ archive: [{ source: outputPath, destination: normalZipFilePath, + }, { + source: outputPath, + destination: targetZipFilePath, }] }, ]