From 027a22bede65ec725b2285aef7e719c8f72ece74 Mon Sep 17 00:00:00 2001 From: hu xiaotong <416314413@163.com> Date: Thu, 26 Jun 2025 14:08:43 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20Gitea=20Actions=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 ci.yaml 文件,定义 Gitea Actions 示例 --- .gitea/workflows/ci.yaml | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 8ae80c6..10a7987 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -10,7 +10,52 @@ jobs: build: runs-on: gitea_labels steps: - - uses: actions/checkout@v4 + - name: 检出代码 + run: | + echo "📥 检出代码到工作目录..." + echo "当前目录: $(pwd)" + echo "工作目录: ${{ gitea.workspace }}" + echo "仓库: ${{ gitea.repository }}" + echo "分支: ${{ gitea.ref }}" + echo "提交: ${{ gitea.sha }}" + + # 检查是否已经有代码 + if [ -f "go.mod" ]; then + echo "✅ 代码已存在,go.mod文件找到" + else + echo "📥 需要检出代码..." + + # 如果工作目录存在,使用它 + if [ -n "${{ gitea.workspace }}" ] && [ -d "${{ gitea.workspace }}" ]; then + echo "切换到工作目录: ${{ gitea.workspace }}" + cd "${{ gitea.workspace }}" + else + echo "工作目录不存在,尝试检出到当前目录" + # 尝试从git仓库检出 + if [ -n "${{ gitea.repository }}" ]; then + echo "检出仓库: ${{ gitea.repository }}" + git clone "https://gitea.com/${{ gitea.repository }}.git" . + # 切换到指定分支 + if [ -n "${{ gitea.ref }}" ]; then + BRANCH_NAME=$(echo "${{ gitea.ref }}" | sed 's/refs\/heads\///') + echo "切换到分支: $BRANCH_NAME" + git checkout "$BRANCH_NAME" + fi + fi + fi + # 再次检查 + if [ -f "go.mod" ]; then + echo "✅ 代码检出成功" + else + echo "❌ 代码检出失败" + echo "当前目录内容:" + ls -la + exit 1 + fi + fi + echo "最终工作目录: $(pwd)" + echo "目录内容:" + ls -la - name: 安装Go环境 run: |