Skip to content

Commit 543439e

Browse files
bailin0824v_guanglwen
and
v_guanglwen
authored
Feat miniprogram ci (#172)
* feat: 修改miniprogram-ci * feat: 修改miniprogram-ci上传appid * feat: 修改node为ECMAScript模块 * feat: 测试 * feat: 测试 * feat: 测试 * feat: 修改workflows --------- Co-authored-by: v_guanglwen <[email protected]>
1 parent bbb10d5 commit 543439e

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
name: WeChat MiniProgram Demo CI/CD
22

33
on:
4-
push:
5-
branches:
6-
- master
74
pull_request:
5+
types: [closed]
86
branches:
97
- master
108
jobs:
119
upload:
10+
if: github.event.pull_request.merged == true && github.repository == 'wechat-miniprogram/miniprogram-demo'
1211
runs-on: ubuntu-latest
1312
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
submodules: 'recursive'
17+
token: ${{ secrets.GITHUB_TOKEN }}
18+
19+
- name: Clone submodule
20+
run: git submodule status
21+
22+
- name: Install dependencies
23+
run: npm install
24+
25+
- name: Run package script
26+
run: npm run init
27+
1428
- name: Upload MiniProgram
1529
env:
1630
WX_PRIVATE_KEY: ${{ secrets.WX_PRIVATE_KEY }}
1731
run: |
32+
mkdir -p ./build
1833
echo "$WX_PRIVATE_KEY" > ./build/key
19-
node ./build/ci.js
34+
chmod +x ./build/ci.js
35+
node ./build/ci.js --skip-key-write

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "miniprogram/packageSkylineExamples"]
22
path = miniprogram/packageSkylineExamples
3-
url = git@github.com:wechat-miniprogram/awesome-skyline.git
3+
url = https://github.com/wechat-miniprogram/awesome-skyline.git

build/ci.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
const path = require('path')
2-
const ci = require('miniprogram-ci')
3-
const fs = require('fs')
4-
const packageJson = require('../package.json')
1+
import path from 'path'
2+
import { fileURLToPath } from 'url'
3+
import fs from 'fs'
4+
import ci from 'miniprogram-ci'
5+
import packageJson from '../package.json' with { type: 'json' }
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = path.dirname(__filename)
8+
const privateKeyPath = path.resolve(__dirname, './key')
59

6-
const privateKeyContent = process.env.WX_PRIVATE_KEY
7-
if (!privateKeyContent) {
8-
throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets')
10+
// 检查私钥文件是否已存在
11+
if (!fs.existsSync(privateKeyPath)) {
12+
const privateKeyContent = process.env.WX_PRIVATE_KEY
13+
if (!privateKeyContent) {
14+
throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets')
15+
}
16+
console.log('>>>>写入私钥文件:', privateKeyPath);
17+
fs.writeFileSync(privateKeyPath, privateKeyContent)
918
}
1019

11-
const privateKeyPath = path.resolve(__dirname, './private.key')
12-
fs.writeFileSync(privateKeyPath, privateKeyContent)
13-
1420
const project = new ci.Project({
1521
appid: 'wxe5f52902cf4de896',
1622
type: 'miniProgram',
@@ -30,9 +36,11 @@ const params = {
3036
minifyWXML: true,
3137
minifyWXSS: true,
3238
codeProtect: false,
33-
autoPrefixWXSS: true
39+
autoPrefixWXSS: true,
40+
ignoreUploadUnusedFiles: true
3441
},
3542
}
43+
await ci.packNpm(project, {})
3644
ci.upload({
3745
project,
3846
...params
@@ -45,3 +53,5 @@ ci.upload({
4553
// 删除临时私钥文件
4654
fs.unlinkSync(privateKeyPath)
4755
})
56+
57+

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "miniprogram-demo",
33
"version": "1.0.0",
44
"description": "WeChat miniprogram demo",
5+
"type": "module",
56
"scripts": {
67
"init": "npm run sync && cd cloudfunctions/ && npm i --production && cd ../miniprogram/ && npm i --production",
78
"lint": "eslint .",

0 commit comments

Comments
 (0)