From 79b55b70bef9c1157f9bfbd92147e2669a51bcd9 Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 11:35:06 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9miniprogram-ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 27 ++++++++++++++++++++++++++- .gitmodules | 2 +- build/ci.js | 34 ++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49f1f81b..dada1837 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,9 +11,34 @@ jobs: upload: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: 'recursive' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Verify file existence + run: | + echo "当前工作目录:" + pwd + echo "目录内容:" + ls -la + echo "build目录内容:" + ls -la ./build/ + echo "子模块状态:" + git submodule status + + - name: Install dependencies + run: npm install + + - name: Run package script + run: npm run init + - name: Upload MiniProgram env: WX_PRIVATE_KEY: ${{ secrets.WX_PRIVATE_KEY }} run: | + mkdir -p ./build echo "$WX_PRIVATE_KEY" > ./build/key - node ./build/ci.js + chmod +x ./build/ci.js + node ./build/ci.js --skip-key-write diff --git a/.gitmodules b/.gitmodules index 2f398a69..6ccb8b5f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "miniprogram/packageSkylineExamples"] path = miniprogram/packageSkylineExamples - url = git@github.com:wechat-miniprogram/awesome-skyline.git + url = https://github.com/wechat-miniprogram/awesome-skyline.git diff --git a/build/ci.js b/build/ci.js index 9b78edc9..bc3f9d7a 100644 --- a/build/ci.js +++ b/build/ci.js @@ -1,18 +1,24 @@ -const path = require('path') -const ci = require('miniprogram-ci') -const fs = require('fs') -const packageJson = require('../package.json') +import path from 'path' +import { fileURLToPath } from 'url' +import fs from 'fs' +import ci from 'miniprogram-ci' +import packageJson from '../package.json' with { type: 'json' } +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) +const privateKeyPath = path.resolve(__dirname, './key') -const privateKeyContent = process.env.WX_PRIVATE_KEY -if (!privateKeyContent) { - throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets') +// 检查私钥文件是否已存在 +if (!fs.existsSync(privateKeyPath)) { + const privateKeyContent = process.env.WX_PRIVATE_KEY + if (!privateKeyContent) { + throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets') + } + console.log('>>>>写入私钥文件:', privateKeyPath); + fs.writeFileSync(privateKeyPath, privateKeyContent) } -const privateKeyPath = path.resolve(__dirname, './private.key') -fs.writeFileSync(privateKeyPath, privateKeyContent) - const project = new ci.Project({ - appid: 'wxe5f52902cf4de896', + appid: 'wx622bee4f78fa4f5a', type: 'miniProgram', projectPath: path.resolve(__dirname, '../'), privateKeyPath: path.resolve(__dirname, './key'), @@ -30,9 +36,11 @@ const params = { minifyWXML: true, minifyWXSS: true, codeProtect: false, - autoPrefixWXSS: true + autoPrefixWXSS: true, + ignoreUploadUnusedFiles: true }, } +await ci.packNpm(project, {}) ci.upload({ project, ...params @@ -45,3 +53,5 @@ ci.upload({ // 删除临时私钥文件 fs.unlinkSync(privateKeyPath) }) + + From de99aa0f70e7a6a851105fabebf8220df33e393c Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 11:38:02 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9miniprogram-ci?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0appid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/ci.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ci.js b/build/ci.js index bc3f9d7a..00c2998c 100644 --- a/build/ci.js +++ b/build/ci.js @@ -18,7 +18,7 @@ if (!fs.existsSync(privateKeyPath)) { } const project = new ci.Project({ - appid: 'wx622bee4f78fa4f5a', + appid: 'wxe5f52902cf4de896', type: 'miniProgram', projectPath: path.resolve(__dirname, '../'), privateKeyPath: path.resolve(__dirname, './key'), From 9dc3a22b4cc377500d133ad85474155474c6d7a6 Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 11:43:38 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9node=E4=B8=BAECMA?= =?UTF-8?q?Script=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3330ab8e..5268c025 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "miniprogram-demo", "version": "1.0.0", "description": "WeChat miniprogram demo", + "type": "module", "scripts": { "init": "npm run sync && cd cloudfunctions/ && npm i --production && cd ../miniprogram/ && npm i --production", "lint": "eslint .", From 42a89cda21b2b9837cadfc297fcc35061f72e1b4 Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 11:55:44 +0800 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/ci.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ci.js b/build/ci.js index 00c2998c..a93d70e9 100644 --- a/build/ci.js +++ b/build/ci.js @@ -13,7 +13,7 @@ if (!fs.existsSync(privateKeyPath)) { if (!privateKeyContent) { throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets') } - console.log('>>>>写入私钥文件:', privateKeyPath); + console.log('>>>写入私钥文件:', privateKeyPath); fs.writeFileSync(privateKeyPath, privateKeyContent) } From 6528fd8bf6b93d510c17d6c8abf7aa82785a661d Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 14:16:04 +0800 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/ci.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ci.js b/build/ci.js index a93d70e9..082bb094 100644 --- a/build/ci.js +++ b/build/ci.js @@ -18,7 +18,7 @@ if (!fs.existsSync(privateKeyPath)) { } const project = new ci.Project({ - appid: 'wxe5f52902cf4de896', + appid: 'wx622bee4f78fa4f5a', type: 'miniProgram', projectPath: path.resolve(__dirname, '../'), privateKeyPath: path.resolve(__dirname, './key'), From 573408c5aaed8ffc00863af736cd5d1ceec3ec68 Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 14:20:19 +0800 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/ci.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build/ci.js b/build/ci.js index 082bb094..dac40aa1 100644 --- a/build/ci.js +++ b/build/ci.js @@ -6,7 +6,12 @@ import packageJson from '../package.json' with { type: 'json' } const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const privateKeyPath = path.resolve(__dirname, './key') - +try { + const content = fs.readFileSync(privateKeyPath, 'utf8'); + console.log('文件内容:', content); +} catch (err) { + console.error('读取文件出错:', err); +} // 检查私钥文件是否已存在 if (!fs.existsSync(privateKeyPath)) { const privateKeyContent = process.env.WX_PRIVATE_KEY From 6423f909c2735125bfe00297275d1f5d3eea6e3e Mon Sep 17 00:00:00 2001 From: v_guanglwen Date: Wed, 14 May 2025 15:39:44 +0800 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9workflows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 17 ++++------------- build/ci.js | 11 +++-------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dada1837..01376cff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,14 +1,13 @@ name: WeChat MiniProgram Demo CI/CD on: - push: - branches: - - master pull_request: + types: [closed] branches: - master jobs: upload: + if: github.event.pull_request.merged == true && github.repository == 'wechat-miniprogram/miniprogram-demo' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -17,16 +16,8 @@ jobs: submodules: 'recursive' token: ${{ secrets.GITHUB_TOKEN }} - - name: Verify file existence - run: | - echo "当前工作目录:" - pwd - echo "目录内容:" - ls -la - echo "build目录内容:" - ls -la ./build/ - echo "子模块状态:" - git submodule status + - name: Clone submodule + run: git submodule status - name: Install dependencies run: npm install diff --git a/build/ci.js b/build/ci.js index dac40aa1..00c2998c 100644 --- a/build/ci.js +++ b/build/ci.js @@ -6,24 +6,19 @@ import packageJson from '../package.json' with { type: 'json' } const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const privateKeyPath = path.resolve(__dirname, './key') -try { - const content = fs.readFileSync(privateKeyPath, 'utf8'); - console.log('文件内容:', content); -} catch (err) { - console.error('读取文件出错:', err); -} + // 检查私钥文件是否已存在 if (!fs.existsSync(privateKeyPath)) { const privateKeyContent = process.env.WX_PRIVATE_KEY if (!privateKeyContent) { throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets') } - console.log('>>>写入私钥文件:', privateKeyPath); + console.log('>>>>写入私钥文件:', privateKeyPath); fs.writeFileSync(privateKeyPath, privateKeyContent) } const project = new ci.Project({ - appid: 'wx622bee4f78fa4f5a', + appid: 'wxe5f52902cf4de896', type: 'miniProgram', projectPath: path.resolve(__dirname, '../'), privateKeyPath: path.resolve(__dirname, './key'),