ci: 添加 Gitea Actions 示例工作流

- 新增 ci.yaml 文件,定义 Gitea Actions 示例
This commit is contained in:
hu xiaotong
2025-06-26 14:08:43 +08:00
parent 740d3b1856
commit 027a22bede

View File

@@ -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: |