98 lines
2.7 KiB
YAML
98 lines
2.7 KiB
YAML
name: Build
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-and-test:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: 获取 Tag 名称
|
|
id: extract_tag
|
|
run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
|
|
|
|
- name: 通知:开始构建
|
|
run: |
|
|
TAG=${{ steps.extract_tag.outputs.tag }}
|
|
curl -X POST http://10.0.0.3:52222/send \
|
|
-H "Content-Type: application/json" \
|
|
-d @- <<EOF
|
|
{
|
|
"alias": "ci",
|
|
"message": "[AO3 Mirror SSR][${TAG}]\n开始构建..."
|
|
}
|
|
EOF
|
|
|
|
- name: 检出代码
|
|
uses: actions/checkout@v3
|
|
|
|
- name: 设置 Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '22'
|
|
|
|
- name: 缓存 npm 模块
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.npm
|
|
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-npm-
|
|
|
|
- name: 安装依赖
|
|
run: npm install --force
|
|
|
|
- name: 构建项目(可选)
|
|
run: npm run build
|
|
|
|
- name: 打包构建产物
|
|
run: |
|
|
mkdir -p build-out
|
|
cp -r dist build-out/
|
|
cp -r public build-out/
|
|
cp server.js index.html package.json build-out/
|
|
zip -r output.zip build-out
|
|
|
|
- name: 通知:构建完成
|
|
run: |
|
|
TAG=${{ steps.extract_tag.outputs.tag }}
|
|
curl -X POST http://10.0.0.3:52222/send \
|
|
-H "Content-Type: application/json" \
|
|
-d @- <<EOF
|
|
{
|
|
"alias": "ci",
|
|
"message": "[AO3 Mirror SSR][${TAG}]\n构建完成✅"
|
|
}
|
|
EOF
|
|
|
|
- name: 设置 SSH 私钥
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
echo "Host *" > ~/.ssh/config
|
|
echo " StrictHostKeyChecking no" >> ~/.ssh/config
|
|
echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config
|
|
|
|
|
|
- name: 上传产物到远程服务器
|
|
run: |
|
|
TAG=${{ steps.extract_tag.outputs.tag }}
|
|
scp output.zip default@10.0.0.3:/srv/publish/ao3-mirror-ssr/${TAG}.zip
|
|
ssh default@10.0.0.3 sh -c 'cd /srv/publish/ao3-mirror-ssr/; rm -f latest.zip; ln -s ${TAG}.zip latest.zip'
|
|
|
|
- name: 通知:上传完成
|
|
run: |
|
|
TAG=${{ steps.extract_tag.outputs.tag }}
|
|
curl -X POST http://10.0.0.3:52222/send \
|
|
-H "Content-Type: application/json" \
|
|
-d @- <<EOF
|
|
{
|
|
"alias": "ci",
|
|
"message": "[AO3 Mirror SSR][${TAG}]\n上传完成✅"
|
|
}
|
|
EOF
|