Repository navigation
78 lines (71 loc) · 3.06 KB
/
Copy pathgenerate-html.yml
File metadata and controls
78 lines (71 loc) · 3.06 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
name: Generate index.html from SPEC.md
on:
issue_comment:
types: [created]
permissions:
contents: write
pull-requests: write
models: read
jobs:
generate:
# Only run when a maintainer comments "/generate" on a PR
if: >
github.event.issue.pull_request &&
contains(github.event.comment.body, '/generate') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
runs-on: ubuntu-latest
steps:
- name: Get PR details
id: pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }})
echo "head_sha=$(echo "$PR_JSON" | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
echo "head_ref=$(echo "$PR_JSON" | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
echo "head_repo=$(echo "$PR_JSON" | jq -r '.head.repo.full_name')" >> "$GITHUB_OUTPUT"
echo "base_repo=$(echo "$PR_JSON" | jq -r '.base.repo.full_name')" >> "$GITHUB_OUTPUT"
echo "maintainer_can_modify=$(echo "$PR_JSON" | jq -r '.maintainer_can_modify')" >> "$GITHUB_OUTPUT"
- name: Refuse forks without maintainer edits
if: steps.pr.outputs.head_repo != steps.pr.outputs.base_repo && steps.pr.outputs.maintainer_can_modify != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment "${{ github.event.issue.number }}" --repo "${{ github.repository }}" \
--body "Cannot generate on a fork PR without \"Allow edits from maintainers\" enabled. Please enable it on the PR and re-run \`/generate\`."
exit 1
- name: Checkout PR head
uses: actions/checkout@v5
with:
repository: ${{ steps.pr.outputs.head_repo }}
ref: ${{ steps.pr.outputs.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Generate index.html
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
run: bash .github/scripts/generate-html.sh
- name: Commit and push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
run: |
if git diff --quiet -- index.html; then
gh pr comment "$PR_NUMBER" --repo "$REPO" \
--body "\`/generate\` produced no changes to \`index.html\`."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add index.html
git commit -m "Regenerate index.html from SPEC.md (/generate)"
git push
gh pr comment "$PR_NUMBER" --repo "$REPO" \
--body "Regenerated \`index.html\` from \`SPEC.md\`. Please review the diff."