Skip to content

Commit f310150

Browse files
committed
ci: auto-update README.md on pull requests
Add an update-readme job that regenerates README.md and pushes a fix commit to same-repo PRs when it's out of date. The lint-test job is skipped when a fix is pushed, since the new commit re-triggers CI. Fork PRs are unaffected — the job is skipped and the existing diff check in lint-test still catches stale READMEs. This primarily targets Renovate PRs, which often update dependencies without updating the README. The job is generic enough to be useful for other PRs as well, though. Signed-off-by: Tom Hayward <thayward@infoblox.com>
1 parent db5d1b8 commit f310150

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

.github/workflows/lint-test.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,42 @@ on:
44
pull_request:
55

66
jobs:
7+
update-readme:
8+
# Only runs on PRs from the same repo (not forks), where the CI token can push.
9+
if: github.event.pull_request.head.repo.full_name == github.repository
10+
runs-on: ubuntu-latest
11+
outputs:
12+
updated: ${{ steps.commit.outputs.updated }}
13+
steps:
14+
- name: Checkout PR branch
15+
uses: actions/checkout@v6
16+
with:
17+
token: ${{ secrets.CORTEX_HELM_CHART_CI_TOKEN }}
18+
ref: ${{ github.event.pull_request.head.ref }}
19+
fetch-depth: 0
20+
21+
- name: Regenerate README.md
22+
run: make README.md
23+
24+
- name: Commit and push if changed
25+
id: commit
26+
run: |
27+
if git diff --quiet -- README.md; then
28+
echo "updated=false" >> "$GITHUB_OUTPUT"
29+
else
30+
git config user.name "github-actions[bot]"
31+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
32+
git add README.md
33+
git commit -m "Auto-update README.md"
34+
git push
35+
echo "updated=true" >> "$GITHUB_OUTPUT"
36+
fi
37+
738
lint-test:
39+
needs: update-readme
40+
# Run unless update-readme pushed a new commit (which will re-trigger CI).
41+
# Also runs when update-readme is skipped (fork PRs) or fails unexpectedly.
42+
if: "!cancelled() && needs.update-readme.outputs.updated != 'true'"
843
runs-on: ubuntu-latest
944
steps:
1045
- name: Checkout
@@ -30,7 +65,7 @@ jobs:
3065
- name: Run chart-testing (lint)
3166
run: ct lint --config ct.yaml
3267

33-
- name: Updated README.md
68+
- name: Check README.md is up to date
3469
run: |
3570
make README.md
3671
git diff --exit-code -- README.md

0 commit comments

Comments
 (0)