Files
chat-one-web/.gitea/workflows/ci.yml
alboped 7917975b5d
Some checks failed
CI / build (push) Failing after 2m23s
ci: 优化此配置;
2026-04-10 23:04:20 +08:00

94 lines
3.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gitea Actions:需开启 Actions 并注册 act_runner。
# Runner 建议:GITEA_RUNNER_LABELS=ubuntu-latest:docker://node:22-bookworm(Job 内自带 Node,避免 setup-node 重复下载)
# 需挂载 /var/run/docker.sock。
#
# 说明:NODEJS_ORG_MIRROR 在 act_runner 中常被忽略/不生效;用镜像自带 Node 即可绕过。
#
# 部署(推送到 main/master 时):在仓库「工作流 → 密钥」中配置
# SSH_PRIVATE_KEY DEPLOY_HOST DEPLOY_USER DEPLOY_PATH
# DEPLOY_PATH 为 Nginx root,如 /var/www/chat-one-web;rsync 会把 dist/ 下文件同步到该目录。
name: CI
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# 使用 Job 镜像(node:22-bookworm)自带的 Node,不再使用 actions/setup-node,避免重复下载 Node
- name: Setup Yarn
run: |
corepack enable
corepack prepare yarn@1.22.22 --activate
echo "node -v: $(node -v); yarn -v: $(yarn -v)"
echo "yarn config get registry: $(yarn config get registry)"
- name: Cache Yarn
uses: actions/cache@v4
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
run: yarn install --frozen-lockfile
- name: Prettier check
run: yarn format:check
- name: ESLint
run: yarn lint
- name: Build
run: yarn build
# 直连 deb.debian.org 在国内 Runner 上常极慢或卡住;换镜像并限制超时
- name: Install rsync and OpenSSH client
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
run: |
set -e
export DEBIAN_FRONTEND=noninteractive
shopt -s nullglob
for f in /etc/apt/sources.list /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list.d/*.sources /etc/apt/sources.list.d/*.list; do
[ -f "$f" ] || continue
sed -i \
-e 's/deb.debian.org/mirrors.aliyun.com/g' \
-e 's/security.debian.org/mirrors.aliyun.com/g' \
"$f"
done
apt-get -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 -o Acquire::Retries=2 update
apt-get install -y --no-install-recommends rsync openssh-client
- name: Deploy to Nginx (rsync)
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
run: |
set -e
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_deploy
chmod 600 ~/.ssh/id_deploy
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
rsync -avz --delete \
-e "ssh -i ~/.ssh/id_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" \
dist/ \
"${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/chat.alboped.com/"