Update Release Redirects #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Release Redirects | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| jobs: | |
| update-redirects: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Git user | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| - name: Create gh-pages branch if it doesn't exist | |
| run: | | |
| git fetch origin | |
| if ! git ls-remote --heads origin gh-pages | grep gh-pages; then | |
| git checkout -b gh-pages | |
| git push -u origin gh-pages | |
| else | |
| git checkout gh-pages | |
| fi | |
| - name: Get latest Android release | |
| id: android_release | |
| uses: octokit/[email protected] | |
| with: | |
| route: GET /repos/{owner}/{repo}/releases | |
| owner: ${{ github.repository_owner }} | |
| repo: ${{ github.event.repository.name }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get latest Desktop release | |
| id: desktop_release | |
| uses: octokit/[email protected] | |
| with: | |
| route: GET /repos/{owner}/{repo}/releases | |
| owner: ${{ github.repository_owner }} | |
| repo: ${{ github.event.repository.name }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create redirect pages | |
| run: | | |
| mkdir -p releases | |
| # Extract latest Android release URL | |
| ANDROID_RELEASE_URL=$(echo '${{ steps.android_release.outputs.data }}' | jq -r '.[] | select(.tag_name | startswith("android-")) | .html_url' | head -n 1) | |
| # Extract latest Desktop release URL | |
| DESKTOP_RELEASE_URL=$(echo '${{ steps.desktop_release.outputs.data }}' | jq -r '.[] | select(.tag_name | startswith("desktop-")) | .html_url' | head -n 1) | |
| # Create Android redirect page | |
| cat > releases/android.html << EOF | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="refresh" content="0; url=$ANDROID_RELEASE_URL"> | |
| <title>Redirecting to latest Android release</title> | |
| </head> | |
| <body> | |
| <p>Redirecting to <a href="$ANDROID_RELEASE_URL">latest Android release</a>...</p> | |
| </body> | |
| </html> | |
| EOF | |
| # Create Desktop redirect page | |
| cat > releases/desktop.html << EOF | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="refresh" content="0; url=$DESKTOP_RELEASE_URL"> | |
| <title>Redirecting to latest Desktop release</title> | |
| </head> | |
| <body> | |
| <p>Redirecting to <a href="$DESKTOP_RELEASE_URL">latest Desktop release</a>...</p> | |
| </body> | |
| </html> | |
| EOF | |
| # Create index page | |
| cat > index.html << EOF | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>TrailRunning App Releases</title> | |
| <style> | |
| body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } | |
| h1 { color: #2c3e50; } | |
| .button { display: inline-block; background-color: #3498db; color: white; padding: 10px 20px; | |
| text-decoration: none; border-radius: 5px; margin: 10px 5px; } | |
| .button:hover { background-color: #2980b9; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>TrailRunning App Releases</h1> | |
| <p>Access the latest releases of our applications:</p> | |
| <a class="button" href="releases/android.html">Latest Android Release</a> | |
| <a class="button" href="releases/desktop.html">Latest Desktop Release</a> | |
| </body> | |
| </html> | |
| EOF | |
| - name: Commit and push changes | |
| run: | | |
| git add releases/android.html releases/desktop.html index.html | |
| git commit -m "Update release redirect pages" || echo "No changes to commit" | |
| git push origin gh-pages |