Update .gitea/actions/test-links/action.yml
This commit is contained in:
@@ -99,30 +99,38 @@ runs:
|
|||||||
echo " $status $decoded_link" >> /tmp/download_$$.txt
|
echo " $status $decoded_link" >> /tmp/download_$$.txt
|
||||||
fi
|
fi
|
||||||
else
|
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
|
if [[ "$link" =~ ^/ ]]; then
|
||||||
# Absolute path from repo root
|
# Absolute path from repo root - convert to full URL
|
||||||
api_path="${link#/}"
|
|
||||||
else
|
|
||||||
# Relative path from markdown file
|
|
||||||
md_dir=$(dirname "$md_file")
|
|
||||||
if [[ "$md_dir" == "." ]]; then
|
|
||||||
api_path="$link"
|
|
||||||
else
|
|
||||||
api_path="${md_dir#./}/$link"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get repository info from git remote
|
|
||||||
if [ -z "$REPO_OWNER" ]; then
|
if [ -z "$REPO_OWNER" ]; then
|
||||||
REPO_OWNER=$(git config --get remote.origin.url | sed -n 's|.*[:/]\([^/]*\)/[^/]*\.git|\1|p' || echo "")
|
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 "")
|
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")
|
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check file via Gitea API
|
# Build full URL: http://gitea:3000/owner/repo/raw/branch/main/path
|
||||||
api_url="http://gitea:3000/api/v1/repos/$REPO_OWNER/$REPO_NAME/contents/$api_path?ref=$GIT_BRANCH"
|
check_url="http://gitea:3000/$REPO_OWNER/$REPO_NAME/raw/branch/$GIT_BRANCH${link}"
|
||||||
http_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$api_url" 2>/dev/null || echo "000")
|
else
|
||||||
|
# Relative path from markdown file
|
||||||
|
md_dir=$(dirname "$md_file")
|
||||||
|
if [[ "$md_dir" == "." ]]; then
|
||||||
|
rel_path="$link"
|
||||||
|
else
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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
|
if ! [[ "$http_code" =~ ^[23][0-9][0-9]$ ]]; then
|
||||||
status="✖ (not found)"
|
status="✖ (not found)"
|
||||||
|
|||||||
Reference in New Issue
Block a user