Skip to content

Commit e7924bd

Browse files
committed
make the workflow regen the readme as part of the PR, not when merging to main
1 parent 6a8fbc5 commit e7924bd

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

.github/workflows/hype.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: Generate README with Hype
22
on:
3-
push:
4-
branches:
5-
- main
3+
pull_request:
4+
types: [opened, synchronize, reopened]
65
jobs:
76
build:
87
runs-on: ubuntu-latest
8+
permissions:
9+
contents: write
10+
pull-requests: write
911
steps:
1012
- uses: actions/checkout@v4
1113
with:
12-
repository: ${{ github.event.pull_request.head.repo.full_name }}
13-
ref: ${{ github.event.pull_request.head.ref }}
14+
ref: ${{ github.head_ref }}
1415
- name: Set up Go
1516
uses: actions/setup-go@v4
1617
with:
@@ -20,10 +21,15 @@ jobs:
2021
run: go install github.com/gopherguides/hype/cmd/hype@latest
2122
- name: Run hype
2223
run: hype export -format=markdown -f hype.md -o README.md
23-
- name: Commit README back to the repo
24-
run: |-
25-
git rev-parse --abbrev-ref HEAD
26-
git config user.name 'GitHub Actions'
27-
git config user.email '[email protected]'
28-
git diff --quiet || (git add README.md && git commit -am "Updated README")
29-
git push origin ${{github.event.pull_request.head.ref}}
24+
- name: Check for changes
25+
id: git-check
26+
run: |
27+
git diff --quiet README.md || echo "changed=true" >> $GITHUB_OUTPUT
28+
- name: Commit README changes if any
29+
if: steps.git-check.outputs.changed == 'true'
30+
run: |
31+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
32+
git config --local user.name "github-actions[bot]"
33+
git add README.md
34+
git commit -m "Update README.md with latest Hype changes"
35+
git push

0 commit comments

Comments
 (0)