Skip to content

lets go

lets go #61

Workflow file for this run

name: Build and Deploy Plot
# Only push when a new file is available or the plotter script has been updated
on:
push:
paths:
- "data/*.csv"
- "data/*.parquet"
- "main.py"
permissions:
contents: write
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install numpy pandas pyarrow plotly
- name: Ensure output directory exists
run: mkdir -p output
- name: Detect changed data files
id: changed
run: |
# Handle first-commit edge case
if [ "$(git rev-list --count HEAD)" -eq 1 ]; then
echo "No parent commit, skipping diff."
echo "changed=" >> $GITHUB_OUTPUT
exit 0
fi
# Get changed CSV or Parquet files (each on its own line)
changed=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(csv|parquet)$' || true)
echo "Changed files:"
while IFS= read -r file; do
echo " - $file"
done <<< "$changed"
# Convert newlines → spaces *only* for the GitHub output variable
changed_space=$(echo "$changed" | tr '\n' ' ')
echo "changed=$changed_space" >> $GITHUB_OUTPUT
- name: Run plot generator on changed files
if: ${{ steps.changed.outputs.changed != '' }}
run: |
echo "Detected changed files:"
echo ${{ steps.changed.outputs.changed }}
for file in ${{ steps.changed.outputs.changed }}; do
echo "Plotting $file"
python main.py "$file"
done
- name: Compress HTML in output/
run: |
if ls output/*.html 1> /dev/null 2>&1; then
gzip -kf output/*.html
fi
- name: Commit generated output files
if: ${{ steps.changed.outputs.changed != '' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add and commit any changes in output/
git add output || echo "No HTML files to add"
git diff --cached --quiet && echo "No changes to commit" || git commit -m "Add generated plots [skip ci]"
# Push changes back to main branch
git push origin HEAD:main
- name: Generate index.html for GitHub Pages
run: |
echo "<html><head><title>Simple Data Plotter - Index</title></head><body>" > index.html
echo "<h1>da plots</h1>" >> index.html
echo "<p>plots:</p><ul>" >> index.html
# Loop through only *.html (exclude index itself)
shopt -s nullglob
for file in output/*.html; do
file_name=$(basename "$file")
if [ "$file_name" != "index.html" ]; then
echo "<li><a href='output/$file_name'>$file_name</a></li>" >> index.html
fi
done
echo "</ul>" >> index.html
# ---- PDF viewer embed ----
if [ -f PSPL_CMS_MASTER_11012025.pdf ]; then
echo "<h2>CMS Master P&ID</h2>" >> index.html
echo "<iframe src='PSPL_CMS_MASTER_11012025.pdf' width='100%' height='800px'></iframe>" >> index.html
else
echo "<p>No PDF found.</p>" >> index.html
fi
# --------------------------
echo "</body></html>" >> index.html
- name: Upload artifact for GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: .
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deploy-pages.outputs.page_url }}
steps:
- name: Deploy GitHub Pages
id: deploy-pages
uses: actions/deploy-pages@v4