fix: 优化 CI/CD git clone 步骤

## 修改内容
- 使用 GitHub Actions 上下文变量替代 bash 变量
- 添加工作目录清理,避免冲突
- 优化 Node.js 安装,检查是否已安装

## 变更说明
- $GITHUB_WORKSPACE - 工作目录路径
- ${{ github.server_url }} - Gitea 服务器 URL
- ${{ github.repository }} - 仓库路径
- ${{ github.sha }} - 提交 SHA

## 优点
- 使用 Gitea 原生变量,更可靠
- 清理工作目录,避免重复克隆冲突
- 检查 Node.js 是否已安装,避免重复安装

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 16:56:49 +08:00
parent 7bdcf07d56
commit 1b178eb69d
+17 -10
View File
@@ -15,13 +15,14 @@ jobs:
steps:
- name: Checkout code
run: |
git clone --depth 1 --branch ${GITHUB_REF#refs/heads/} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git .
git checkout ${GITHUB_SHA}
rm -rf $GITHUB_WORKSPACE/*
cd $GITHUB_WORKSPACE
git clone --depth 1 ${{ github.server_url }}/${{ github.repository }}.git .
git checkout ${{ github.sha }}
- name: Setup Node.js
run: |
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs
which node || (curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y nodejs)
- name: Install dependencies
run: |
@@ -35,8 +36,10 @@ jobs:
steps:
- name: Checkout code
run: |
git clone --depth 1 --branch ${GITHUB_REF#refs/heads/} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git .
git checkout ${GITHUB_SHA}
rm -rf $GITHUB_WORKSPACE/*
cd $GITHUB_WORKSPACE
git clone --depth 1 ${{ github.server_url }}/${{ github.repository }}.git .
git checkout ${{ github.sha }}
- name: Build shared packages
run: |
@@ -65,8 +68,10 @@ jobs:
steps:
- name: Checkout code
run: |
git clone --depth 1 --branch ${GITHUB_REF#refs/heads/} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git .
git checkout ${GITHUB_SHA}
rm -rf $GITHUB_WORKSPACE/*
cd $GITHUB_WORKSPACE
git clone --depth 1 ${{ github.server_url }}/${{ github.repository }}.git .
git checkout ${{ github.sha }}
- name: Deploy to production
run: |
@@ -90,8 +95,10 @@ jobs:
steps:
- name: Checkout code
run: |
git clone --depth 1 --branch ${GITHUB_REF#refs/heads/} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git .
git checkout ${GITHUB_SHA}
rm -rf $GITHUB_WORKSPACE/*
cd $GITHUB_WORKSPACE
git clone --depth 1 ${{ github.server_url }}/${{ github.repository }}.git .
git checkout ${{ github.sha }}
- name: Deploy to test
run: |