Branch merge
Assume that the current project branch has master(formal), staging(pre-release), develop(test) scenarios:
- Master update, code synchronization to staging and Develop
- Staging update, code synchronization to Develop
Above, in order to keep the test branch code synchronized with the new feature of the main branch, reduce the manual merge work (note π’ : different teams have different branch management and CI/CD, I happen to have this requirement).
First edition: Git command
- Set the current Git user
- Update the code
- Set up upstream warehouse
- Cut the branches that need to be synchronized
- After the merge to submit
name: develop Merge master
on:
# Trigger after push code
push:
branches:
- master
# Timed task trigger, using cron rule, which executes once an hour by default
# schedule:
# - cron: '0 * * * *'
jobs:
merge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Merge origin master
run: | git config - global user. The name 'Autumn' git config - global user. The email '439661734 @qq.com' git pull - unshallow # set upstream of the warehouse # git remote add upstream https://github.com/upstream/upstream.git # git fetch upstream git checkout -b develop origin/develop git merge --no-edit origin/master git push origin developCopy the code
Second version, Github API
The default committer is Autumn, and Giuhub calls the powerful GitHub REST API
GitHub REST API You can use the GitHub REST API to create calls to get the data you need to integrate with GitHub.
Curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl curl π’ Note that using Github_Token directly will only trigger one Workflow at a time.
name: develop Merge master
on:
# Trigger after push code
push:
branches:
- master
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Using REST API pre-master2 Merge pre-master
run: | curl \ -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "content-type: application/json" \ -H "authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" \ https://github.com/AutumnWhj/GithubAction/merges \ -d '{"base":"develop","head":"master"}'Copy the code
In version 3, Node performs Actions
The leader required that there should be a notification sent out after the merger, so it was not necessary to read it manually. Therefore, since it was only an interface request, node would use the familiar AXIos to merge branches and send the notification, and send the notification to the enterprise wechat to call the robot π€ Webhook. Step by step processing:
- Integrated Node environment
- Installation required dependencies
- Execute the predefined commands of package.json scripts
name: staging merge master & send Commits
on:
push:
branches:
- master
jobs:
exec_node_job:
env:
BASE_BRANCH: staging
HEAD_BRANCH: master
ACCESS_TOKEN: The ${{ secrets.ACCESS_TOKEN }}
COMMIT_SIZE: 5
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.161.]
steps:
- uses: actions/checkout@v2
- name: Use Node.js The ${{ matrix.node-version }} Install the Node environment using action
uses: actions/setup-node@v1
with:
node-version: The ${{ matrix.node-version }}
- run: npm install axios Install axiOS dependencies
- run: npm run actions Execute the node file from the command line
Copy the code
Env specifies an environment variable for the job. If the env is installed, the process. Env specifies an environment variable for the job. NPM run Actions are script execution commands defined in package.json scripts, such as:
"scripts": {
"actions": "node ./node-ci/index.js"
}
Copy the code
The above branch combined with small requirements, and all kinds of scheme thinking, the current task node implementation, is more convenient and easier to expand.
Front-end project construction and deployment
Create a new VUE project — github- Actions -docs
Create a github-actions-docs project, modify the vue.config.js file, and modify the publicPath
/ / after accessed through https://autumnwhj.github.io/github-actions-docs/, so the path of the resource file to do the corresponding configuration
/ / if you eventually site access path is https://autumnwhj.github.io/docs-other/, then the value is/docs - other /,
module.exports = {
// publicPath configures the base path of all resources in the application.
publicPath: '/github-actions-docs/'
}
Copy the code
Create Personal Access Tokens
This step gives you permission to operate all repositories on Github, such as the following permission Settings.
First go to Github,Click on the link πDirect. orGithub top right corner profile picture π€ -- Settings -- Developer Settings -- Personal Access Token
Settings. The validity period can be customized.
β
Create Action secrets for your project — github- Actions -docs
This step sets up the Repositoryworkflow
Variables that are accessed at execution time, and environment variables that are set in GitHub Actionsecrets
Accessible to.
β
Create a Github Page project – autumnwhj.github
This step creates a repository for the Github Page static site.
Click on the upper right corner to create a new project.
Make sure the names are the same, otherwise you may find that your site will become longer and not overwrite automatically, as in this case[https://autumnwhj.github.io/](https://autumnwhj.github.io/)autumn.github.io
, the correct concise display is as follows:
Create github action auto-package deployment — github-actions-docs
The handy deploy-to-Github pages package is used here
name: Vue project Build and Deploy
on:
push:
branches:
- master # When the master branch changes, perform the following jobs operation
jobs:
deploying_vue_project:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: The actions/[email protected]
with:
persist-credentials: false
- name: building
Run the shell command
run: | npm install npm run build - name: Deploy π
uses: JamesIves/[email protected]
with:
branch: master
folder: dist
token: The ${{ secrets.ACCESS_TOKEN }}
repository-name: AutumnWhj/AutumnWhj.github.io # Github Page repository
target-folder: github-actions-docs
Copy the code
Last visit: Preview the address to access the newly deployed VUE project! The above note distinguishes the operation of two different warehouses. I have also marked which warehouse is operated in each step. Autumnwhj.github. IO github-actions-docs
The Nuggets automatically check in
Check in the interface of the network, copy curl down, put into Github Actions to trigger the periodic good, the community has a clever buddy already implemented, here is not to repeat it, everyone can refer to see. Nuggets are free! Automatic check-in & Automatic free draw
conclusion
I also just contact GitHub Actions not long, here to learn the process of some applications to share with you, but also to their own learning summary. Cognition determines the pattern. Let’s expand the boundaries of knowledge.