Making paper
References:
- GitHub Actions Introduction tutorial – Ruan Yifeng
- GitHub Actions Documentation
- Workflow syntax for GitHub Actions
- Actions plug-in: SSH deploy configuration
- GitHub Action One-click deployment – Yopai’s Blog
1. Configure the workflow
-
At the root of the repository, create the.github/workflows directory
-
Add xxx.yml or xxx.yaml files to.github/workflows (keep the indent, XXX is optional, syntax: Resources 3.)
2. Configure the server key :(the key file is in the ~/. SSH/directory)
- Generate key:
ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]"
(Change your email address to your GitHub address and press enter.) - Save the public key to the authorized_keys file:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3. Configure GitHub SSH and Secrets
-
Configure path: current repository -> Settings -> Secrets (${{Secrets in xxx.yml) The name of your configuration}} needs to be used. See Resources 4.)
-
Configure SSH Public keys (SSH to add server public keys to GitHub account)
Example workflow file:
name: Tser CI
on:
push:
branches:
- master
jobs:
Publish to GitHub Pages
# build-and-deploy-to-github-pages:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@master
# - name: Build and Deploy to GitHub Pages
# uses: JamesIves/github-pages-deploy-action@master
# env:
# ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# BRANCH: gh-pages
# FOLDER: build
# BUILD_SCRIPT: npm install && npm run build
Publish to the server
build-and-deploy-to-server:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup Node.js environment
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install Dependencies
run: npm install
env:
CI: true
- name: Build Project
run: npm run build
env:
CI: true
- name: Deploy to Server
uses: Easingthemes/[email protected]
env:
SSH_PRIVATE_KEY: The ${{ secrets.SERVER_SSH_KEY }}
ARGS: '-rltgoDzvO --delete'
SOURCE: 'build/'
REMOTE_HOST: The ${{ secrets.REMOTE_HOST }}
REMOTE_USER: The ${{ secrets.REMOTE_USER }}
TARGET: The ${{ secrets.REMOTE_TARGET }}
Copy the code
Submit the code and view the execution record in the repository -> Actions
GitLab article
In Windows, for example
References:
- Install GitLab Runner on Windows
- GitLab CI/CD Pipeline Configuration Reference
- Registering Runners
1. Install GitLab Runner
-
Press Win + Q and enter PowerShell to run as administrator
-
Install GitLab Runner (see Resources 1.)
- Create the C:\ gitlab-runner directory in the open PowerShell
mkdir C:\GitLab-Runner
- Rename the downloaded Gitlab-Runner installation package to:
gitlab-runner.exe
Then put it in C:\ gitlab-runner - Run the following command in PowerShell:
cd C:\GitLab-Runner && .\gitlab-runner.exe install && .\gitlab-runner.exe start
- Create the C:\ gitlab-runner directory in the open PowerShell
-
Register as a runner (also as an administrator to execute commands in PowerShell. See Resources 3.)
URL and token required for registration :(warehouse -> Settings -> CI/CD Pipelines)
Registration steps:
2. Configure the.gitlab-ci.yml file in the project root directory
Example contents of a.gitlab-ci.yml file: (Do not name this file arbitrarily; see Resources 2 for syntax.)
Deploy To Server:
stage: deploy
script:
- ls
- whoami
- rm -r C:\inetpub\wwwroot\*
- cp -r ./dist/* C:\inetpub\wwwroot\
only:
- master
tags:
- IFSDeploy
Copy the code
Note:
I have also committed the packaged files (dist directory) to the repository, and the packaging steps can also be executed in an automated deployment, which needs to be explored.