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 | |
| 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: 2 | |
| 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 | |
| changed=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(csv|parquet)$' || true) | |
| changed=$(echo "$changed" | tr '\n' ' ') # 👈 convert newlines to spaces | |
| echo "Changed files: $changed" | |
| echo "changed=$changed" >> $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 -k 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/*.html output/*.html.gz || 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: 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 |