All checks were successful
Release Docs / release (push) Successful in 3s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
72 lines
2.3 KiB
YAML
72 lines
2.3 KiB
YAML
name: Release Docs
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
git clone -b ${GITHUB_REF#refs/tags/} \
|
|
"${{ github.server_url }}/${{ github.repository }}.git" .
|
|
|
|
- name: Package docs
|
|
run: |
|
|
if [ ! -d "docs" ]; then
|
|
echo "Error: docs directory not found"
|
|
exit 1
|
|
fi
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
echo "$TAG" > "docs/.version"
|
|
tar -czf /tmp/docs.tar.gz docs/
|
|
|
|
- name: Create Release and Upload
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}"
|
|
AUTH="Authorization: token ${GITEA_TOKEN}"
|
|
|
|
# Delete existing release for this tag if any
|
|
EXISTING_ID=$(curl -sf "${API}/releases/tags/${TAG}" -H "$AUTH" 2>/dev/null \
|
|
| python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
|
if [ -n "$EXISTING_ID" ]; then
|
|
echo "Deleting existing release #${EXISTING_ID}"
|
|
curl -sf -X DELETE "${API}/releases/${EXISTING_ID}" -H "$AUTH" 2>/dev/null || true
|
|
fi
|
|
|
|
# Create release
|
|
curl -sf -X POST "${API}/releases" \
|
|
-H "$AUTH" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG}\",
|
|
\"name\": \"API文档 ${TAG}\",
|
|
\"body\": \"米普云航司API文档更新 ${TAG}\"
|
|
}"
|
|
|
|
# Get release ID
|
|
RELEASE_ID=$(curl -sf "${API}/releases/tags/${TAG}" -H "$AUTH" \
|
|
| python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
|
|
|
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "None" ]; then
|
|
echo "Error: failed to get release ID"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release #${RELEASE_ID} created"
|
|
|
|
# Upload docs.tar.gz
|
|
curl -sf -X POST "${API}/releases/${RELEASE_ID}/assets?name=docs.tar.gz" \
|
|
-H "$AUTH" \
|
|
-F "attachment=@/tmp/docs.tar.gz"
|
|
|
|
echo "Release ${TAG} created with docs.tar.gz"
|