Writing in the front

Collaborative development of many people, the release is really suffocating

Pain points

1. Inconsistent developers, need to frequently login background switch 2. Manually fill in version information and description, low efficiency 3. Merge code and build separately, need to communicate back and forth 4. Code version cannot be traced

The specific process

Thanks to GitLab’S CI and miniprogram- CI, I designed the process like this

Ok, so let’s start scripting

The installation

First, initialize the gitlab-ci.yml file in the project root directory, open GitLab Runner, and divide the whole process into two steps

Job_install: # specifies the stage image script used by the current job. Stage: install -yarn --pure-lockfile only: # Specify the branches that need to be packaged. -master artifacts: Paths: # Specify the path to the files that need to be packaged. -node_modulesCopy the code

build

This step relies on node_modules generated by the Install step

Job_build: stage: build image: node:10.13.0 script: - yarn build - VERSION=$(git rev-parse --short HEAD)-stable ROBOT=2 DESCRIPTION=$(git log -1 --pretty=%B) node deploy.js  only: - masterCopy the code

Here we add version, robot, and description to our environment variables when we execute deploy.js after the build

  1. Git rev-parse –short HEAD is used to get the COMMIT SHA for traceability

  2. Robot: developer. Since the experience version of the small program is bound to the developer of the upload, we fixed one robot to upload the experience version

  3. Git log-1 –pretty=%B

The deployment of

The code for deployjs implements the contents of deployjs, where we use miniProgram-ci

1. Install tools

yarn add miniprogram-ci
Copy the code

2. Generate a secret key

Development -> Development Management -> Development Settings -> Applets code upload -> Applets upload secret keys -> Reset

Then download and save the generated secret key to the local root directory named private.key

3. Enable the whitelist

Configure an external IP address for GitLab

4. Deploy code

deploy.js

Const projectConfig = require('./project.config.json') const projectConfig = require('./project.config.json') Appid const {VERSION: VERSION, DESCRIPTION: desc, ROBOT: ROBOT} = process.env; // Const project = new ci. project ({appId: projectconfig. appid, type: 'miniProgram', projectPath: After projectConfig miniprogramRoot, / / build directory privateKeyPath: '. / private. Key ', / / secret key ignores: ['node_modules/**/*', 'src/*'], }); async function upload({version, desc, robot}) { const result = await ci.upload({ project, version, desc, robot, setting: { minify: true, autoPrefixWXSS: true }, onProgressUpdate: console.log }) console.log(result); } upload({version, desc, robot})Copy the code

The final code

.gitlab-ci.yml

Stages: -install-build job_install: # Indicates the task for installation. Stage: install Node :10.13.0 # Specify the docker image required for the current job script: # Run the command -yarn --pure-lockfile only: # Specify the branches required to be packaged-master artifacts: paths: -node_modules Job_build: stage: build image: node:10.13.0 script: - yarn build - VERSION=$(git rev-parse --short HEAD)-stable ROBOT=2 DESCRIPTION=$(git log -1 --pretty=%B) node deploy.js  only: - masterCopy the code

The effect

And you’re done!