Add GitHub Action to run doctools.py on pull requests and commit data changes#1070
Add GitHub Action to run doctools.py on pull requests and commit data changes#1070
Conversation
Co-authored-by: sei-renae <190382933+sei-renae@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds CI enforcement to run ssvc.doctools on pull requests that modify src/ssvc/**, with the intent of ensuring regenerated data/ artifacts are committed before merge.
Changes:
- Introduces a new GitHub Actions workflow to run
python -m ssvc.doctools --overwrite --datadir ./dataon relevant PRs. - Removes existing
data/json/decision_pointsprior to regeneration to avoid stale outputs. - Attempts to auto-commit and push any resulting
data/changes back to the PR branch.
| - uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Python 3.12 | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip uv | ||
| uv sync --dev --frozen | ||
|
|
||
| - name: Run doctools | ||
| run: | | ||
| # Remove stale decision point files so doctools generates a clean set | ||
| rm -rf data/json/decision_points | ||
| export PYTHONPATH=$(pwd)/src | ||
| uv run python -m ssvc.doctools --overwrite --datadir ./data | ||
|
|
||
| - name: Commit changes to data/ | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add data/ | ||
| if git diff --cached --quiet; then | ||
| echo "No changes to commit" | ||
| else | ||
| git commit -m "chore: regenerate data files via doctools [skip ci]" | ||
| git push | ||
| fi |
There was a problem hiding this comment.
This checkout/push approach won’t work for pull requests from forks: ref: ${{ github.head_ref }} points to a branch name in the base repo, and git push with GITHUB_TOKEN cannot push back to a fork. As written, the workflow is likely to fail (or block) on external contributor PRs. Consider checking out the PR SHA/merge ref for running doctools, and then conditionally doing the commit/push only when github.event.pull_request.head.repo.full_name == github.repository; for forks, fail with a clear message telling the contributor to run doctools locally and commit data/ changes.
| - name: Commit changes to data/ | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add data/ | ||
| if git diff --cached --quiet; then | ||
| echo "No changes to commit" | ||
| else | ||
| git commit -m "chore: regenerate data files via doctools [skip ci]" | ||
| git push |
There was a problem hiding this comment.
Using [skip ci] on the auto-generated commit can prevent other required PR checks from re-running on the updated data/ state, leaving the PR green based on an older commit. A safer pattern is to avoid [skip ci] and instead prevent recursion by skipping this job/commit step when github.actor is github-actions[bot] (or by checking the last commit author/message), so the rest of the CI still runs on the final commit.
Independent contributors rely on local git hooks to run
src/ssvc/doctools.pywhensrc/ssvc/*changes. This adds a CI enforcement step so PRs always regenerate and commit updateddata/files before merging.Changes
.github/workflows/run_doctools.yml— new workflow that:src/ssvc/**uv, clears staledata/json/decision_points/, then runspython -m ssvc.doctools --overwrite --datadir ./datadata/changes back to the PR branch with[skip ci]to prevent recursion; no-ops if nothing changedOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.