diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49f1f81b..01376cff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,35 @@ 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 + with: + fetch-depth: 0 + submodules: 'recursive' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Clone submodule + run: 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..00c2998c 100644 --- a/build/ci.js +++ b/build/ci.js @@ -1,16 +1,22 @@ -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', type: 'miniProgram', @@ -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) }) + + 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 .",