🔧 chore(ci): extract prepare_repo.sh and clean up workflows
- Extract shared repo-checkout logic into .gitea/ci/prepare_repo.sh, removing ~47 lines of duplication from standards-check.yml and test.yml - Remove unused TEST_WORKSPACE env var from test.yml Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7ade85ea1b
commit
da08212cd6
|
|
@ -0,0 +1,51 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Clones or updates the repo to WORKSPACE_DIR/<repo-name> and checks out the
|
||||||
|
# target commit. Sets REPO_DIR in $GITHUB_ENV on success.
|
||||||
|
#
|
||||||
|
# Required env vars (provided by GitHub Actions context):
|
||||||
|
# WORKSPACE_DIR, GITHUB_SERVER_URL, GITHUB_REPOSITORY, github.sha,
|
||||||
|
# github.ref, github.ref_name, github.event.repository.name
|
||||||
|
# Optional:
|
||||||
|
# WORKFLOW secret (used as OAuth token for private repos)
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_NAME="${REPO_NAME}"
|
||||||
|
REPO_DIR="${WORKSPACE_DIR}/${REPO_NAME}"
|
||||||
|
TOKEN="${TOKEN:-}"
|
||||||
|
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
REPO_URL="https://oauth2:${TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
|
||||||
|
else
|
||||||
|
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$REPO_DIR" ]; then
|
||||||
|
if [ -d "$REPO_DIR/.git" ]; then
|
||||||
|
cd "$REPO_DIR"
|
||||||
|
git clean -fdx
|
||||||
|
git reset --hard
|
||||||
|
git fetch --all --tags --force --prune --prune-tags
|
||||||
|
else
|
||||||
|
rm -rf "$REPO_DIR"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$REPO_DIR/.git" ]; then
|
||||||
|
mkdir -p "$WORKSPACE_DIR"
|
||||||
|
git clone "$REPO_URL" "$REPO_DIR"
|
||||||
|
cd "$REPO_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if git -C "$REPO_DIR" cat-file -e "${TARGET_SHA}^{commit}" 2>/dev/null; then
|
||||||
|
git -C "$REPO_DIR" checkout -f "$TARGET_SHA"
|
||||||
|
else
|
||||||
|
if [ -n "${TARGET_REF:-}" ]; then
|
||||||
|
git -C "$REPO_DIR" fetch origin "$TARGET_REF"
|
||||||
|
git -C "$REPO_DIR" checkout -f FETCH_HEAD
|
||||||
|
else
|
||||||
|
git -C "$REPO_DIR" checkout -f "$TARGET_REF_NAME"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
git config --global --add safe.directory "$REPO_DIR"
|
||||||
|
echo "REPO_DIR=$REPO_DIR" >> "$GITHUB_ENV"
|
||||||
|
|
@ -105,6 +105,7 @@ tracked_skill_exists() {
|
||||||
[ -f "codex/skills/$name/SKILL.md" ]
|
[ -f "codex/skills/$name/SKILL.md" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cd "$REPO_DIR"
|
cd "$REPO_DIR"
|
||||||
|
|
||||||
git config user.name "$COMMIT_AUTHOR_NAME"
|
git config user.name "$COMMIT_AUTHOR_NAME"
|
||||||
|
|
@ -163,7 +164,7 @@ while IFS=$'\x1f' read -r source_id snapshot_dir sync_mode source_list skills_su
|
||||||
echo "ERROR: duplicate third-party skill name: $name" >&2
|
echo "ERROR: duplicate third-party skill name: $name" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ -d "codex/skills/thirdparty/$name" ] && tracked_skill_exists "$name"; then
|
if tracked_skill_exists "$name"; then
|
||||||
echo "ERROR: skill name conflict with tracked skill: $name" >&2
|
echo "ERROR: skill name conflict with tracked skill: $name" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -180,7 +181,7 @@ while IFS=$'\x1f' read -r source_id snapshot_dir sync_mode source_list skills_su
|
||||||
echo "ERROR: duplicate third-party skill name: $name" >&2
|
echo "ERROR: duplicate third-party skill name: $name" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ -d "codex/skills/thirdparty/$name" ] && tracked_skill_exists "$name"; then
|
if tracked_skill_exists "$name"; then
|
||||||
echo "ERROR: skill name conflict with tracked skill: $name" >&2
|
echo "ERROR: skill name conflict with tracked skill: $name" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue