Reference # 1: What is continuous integration? Reference 3: GitHub Actions
1. Basic concept description
2. Workflow
Sample a
Package the code of master branch of XX project in Github warehouse and deploy it to Ali Cloud server
# Deploy the code of master branch in Github repository to Ali Cloud servername: Build app and deploy to aliyun
onExecute workflow code branches -masterjobs: build: # runs-on Specifies the VM environment that the job task needs to run (mandatory field) run-ON: Ubuntu-lateststeps# use actions/ Checkout to fetch the source codeuses: actions/checkout@master # Install node12-name: use node.js12.163.Install node using actions/setup-nodeuses: actions/setup-node@v1
with:
node-version: 12.163.# install dependency - name: Yarn installrun: NPM install yarn && yarn install # package-name: yarn buildrun: YARN Run build:prod # Upload the deployment file to Aliyun using SSH. - name: Deploy to Aliyunuses: easingthemes/ssh-deploy@v21.1.
envPRIVATE_KEY is required to be configured to the project /Settings/Secrets/New Repository secretSSH_PRIVATE_KEY: ${{secrets.private_key}} # Server IP addressREMOTE_HOST: "xxx.xxx.xxx.xxx"Server user nameREMOTE_USER: "root"# SCP parametersARGS: "-avzr --delete"# source directorySOURCE: "dist"Server does not exist directory will fail to publish, need attentionTARGET: "/root/web-stite/client"
Copy the code
Example 2:
Package the code for the master branch of the XX project in Github repository and deploy it to Github-Pages
# the name of the workflownameTrigger condition: The master branch starts when it receives pushon: Push: Branches: -Master # Execute tasksjobs: build-and-deploy: name: build and deploy # runs-on The VM environment runs-on: Ubuntu-latest # Task stepstepsName = 'name';1.Pull code 🚀 # Use action library Actions /checkout to get the source codeuses: actions/checkout@master # Install Node1218.3.
- name: 2.Install Node 🚀 # Install Node using actions/setup-nodeuses: actions/setup-node@v1
with:
node-version: 12.183.# install dependency - name:3.Installation dependencies 🚀runNPM install yarn && yarn install4.Compile project 🚀run: yarn run build:prod
- name: 5.Deploy 🚀 # Use JamesIves library JamesIves/github-pages-deploy-action@3.71.
uses: JamesIves/github-pages-deploy-action@3.71.
with: # GitHub keyGITHUB_TOKEN: ${{secrets.github_access_token}} # Branch to publish toBRANCH: gh-pages # To deploy folderFOLDER: dist # Automatically deletes deployed filesCLEAN: true
Copy the code
3. Simple flow chart
Extended content
Create SSH public and private keys
To view the contents of the file, run the cat XXX command
- SSH directory of the current user. If no
- Go to the. SSH directory
cd ~/.ssh/
- Create the.ssh directory
mkdir ~/.ssh
- Go to the. SSH directory
- Execute build command:
Ssh-keygen -t rsa -c "Recommended email address"
- Can be achieved by
ls
Command to view the current directory to find the newly generated public key:id_rsa.pub
The private key:id_rsa
- Can be achieved by
cat .\id_rsa.pub
Command to print the public key information or directly open the file to view it
Extension 2. Configure the local public key information to the server
You can log in to the server without password
Manual operation
- Log in to ali Cloud server SSH [email protected]
- Go to the. SSH directory cd.ssh /
- Run the vi authorized_keys command
- Pasting Public Key Information
- Press ECS& to print :wq to save and exit
Simplified operation
- Execute command:
ssh-copy-id [email protected]
Github SSH and GPG keys
Git can be operated by SSH
- Menu location: Settings /SSH and GPG keys/New SSH key
- Add a name and paste the locally generated public key information
- through
ssh -T [email protected]
The verification results are as follows:Hi OSpoon! You've successfully authenticated, but GitHub does not provide shell access.
Extension 4, Github project configure Secrets
A variable configuration that can act as private key information,IP, port, username, password,Token, etc. for logging in to the server
Configure the private key information generated by the server to Github
- Menu location: Project /Settings/Secrets/New Repository Secret
- You are advised to name it PRIVATE_KEY and save it by pasting the private key
Github generates personal access tokens
Github -pages- deploy-Action extension needs to configure tokens to project Secrets to be used
- Menu Location: Setting/Developer Settings /Personal Access Tokens
- Generate New Token: Add the token name and select the required permissions
- The token is generated and saved, the forgotten token needs to be regenerated