Skip to content

Commit

Permalink
run ephemeral instances every few hours
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshCasper committed Oct 28, 2024
1 parent f986429 commit 356d5c6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
92 changes: 92 additions & 0 deletions .github/workflows/ephemeral.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Deploy Redirect to GitHub Pages

on:
schedule:
- cron: '0 */2 * * *'
workflow_dispatch:
push:
branches:
- main

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
1 change: 0 additions & 1 deletion bin/ephemeral.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ else
fi

ENDPOINT_URL=$(echo "$CREATE_RESPONSE" | jq -r '.endpoint_url')
echo "Endpoint URL: $ENDPOINT_URL"

export AWS_ENDPOINT_URL="$ENDPOINT_URL"
export ENDPOINT_URL="$ENDPOINT_URL"
Expand Down

0 comments on commit 356d5c6

Please sign in to comment.