-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run ephemeral instances every few hours
- Loading branch information
1 parent
f986429
commit 356d5c6
Showing
2 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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