-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (114 loc) · 4.13 KB
/
plot_new_data.yml
File metadata and controls
146 lines (114 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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" || echo "Plotting $file failed, continuing..."
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
echo "<p>old plotter: <a href="pspl.dataviewer.space">pspl.dataviewer.space</a></p> <ul>" >> index.html
# ---- PDF viewer embed ----
if [ -f PSPL_CMS_MASTER_11192025.pdf ]; then
echo "<h2>CMS Master P&ID</h2>" >> index.html
echo "<iframe src='PSPL_CMS_MASTER_11192025.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