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

  1. SSH directory of the current user. If no
    1. Go to the. SSH directorycd ~/.ssh/
    2. Create the.ssh directorymkdir ~/.ssh
  2. Execute build command:Ssh-keygen -t rsa -c "Recommended email address"
  3. Can be achieved bylsCommand to view the current directory to find the newly generated public key:id_rsa.pubThe private key:id_rsa
  4. Can be achieved bycat .\id_rsa.pubCommand 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

  1. Log in to ali Cloud server SSH [email protected]
  2. Go to the. SSH directory cd.ssh /
  3. Run the vi authorized_keys command
  4. Pasting Public Key Information
  5. Press ECS& to print :wq to save and exit

Simplified operation

  1. Execute command:ssh-copy-id [email protected]

Github SSH and GPG keys

Git can be operated by SSH

  1. Menu location: Settings /SSH and GPG keys/New SSH key
  2. Add a name and paste the locally generated public key information
  3. throughssh -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

  1. Menu location: Project /Settings/Secrets/New Repository Secret
  2. 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

  1. Menu Location: Setting/Developer Settings /Personal Access Tokens
  2. Generate New Token: Add the token name and select the required permissions
  3. The token is generated and saved, the forgotten token needs to be regenerated