clean shit up #53
This file contains hidden or 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
| 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>" > output/index.html | |
| echo "<h1>da plots</h1>" >> output/index.html | |
| echo "<p>plots:</p><ul>" >> output/index.html | |
| # Loop through only *.html (exclude index itself) | |
| shopt -s nullglob | |
| for file in output/*.html; do | |
| fname=$(basename "$file") | |
| # skip index.html itself | |
| if [ "$fname" != "index.html" ]; then | |
| echo "<li><a href='$fname'>$fname</a></li>" >> output/index.html | |
| fi | |
| done | |
| echo "</ul></body></html>" >> output/index.html | |
| - name: Upload artifact for GitHub Pages | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: output/ | |
| 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 |