跳到主要内容

GitHub Actions实用手册

常用操作

使用SSH连接到服务器
- name: run ssh command
uses: fifsky/ssh-action@master
with:
command: |
pwd
ls -l
host: ${{ secrets.SERVER_HOST }} # 服务器地址
user: ${{ secrets.SERVER_USER }} # 用户名
key: ${{ secrets.SERVER_SSH_KEY}} # SSH私钥
使用rsync同步目录到服务器
- name: sync files
uses: easingthemes/ssh-deploy@main
env:
ARGS: "-rltgoDzvO --delete"
REMOTE_HOST: ${{ secrets.SERVER_HOST }} # 服务器地址
REMOTE_USER: ${{ secrets.SERVER_USER }} # 用户名
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }} # SSH私钥
SOURCE: "dist/" # 源目录
TARGET: ${{ secrets.REMOTE_TARGET }} # 目标目录
EXCLUDE: "/dist/, /node_modules/" # 排除文件
使用maven构建项目
name: Build with Maven

on:
workflow_dispatch: # 允许手动触发
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
# 获取最新代码
- uses: actions/checkout@v3

# 部署jdk
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'liberica'
cache: maven

# 构建项目
- name: Build with Maven
run: mvn -B install --file pom.xml

# 上传构建产物
- name: Upload Build Artifact
uses: actions/upload-artifact@v3.1.0
if: success()
with:
name: build-artifact
path: target/*
if-no-files-found: error
同步仓库到 Gitee
on:
workflow_dispatch:
push:
schedule:
# UTC 21:00 -> CST (China) 5:00
- cron: '0 21 * * *'

name: Gitee mirror

jobs:
run:
name: Gitee mirror
runs-on: ubuntu-latest
steps:
- name: Mirror the Github repos to Gitee.
# https://github.com/Yikun/hub-mirror-action
uses: Yikun/hub-mirror-action@master
with:
src: github/AkagiYui
dst: gitee/AkagiYui
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
static_list: 'eeas-frontend'
force_update: true
timeout: '30m'