Skip to content

Commit dff3c60

Browse files
committed
update
1 parent 90a87a6 commit dff3c60

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

.github/workflows/codestate-pr-report.yml

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ jobs:
1919
with:
2020
fetch-depth: 0
2121

22+
- name: Fetch gh-pages branch (if exists)
23+
uses: actions/checkout@v4
24+
continue-on-error: true
25+
with:
26+
ref: gh-pages
27+
path: ghp
28+
2229
- name: Set up Python
2330
uses: actions/setup-python@v5
2431
with:
@@ -31,7 +38,7 @@ jobs:
3138
run: |
3239
python tools/codestate_pr_report.py
3340
34-
- name: Build Pages content
41+
- name: Build Pages content (index + history)
3542
env:
3643
PR_NUMBER: ${{ github.event.pull_request.number }}
3744
GITHUB_SHA: ${{ github.sha }}
@@ -57,29 +64,53 @@ jobs:
5764
if [ -f codestate_pr_report.json ]; then
5865
cp codestate_pr_report.json "$OUTDIR/$SUBPATH/codestate_pr_report.json"
5966
fi
60-
# Minimal landing index pointing to this run's page
61-
cat > "$OUTDIR/index.html" << 'HTML'
62-
<!doctype html>
63-
<html lang="en"><head><meta charset="utf-8" />
64-
<meta name="viewport" content="width=device-width, initial-scale=1" />
65-
<title>CodeState Reports</title>
66-
<style>body{font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;padding:24px;line-height:1.5}a{color:#2563eb}</style>
67-
</head><body>
68-
<h2>CodeState PR Reports</h2>
69-
<p>This site hosts the latest generated PR report for this run.</p>
70-
<p><a id="runLink" href="SUBPATH_PLACEHOLDER/">Open this run's report</a></p>
71-
<p>Looking for older runs? Use the URL pattern: <code>/reports/pr-&lt;number&gt;/sha-&lt;short&gt;/</code></p>
72-
</body></html>
73-
HTML
74-
# Inject subpath
75-
sed -i "s|SUBPATH_PLACEHOLDER|$SUBPATH|g" "$OUTDIR/index.html"
67+
# Build history list from existing gh-pages (if available)
68+
HISTORY_FILE_MD="$OUTDIR/history.md"
69+
echo "# CodeState Report History" > "$HISTORY_FILE_MD"
70+
echo >> "$HISTORY_FILE_MD"
71+
echo "Browse all published reports. Newest first." >> "$HISTORY_FILE_MD"
72+
echo >> "$HISTORY_FILE_MD"
73+
# Collect existing entries
74+
if [ -d ghp/reports ]; then
75+
# shellcheck disable=SC2012
76+
EXISTING_INDEXES=$(find ghp/reports -type f -name index.html | sort -r)
77+
while IFS= read -r path; do
78+
rel=${path#ghp/}
79+
# rel like reports/pr-123/sha-abc/index.html
80+
dir=$(dirname "$rel")
81+
base=$(basename "$dir")
82+
parent=$(basename "$(dirname "$dir")")
83+
if [[ "$parent" == pr-* ]]; then
84+
prnum=${parent#pr-}
85+
label="PR #$prnum ($base)"
86+
else
87+
label="Manual ($base)"
88+
fi
89+
echo "- [$label](/$dir/)" >> "$HISTORY_FILE_MD"
90+
done <<< "$EXISTING_INDEXES"
91+
fi
92+
# Add current run at the top
93+
echo "- [Current Run](/$SUBPATH/)" | cat - "$HISTORY_FILE_MD" > "$HISTORY_FILE_MD.tmp" && mv "$HISTORY_FILE_MD.tmp" "$HISTORY_FILE_MD"
94+
95+
# Build index.md from root README plus quick links
96+
INDEX_MD="$OUTDIR/index.md"
97+
echo "<!-- Auto-generated by workflow -->" > "$INDEX_MD"
98+
echo "[Open latest report](/$SUBPATH/) · [History](/history.html)" >> "$INDEX_MD"
99+
echo >> "$INDEX_MD"
100+
echo >> "$INDEX_MD"
101+
if [ -f README.md ]; then
102+
cat README.md >> "$INDEX_MD"
103+
else
104+
echo "# CodeState\n\nSee [history](/history) for all reports." >> "$INDEX_MD"
105+
fi
76106
77107
- name: Publish to gh-pages
78108
uses: peaceiris/actions-gh-pages@v3
79109
with:
80110
github_token: ${{ secrets.GITHUB_TOKEN }}
81111
publish_branch: gh-pages
82112
publish_dir: ./site
113+
enable_jekyll: true
83114
keep_files: true
84115

85116
- name: Upload HTML artifact

0 commit comments

Comments
 (0)