利用 GitLab CI/CD 持续集成,并结合微信小程序 miniprogram-ci 编译模块,实现代码自动上传,解决了平时要通过微信开发者工具手动上传的痛点。
代码编写
miniprogram-ci
miniprogram-ci 是从微信开发者工具中抽离的关于小程序/小游戏项目代码的编译模块。官方地址文档地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| const ci = require('miniprogram-ci') let version = process.argv.slice(2)[0] let desc = process.argv.slice(3)[0]
if (!version) version = 'v1.0.0' if (!desc) desc = new Date() + 'Robot上传'
const project = new ci.Project({ appid: '******', type: 'miniProgram', projectPath: process.cwd() + '/dist/build/mp-weixin', privateKeyPath: '/app/mall/private.******.key', ignores: ['node_modules/**/*'], }) ci.upload({ project, version, desc, setting: { es6: true, }, }).then(res => { console.log(res) console.log('上传成功') }).catch(error => { if (error.errCode == -1) { console.log('上传成功') } console.log(error) console.log('上传失败') process.exit(-1) })
|
gitlab-ci
gitlab-ci 是 git 官方提供的的自动化部署持续集成工具。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| before_script: - date - npm -v - node -v - npm install - cp .env.example .env
after_script: - date stages: - deploy
cache: paths: - ./node_modules
deploy: stage: deploy except: - tags script: - npm run build - VERSION=`node -p "require('./package.json').version"` - DESCRIPTION=`git log -1 --pretty=format:%s` - node ./tool/upload.js $VERSION $DESCRIPTION
production: stage: deploy only: - tags script: - npm run build - DESCRIPTION=`git log -1 --pretty=format:%s` - node ./tool/upload.js $CI_BUILD_TAG $DESCRIPTION
|
miniprogram+GitLab CI/CD 实现微信小程序代码自动上传