Repository navigation
80 lines (71 loc) · 2.69 KB
/
Copy pathupdate-github-code.yml
File metadata and controls
80 lines (71 loc) · 2.69 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
79
80
name: Update GitHub code examples
on:
workflow_dispatch:
schedule:
- cron: '0 10 * * 1'
concurrency:
group: update-github-code
cancel-in-progress: false
jobs:
update-examples:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
copilot-requests: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Test sync script
run: node --test scripts/sync-github-code.test.mjs
- name: Refresh code examples
id: sync
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p .tmp
status=0
node scripts/sync-github-code.mjs > .tmp/github-code-sync.log 2>&1 || status=$?
cat .tmp/github-code-sync.log
if [ "$status" -ne 0 ] || ! git diff --quiet -- '*.mdx'; then
echo "repair=true" >> "$GITHUB_OUTPUT"
fi
- name: Install Copilot CLI
if: steps.sync.outputs.repair == 'true'
run: npm install -g @github/copilot
- name: Repair excerpts and explanations with Copilot
if: steps.sync.outputs.repair == 'true'
env:
GH_TOKEN: ${{ github.token }}
COPILOT_GITHUB_TOKEN: ${{ github.token }}
run: |
copilot -p "$(cat .github/prompts/update-github-code.md)" \
--allow-tool=write \
--allow-tool='shell(git diff:*)' \
--allow-tool='shell(git show:*)' \
--allow-tool='shell(gh api:*)' \
--allow-tool='shell(node scripts/sync-github-code.mjs:*)'
- name: Validate updated documentation
if: steps.sync.outputs.repair == 'true'
run: |
git diff --check
git diff --quiet -- scripts .github
npx --yes mint@4.2.666 validate
- name: Open PR if changed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b update-github-code
git add -- '*.mdx'
git diff --staged --quiet && exit 0
git commit -m "chore(docs): update GitHub code examples"
git push origin update-github-code --force
if [ "$(gh pr list --head update-github-code --state open --json number --jq length)" = "0" ]; then
gh pr create --title "chore(docs): update GitHub code examples" \
--body "Refresh embedded code and commit-pinned source links from GitHub. Review the excerpts against their surrounding explanations before merging." \
--head update-github-code
fi