diff --git a/.forgejo/workflows/deploy-cfn.yml b/.forgejo/workflows/deploy-cfn.yml index 2853b62..954968c 100644 --- a/.forgejo/workflows/deploy-cfn.yml +++ b/.forgejo/workflows/deploy-cfn.yml @@ -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"