Update .gitea/actions/test-links/action.yml

This commit is contained in:
2025-11-23 15:10:12 +01:00
parent 4d7d67b8e0
commit 64f3621ff7

View File

@@ -99,30 +99,38 @@ runs:
echo " $status $decoded_link" >> /tmp/download_$$.txt
fi
else
# Local file - check via Gitea API (use original URL-encoded link)
# Local file - convert to full URL and check via web
if [[ "$link" =~ ^/ ]]; then
# Absolute path from repo root
api_path="${link#/}"
# Absolute path from repo root - convert to full URL
if [ -z "$REPO_OWNER" ]; then
REPO_OWNER=$(git config --get remote.origin.url | sed -n 's|.*[:/]\([^/]*\)/[^/]*\.git|\1|p' || echo "")
REPO_NAME=$(git config --get remote.origin.url | sed -n 's|.*[:/][^/]*/\([^/]*\)\.git|\1|p' || echo "")
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
fi
# Build full URL: http://gitea:3000/owner/repo/raw/branch/main/path
check_url="http://gitea:3000/$REPO_OWNER/$REPO_NAME/raw/branch/$GIT_BRANCH${link}"
else
# Relative path from markdown file
md_dir=$(dirname "$md_file")
if [[ "$md_dir" == "." ]]; then
api_path="$link"
rel_path="$link"
else
api_path="${md_dir#./}/$link"
rel_path="${md_dir#./}/$link"
fi
if [ -z "$REPO_OWNER" ]; then
REPO_OWNER=$(git config --get remote.origin.url | sed -n 's|.*[:/]\([^/]*\)/[^/]*\.git|\1|p' || echo "")
REPO_NAME=$(git config --get remote.origin.url | sed -n 's|.*[:/][^/]*/\([^/]*\)\.git|\1|p' || echo "")
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
fi
# Build full URL for relative path
check_url="http://gitea:3000/$REPO_OWNER/$REPO_NAME/raw/branch/$GIT_BRANCH/$rel_path"
fi
# Get repository info from git remote
if [ -z "$REPO_OWNER" ]; then
REPO_OWNER=$(git config --get remote.origin.url | sed -n 's|.*[:/]\([^/]*\)/[^/]*\.git|\1|p' || echo "")
REPO_NAME=$(git config --get remote.origin.url | sed -n 's|.*[:/][^/]*/\([^/]*\)\.git|\1|p' || echo "")
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
fi
# Check file via Gitea API
api_url="http://gitea:3000/api/v1/repos/$REPO_OWNER/$REPO_NAME/contents/$api_path?ref=$GIT_BRANCH"
http_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$api_url" 2>/dev/null || echo "000")
# Check URL with curl
http_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$check_url" 2>/dev/null || echo "000")
if ! [[ "$http_code" =~ ^[23][0-9][0-9]$ ]]; then
status="✖ (not found)"