Loading files
name: Deploy to GitHub Pages
on:
push:
branches:
- dev
paths:
- static/**
- .github/workflows/gh-pages.yml
release:
types:
- published
- unpublished
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.13"
- name: Install requests
run: |
python -m pip install --upgrade pip
pip install requests
- name: Fetch releases and update HTML
shell: python
run: |
import datetime
import os
import requests
import re
repo = os.getenv('GITHUB_REPOSITORY')
event_name = os.getenv('GITHUB_EVENT_NAME', 'unknown')
run_id = os.getenv('GITHUB_RUN_ID', 'unknown')
ref = os.getenv('GITHUB_REF', 'unknown')
timestamp = datetime.datetime.now().isoformat()
run_url = f"https://github.com/{repo}/actions/runs/{run_id}"
api_url = f'https://api.github.com/repos/{repo}/releases'
response = requests.get(api_url)
releases = response.json()
# create <option> elements for <select> list
releases_options = ""
for release in releases:
release_name = release['name'] if release['name'] else release['tag_name']
release_description = " (pre-release)" if release['prerelease'] else ""
releases_options += f'<option value="{release_name}">{release_name}{release_description}</option>\n'
# replace <option> elements inside <select id="releases">...</select>
html_file_path = 'static/index.html'
with open(html_file_path, 'r') as file:
html_content = file.read()
html_content = re.sub(
r'(<select id="releases">).*?(</select>)',
f'\\1{releases_options}\\2',
html_content,
flags=re.DOTALL
)
# add metadata to beginning of HTML file
metadata = f"<!-- created: {timestamp} -->\n"
metadata += f"<!-- CI/CD run: {run_url} -->\n"
metadata += f"<!-- triggered by: {event_name} -->\n"
metadata += f"<!-- branch/tag: {ref} -->\n"
html_content = metadata + html_content
# write updated content back to the file
with open(html_file_path, 'w') as file:
file.write(html_content)
- name: Upload artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: static
retention-days: 1
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
steps:
- name: Setup Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0
8fd9da023This file is pinned to the selected release. Download the original to open it in your design tool.