Skip to content

Feat miniprogram ci #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
32 changes: 21 additions & 11 deletions build/ci.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
Expand All @@ -45,3 +53,5 @@ ci.upload({
// 删除临时私钥文件
fs.unlinkSync(privateKeyPath)
})


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
Loading