|
| 1 | +name: Docs Release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 6 * * *' # Daily at 6:00 AM UTC |
| 6 | + workflow_dispatch: # Allow manual trigger for first run after PR approval |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Check if docs have changed since last release |
| 22 | + id: changes |
| 23 | + run: | |
| 24 | + # On manual dispatch (first run), always build |
| 25 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 26 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 27 | + echo "First run (manual dispatch) — building unconditionally." |
| 28 | + exit 0 |
| 29 | + fi |
| 30 | +
|
| 31 | + # For scheduled runs, check if docs/ or html/docs/ changed in the last 24 hours |
| 32 | + LAST_CHANGE=$(git log --since="24 hours ago" --format="%H" -- docs/ html/docs/ | head -1) |
| 33 | + if [ -n "$LAST_CHANGE" ]; then |
| 34 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 35 | + echo "Changes detected in docs/ or html/docs/." |
| 36 | + else |
| 37 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 38 | + echo "No changes detected — skipping release." |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Set date tag |
| 42 | + if: steps.changes.outputs.changed == 'true' |
| 43 | + id: date |
| 44 | + run: | |
| 45 | + DATE=$(date -u +"%Y-%m-%d") |
| 46 | + echo "date=$DATE" >> "$GITHUB_OUTPUT" |
| 47 | + echo "tag=v$DATE" >> "$GITHUB_OUTPUT" |
| 48 | + echo "zip_name=Git-Going-With-Git-$DATE.zip" >> "$GITHUB_OUTPUT" |
| 49 | +
|
| 50 | + - name: Create zip of docs and html/docs |
| 51 | + if: steps.changes.outputs.changed == 'true' |
| 52 | + run: | |
| 53 | + zip -r "${{ steps.date.outputs.zip_name }}" docs/ html/docs/ |
| 54 | +
|
| 55 | + - name: Delete existing release for today if it exists |
| 56 | + if: steps.changes.outputs.changed == 'true' |
| 57 | + run: | |
| 58 | + gh release delete "${{ steps.date.outputs.tag }}" --yes --cleanup-tag 2>/dev/null || true |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Create GitHub release |
| 63 | + if: steps.changes.outputs.changed == 'true' |
| 64 | + run: | |
| 65 | + gh release create "${{ steps.date.outputs.tag }}" \ |
| 66 | + "${{ steps.date.outputs.zip_name }}" \ |
| 67 | + --title "Docs Release ${{ steps.date.outputs.date }}" \ |
| 68 | + --notes "Daily docs release for ${{ steps.date.outputs.date }}. Contains docs/ (Markdown) and html/docs/ (HTML)." \ |
| 69 | + --latest |
| 70 | + env: |
| 71 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + - name: Clean up old releases (keep last 10) |
| 74 | + if: steps.changes.outputs.changed == 'true' |
| 75 | + run: | |
| 76 | + # List all releases sorted by date (newest first), skip the first 10 |
| 77 | + RELEASES_TO_DELETE=$(gh release list --limit 100 --json tagName,createdAt \ |
| 78 | + --jq 'sort_by(.createdAt) | reverse | .[10:] | .[].tagName' \ |
| 79 | + | grep -E '^v[0-9]{4}-[0-9]{2}-[0-9]{2}$' || true) |
| 80 | +
|
| 81 | + if [ -z "$RELEASES_TO_DELETE" ]; then |
| 82 | + echo "No old releases to clean up." |
| 83 | + else |
| 84 | + for TAG in $RELEASES_TO_DELETE; do |
| 85 | + echo "Deleting release $TAG..." |
| 86 | + gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true |
| 87 | + done |
| 88 | + fi |
| 89 | + env: |
| 90 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments