.gitea/workflows/update.yml aktualisiert

This commit is contained in:
2026-11-10 21:25:22 +01:00
parent 9b598c36ac
commit 93b836794d
+44 -9
View File
@@ -25,7 +25,7 @@ jobs:
run: | run: |
set -Eeuo pipefail set -Eeuo pipefail
umask 077 umask 077
: "${GITEA_JOB_TOKEN:?GITEA_TOKEN fehlt}" : "${GITEA_JOB_TOKEN:?GITEATOKEN fehlt}"
mkdir -p "$CACHE_ROOT" mkdir -p "$CACHE_ROOT"
exec 9>"$CACHE_ROOT/.sync.lock" exec 9>"$CACHE_ROOT/.sync.lock"
flock -w 300 9 || { echo "Bereits ein Lauf aktiv" >&2; exit 1; } flock -w 300 9 || { echo "Bereits ein Lauf aktiv" >&2; exit 1; }
@@ -42,24 +42,57 @@ jobs:
ASKPASS_SCRIPT ASKPASS_SCRIPT
chmod 700 "$ASKPASS" chmod 700 "$ASKPASS"
export GIT_ASKPASS="$ASKPASS" GIT_TERMINAL_PROMPT=0 export GIT_ASKPASS="$ASKPASS" GIT_TERMINAL_PROMPT=0
REMOTE="https://git.apex-project.de/VULN/vuln-osv.git" REMOTE="https://git.apex-project.de/VULN/vuln-osv.git"
REPO="$CACHE_ROOT/repo" REPO="$CACHE_ROOT/repo"
backup_repo() {
mkdir -p "$CACHE_ROOT/backups"
local backup="$CACHE_ROOT/backups/repo.$(date -u +%Y%m%dT%H%M%SZ).$$"
echo "Repository-Cache wird gesichert: $backup"
mv -- "$REPO" "$backup"
}
clone_repo() {
git -c credential.helper= clone \
--branch main --single-branch --depth 1 \
"$REMOTE" "$REPO"
}
if [ ! -d "$REPO/.git" ]; then if [ ! -d "$REPO/.git" ]; then
[ ! -e "$REPO" ] || { echo "Unvollstaendiger Cache: $REPO" >&2; exit 1; } if [ -e "$REPO" ]; then
git -c credential.helper= clone --branch main --single-branch --depth 1 "$REMOTE" "$REPO" backup_repo
else
# Never reset an unfinished local commit or changes after a failed push.
if [ -n "$(git -C "$REPO" status --porcelain)" ] || [ "$(git -C "$REPO" rev-list --count origin/main..HEAD)" != 0 ]; then
echo "Lokale Aenderungen/Commits vorhanden: manuell pruefen, nicht ueberschreiben" >&2
exit 1
fi fi
clone_repo
else
# Den Tracking-Stand VOR dem Fetch merken: bei shallow clones
# ist ein reiner rev-list-Vergleich NACH dem Fetch unzuverlaessig.
OLD_REMOTE_HEAD="$(git -C "$REPO" rev-parse -q --verify refs/remotes/origin/main 2>/dev/null || true)"
LOCAL_HEAD="$(git -C "$REPO" rev-parse -q --verify HEAD 2>/dev/null || true)"
LOCAL_STATUS="$(git -C "$REPO" status --porcelain)"
git -C "$REPO" remote set-url origin "$REMOTE" git -C "$REPO" remote set-url origin "$REMOTE"
git -C "$REPO" -c credential.helper= fetch --no-tags --depth 1 origin main git -C "$REPO" -c credential.helper= fetch --no-tags --depth 1 origin main
git -C "$REPO" checkout -B main FETCH_HEAD NEW_REMOTE_HEAD="$(git -C "$REPO" rev-parse FETCH_HEAD)"
if [ -n "$LOCAL_STATUS" ]; then
echo "Lokale Aenderungen gefunden; sichere Repository-Cache."
backup_repo
clone_repo
elif [ "$LOCAL_HEAD" = "$OLD_REMOTE_HEAD" ] || [ "$LOCAL_HEAD" = "$NEW_REMOTE_HEAD" ]; then
# Keine ausstehenden lokalen Commits: Aktualisierung ist sicher.
git -C "$REPO" checkout -B main "$NEW_REMOTE_HEAD"
else
echo "Moeglicherweise ungepushte lokale Commits; sichere Repository-Cache."
backup_repo
clone_repo
fi
fi fi
cd "$REPO" cd "$REPO"
python3 scripts/sync.py python3 scripts/sync.py
python3 scripts/validate.py python3 scripts/validate.py
git config user.name "Vulnerability Bot" git config user.name "Vulnerability Bot"
git config user.email "vuln-bot@users.noreply.local" git config user.email "vuln-bot@users.noreply.local"
git add -A -- data/ state/ git add -A -- data/ state/
@@ -67,5 +100,7 @@ jobs:
echo "Keine neuen Daten" echo "Keine neuen Daten"
exit 0 exit 0
fi fi
git commit -m "vuln-osv update $(date -u +%Y-%m-%dT%H:%M:%SZ)" git commit -m "vuln-osv update $(date -u +%Y-%m-%dT%H:%M:%SZ)"
git -c credential.helper= push origin HEAD:main git -c credential.helper= push origin HEAD:main