Use persistent cached source clone for faster runs
All checks were successful
Deploy Hello Lambda CFT / deploy (push) Successful in 16s
All checks were successful
Deploy Hello Lambda CFT / deploy (push) Successful in 16s
This commit is contained in:
parent
ba42de1500
commit
f2ded210f3
1 changed files with 23 additions and 3 deletions
|
|
@ -22,9 +22,29 @@ jobs:
|
|||
set -e
|
||||
SRC_DIR="."
|
||||
if [ ! -f "infra/hello-lambda.yml" ]; then
|
||||
echo "Repository files not present in workspace. Cloning from Forgejo..."
|
||||
git clone --depth 1 "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" _src
|
||||
SRC_DIR="_src"
|
||||
echo "Repository files not present in workspace. Using persistent cached clone..."
|
||||
CACHE_BASE="$HOME/.cache/forgejo-src"
|
||||
REPO_KEY="${GITHUB_REPOSITORY//\//_}"
|
||||
CACHE_REPO_DIR="${CACHE_BASE}/${REPO_KEY}"
|
||||
mkdir -p "$CACHE_BASE"
|
||||
|
||||
if [ -d "${CACHE_REPO_DIR}/.git" ]; then
|
||||
echo "Refreshing cached repository..."
|
||||
git -C "$CACHE_REPO_DIR" remote set-url origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||
git -C "$CACHE_REPO_DIR" fetch --depth 1 origin "${GITHUB_REF_NAME}"
|
||||
git -C "$CACHE_REPO_DIR" checkout -B "${GITHUB_REF_NAME}" FETCH_HEAD
|
||||
else
|
||||
echo "Creating cached repository clone..."
|
||||
git clone --depth 1 --branch "${GITHUB_REF_NAME}" "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" "$CACHE_REPO_DIR"
|
||||
fi
|
||||
|
||||
# Prefer exact triggering commit when available.
|
||||
if [ -n "${GITHUB_SHA}" ]; then
|
||||
git -C "$CACHE_REPO_DIR" fetch --depth 1 origin "${GITHUB_SHA}" || true
|
||||
git -C "$CACHE_REPO_DIR" checkout -q "${GITHUB_SHA}" || true
|
||||
fi
|
||||
|
||||
SRC_DIR="$CACHE_REPO_DIR"
|
||||
fi
|
||||
[ -f "${SRC_DIR}/infra/hello-lambda.yml" ] || { echo "infra/hello-lambda.yml not found"; exit 1; }
|
||||
echo "SRC_DIR=${SRC_DIR}" >> "$GITHUB_ENV"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue