跳到主要内容

github的ci一些问题的记录

这篇算是2023年第一篇偏技术的文档了,回顾一下当初github的ci配置的问题。

之前一直用的gitlab的ci,而且很多的服务器参数是运维配置好的,对github的ci不那么熟悉,而且对服务器的登录参数也是一次配置,所以写这个文章记录一下。

这里先写一下自己的ci的配置:

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI # ci的名字,没有啥特殊含义

on:
push: # 当push哪些分支的时候运行这个ci
branches: [ "dev" ]
pull_request: # 当提交到哪些分支的pr运行这个ci
branches: [ "dev" ]

jobs: # 工作流正式开始
build:

runs-on: ubuntu-latest # 在什么环境下运行,我这里选的最新的ubuntu

strategy:
matrix:
node-version: [16.x] # node的版本,我这里选的16.x
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps: # 运行步骤
- uses: actions/checkout@v3 # 签出代码方便后续工作流使用
- name: Use Node.js ${{ matrix.node-version }} # 名字,没有特殊含义
uses: actions/setup-node@v3 # 指定 Node.js 版本
with:
node-version: ${{ matrix.node-version }} # 使用上面预定的node版本
cache: 'npm' 缓存 npm 的依赖项。
- name: Install dependencies 📦️
run: yarn --if-present
- name: 构建
run: yarn build

- name: Deploy to aliyun server
uses: easingthemes/ssh-deploy@v2.1.5 # 选择ssh的版本
env:
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }} # 配置的ssh key
SOURCE: "build/" # 使用产物,记得加’/‘否则可能不回把子文件复制过去
REMOTE_HOST: ${{ secrets.ALIYUN_SERVER_HOST }} #配置的阿里云的服务器的公网IP
REMOTE_USER: "root" #登录角色
TARGET: "/usr/share/nginx/html" # 产物的目标位置


这个目录中每条命令都加上了相应的注释,想要系统的学习的github的ci的话可以去这里

配置ssh的密钥和host的问题参考github的ci文档

这里有一个我自己遇到的坑,就是在这里配置的ssh key总是无法正确访问服务器,建议先把那个密钥文件在自己电脑上远程连一下,确认没问题,否则排查起来很麻烦。

Loading Comments...