Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
T treasure
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 12
    • Issues 12
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FE
  • treasure
  • Issues
  • #36

Closed
Open
Created Jun 28, 2021 by xingkai@kevin

小程序自动部署

第一步下载小程序密钥: 后台=》开发管理=〉小程序代码上传

下载密钥

如果要指定的服务器上传代码就设置下ip白名单,不指定就关闭白名单功能。

第二步安装miniprogram-ci

第三步修改代码中相关的配置信息


const ci = require('miniprogram-ci');
// const path = require('path');
const env = process.argv[2];

const packageInfo = require('../package.json');
const config = {
  name: packageInfo.name,
  version: packageInfo.version,
  description: packageInfo.description,
};

const params = {
  'appid': 'wxd31a445fdccea02f', // 改成自己的appid
  'type': 'miniProgram',
  'projectPath': './weapp/',
  'privateKeyPath': './build/secret/private.wxd31a445fdccea02f.key', // 改成自己的密钥存储路径
  'ignores': ['node_modules/**/*', '*.ts']
};

const descObj = {
  IE: '集成环境,机器人发布',
  TE: '测试环境,机器人发布',
  SE: '预演环境,机器人发布',
  PE: '生产环境,机器人发布'
};

const DEPLOYED_MESSAGE = `
${config.version}

${descObj[env] || ''}

`;

const project = new ci.Project(params);

void (async function run() {
  // const warning = await ci.packNpm(project, {
  //   // ignores: ['pack_npm_ignore_list'],
  //   reporter: (infos) => { console.log(infos); }
  // });
  // console.log(warning);

  // if (env === 'IE') {

  //   const previewResult = await ci.preview({
  //     project,
  //     ...update,
  //     setting: {
  //       es6: true,
  //       es7: true,
  //       minify: true,
  //       autoPrefixWXSS: true
  //     },
  //     qrcodeFormat: 'image',
  //     qrcodeOutputDest: path.join(__dirname, 'build/qrcode/miniprogram.jpg')
  //     // onProgressUpdate: console.log
  //   // pagePath: 'pages/index/index', // 预览页面
  //   // searchQuery: 'a=1&b=2',  // 预览参数 [注意!]这里的`&`字符在命令行中应写成转义字符`\&`
  //   // proxy: 'your proxy url',
  //   });

  //   console.log(previewResult);

  // } else {
    // 这一步会报错
  await ci.upload({
    project,
    desc: DEPLOYED_MESSAGE,
    version: config.version,
    setting: {
      es6: true,
      es7: true,
      minify: true,
      autoPrefixWXSS: true
    }
    // onProgressUpdate: console.log
  });

  // }

  console.log('上传成功');
}());


第四步服务器上部署代码

第五步修改gitlab-ci.yml

stages:
  - integration
  - testing
  - staging
  - production

  
deploy to inegration:
  stage: integration
  script:
    - cd /opt/lampp/htdocs/ebookingwx
    - git pull origin develop
    - npm install
    - rm -rf weapp
    - npm run IE
    - rm -rf 'weapp/$vendor/@vant/weapp/dist'
    - cp -r 'node_modules/@vant/weapp/dist' 'weapp/$vendor/@vant/weapp/dist'
    - cp project.config.json weapp/project.config.json
    - node build/build LE

  environment:
    name: integration
  only:
    refs:
      - integration
  when: on_success
  
deploy to testing:
  stage: testing
  script:
    - cd /opt/lampp/htdocs/ebookingwx
    - git pull origin develop
    - npm install
    - rm -rf weapp
    - npm run TE
    - rm -rf 'weapp/$vendor/@vant/weapp/dist'
    - cp -r 'node_modules/@vant/weapp/dist' 'weapp/$vendor/@vant/weapp/dist'
    - cp project.config.json weapp/project.config.json
    - node build/build TE
    - node build/weixin/index TE

  environment:
    name: testing
  only:
    refs:
      - develop
  when: manual
    
deploy to staging:
  stage: staging
  script:
    - cd /opt/lampp/htdocs/ebookingwx
    - git pull origin master
    - npm install
    - rm -rf weapp
    - npm run SE
    - rm -rf 'weapp/$vendor/@vant/weapp/dist'
    - cp -r 'node_modules/@vant/weapp/dist' 'weapp/$vendor/@vant/weapp/dist'
    - cp project.config.json weapp/project.config.json
    - node build/build SE
    - node build/weixin/index SE

  environment:
    name: staging
  only:
    refs:
      - master
  when: manual
    
deploy to production:
  stage: production
  script:
    - cd /opt/lampp/htdocs/ebookingwx
    - git pull origin master
    - npm install
    - rm -rf weapp
    - npm run PE
    - rm -rf 'weapp/$vendor/@vant/weapp/dist'
    - cp -r 'node_modules/@vant/weapp/dist' 'weapp/$vendor/@vant/weapp/dist'
    - cp project.config.json weapp/project.config.json
    - node build/build PE
    - node build/weixin/index PE

  environment:
    name: production
  only:
    refs:
      - release
  when: manual
    

第六步gitlab设置ci配置

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking