fix: 配置远程仓库

This commit is contained in:
秋云
2025-05-16 18:25:41 +08:00
parent d17a9c5d08
commit 1c97f20818
2 changed files with 41 additions and 3 deletions

View File

@@ -62,11 +62,35 @@ jobs:
mkdir -p build mkdir -p build
fi fi
- name: Setup Git and checkout branch - name: Setup Git and repositories
run: | run: |
git config --global user.name "GitHub Actions Bot" git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com" git config --global user.email "actions@github.com"
# 确保远程仓库设置正确
echo "当前远程仓库配置:"
git remote -v
# 设置上游仓库(upstream)和origin
UPSTREAM_REPO="https://github.com/${{ github.repository }}.git"
ORIGIN_REPO="https://github.com/${{ github.event.pull_request.head.repo.full_name || github.repository }}.git"
echo "设置upstream指向主仓库: $UPSTREAM_REPO"
git remote remove upstream 2>/dev/null || true
git remote add upstream $UPSTREAM_REPO
echo "确保origin指向正确的仓库: $ORIGIN_REPO"
git remote set-url origin $ORIGIN_REPO 2>/dev/null || git remote add origin $ORIGIN_REPO
# 获取最新的主仓库和分支
echo "获取远程分支信息"
git fetch upstream
git fetch origin
# 显示远程仓库配置
echo "更新后的远程仓库配置:"
git remote -v
# 检查是否处于PR环境 # 检查是否处于PR环境
if [ -n "${{ github.event.pull_request.head.ref }}" ]; then if [ -n "${{ github.event.pull_request.head.ref }}" ]; then
echo "检测到PR切换到PR分支: ${{ github.event.pull_request.head.ref }}" echo "检测到PR切换到PR分支: ${{ github.event.pull_request.head.ref }}"
@@ -79,6 +103,19 @@ jobs:
git checkout -b temp-validation-branch git checkout -b temp-validation-branch
fi fi
- name: Prepare validation script
run: |
git show upstream/main:build/validate.py > build/validate.py 2>/dev/null
# 检查文件是否成功获取并且非空
if [ ! -s "build/validate.py" ]; then
echo "无法从上游仓库获取validate.py文件终止流程"
exit 1
else
echo "成功获取validate.py"
fi
- name: Get PR information - name: Get PR information
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr_number != '' }} if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr_number != '' }}
id: pr_info id: pr_info
@@ -118,8 +155,9 @@ jobs:
id: changed_files id: changed_files
if: github.event_name == 'pull_request_target' if: github.event_name == 'pull_request_target'
run: | run: |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -E '^repo/pathing/.*\.json$' || true) # 使用upstream/main作为比较基准
echo "Changed JSON files in repo/pathing:" CHANGED_FILES=$(git diff --name-only upstream/main HEAD | grep -E '^repo/pathing/.*\.json$' || true)
echo "Changed JSON files in repo/pathing compared to upstream/main:"
echo "$CHANGED_FILES" echo "$CHANGED_FILES"
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT

Binary file not shown.