-
Notifications
You must be signed in to change notification settings - Fork 4
98 lines (80 loc) · 2.77 KB
/
update-cli-docs.yml
File metadata and controls
98 lines (80 loc) · 2.77 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Update CLI Docs
on:
schedule:
- cron: "0 8 * * 1"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
env:
BRANCH: actions/update-cli-docs
jobs:
update-cli-docs:
name: Update CLI Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- uses: pnpm/action-setup@v4
with:
version: latest
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Sprites CLI
run: |
curl -fsSL https://sprites.dev/install.sh | bash
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Sprites auth
run: sprite auth setup --token "$SPRITES_TEST_TOKEN"
env:
SPRITES_TEST_TOKEN: ${{ secrets.SPRITES_TEST_TOKEN }}
- name: Generate CLI Docs
run: pnpm generate:cli-docs
- name: Check for changes
id: changes
run: |
if git diff --quiet src/content/docs/cli/commands.mdx
then
echo "changed=false" >> $GITHUB_OUTPUT
echo "CLI docs are already up to date."
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Updated CLI docs"
git diff src/content/docs/cli/commands.mdx
fi
- name: Commit and push to automated branch
if: steps.changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$BRANCH"
git add src/content/docs/cli/commands.mdx
git commit -m "Update auto-generated CLI documentation ($(date -u +%Y-%m-%d))"
git push origin "$BRANCH" --force
- name: Open or update PR
if: steps.changes.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat > /tmp/pr-body.md << EOF
Built from $(sprite --version) on $(date -u +%Y-%m-%d)
> *Generated by the weekly CLI docs update workflow. This PR is automatically updated when new releases are available.*
EOF
pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
if test -z "$pr"
then
gh pr create \
--title "Update auto-generated CLI documentation" \
--body-file /tmp/pr-body.md \
--head "$BRANCH" \
--base main
else
gh pr edit "$pr" --body-file /tmp/pr-body.md
echo "Updated existing PR #$pr"
fi