Skip to content

Deploy Redirect to GitHub Pages #12

Deploy Redirect to GitHub Pages

Deploy Redirect to GitHub Pages #12

Workflow file for this run

name: Deploy Redirect to GitHub Pages
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set Up Git Configuration
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
- name: Set up Python 3.11
id: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install AWS CLI
run: |
pip install awscli awscli-local
- name: Run Ephemeral Script and Capture Output
run: |
OUTPUT=$(bash bin/ephemeral.sh 2>&1)
echo "$OUTPUT"
NEW_URL=$(echo "$OUTPUT" | grep -Eo 'https://ls-[^ ]+')
if [ -z "$NEW_URL" ]; then
echo "Error: Failed to extract URL from script output."
exit 1
fi
echo "Extracted URL: $NEW_URL"
echo "NEW_URL=$NEW_URL" >> $GITHUB_ENV
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
- name: Generate index.html with New Redirect URL
run: |
NEW_URL="${{ env.NEW_URL }}"
# Validate the URL
if [[ ! "$NEW_URL" =~ ^https?:// ]]; then
echo "Error: Invalid URL provided."
exit 1
fi
echo "Redirecting to: $NEW_URL"
cat > index.html <<EOL
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; URL=${NEW_URL}">
<title>Redirecting...</title>
</head>
<body>
<p>If you are not redirected automatically, follow this <a href="${NEW_URL}">link</a>.</p>
</body>
</html>
EOL
- name: Switch to gh-pages Branch and Commit Changes
run: |
git fetch origin gh-pages || echo "gh-pages branch does not exist; creating it."
git checkout gh-pages || git checkout --orphan gh-pages
git rm -rf . # Remove all files in the branch
git add index.html
git commit -m "Update redirect to ${NEW_URL}"
git push origin gh-pages --force