forked from serverpod/serverpod
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (128 loc) · 5.38 KB
/
Copy pathsync-cli-docs.yml
File metadata and controls
145 lines (128 loc) · 5.38 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Sync CLI Docs to Serverpod Docs
# After framework CLI changes land on main, regenerate the serverpod command
# reference docs and open (or refresh) a single rolling PR in the serverpod_docs
# repository.
on:
push:
branches:
- main
paths:
- "tools/serverpod_cli/lib/src/commands/**"
- "tools/serverpod_cli/lib/src/runner/**"
- "tools/serverpod_cli/bin/**"
- "tools/serverpod_cli/scripts/generate_command_usages.dart"
- ".github/actions/retry/**"
- ".github/actions/use-dart-only-workspace/**"
- ".github/actions/use-dart-test-retry/**"
- ".github/workflows/sync-cli-docs.yml"
workflow_dispatch:
permissions:
contents: read
# Only one sync at a time so the rolling branch is never updated concurrently.
concurrency:
group: sync-cli-docs
cancel-in-progress: false
env:
DOCS_REPOSITORY: serverpod/serverpod_docs
# Distinct from the Cloud bot's `auto/cli-docs-sync` branch on the same repo.
SYNC_BRANCH: auto/framework-cli-docs-sync
CLI_DOCS_PATH: docs/06-concepts/cli
jobs:
sync:
name: Sync CLI Docs
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ secrets.DOCS_SYNC_APP_CLIENT_ID }}
private-key: ${{ secrets.DOCS_SYNC_APP_PRIVATE_KEY }}
owner: serverpod
repositories: serverpod_docs
- name: Checkout Serverpod Repo
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
path: src
- name: Use Dart-only workspace
uses: ./src/.github/actions/use-dart-only-workspace
with:
workspace-root: src
# serverpod_cli is a pure Dart package, so the Dart SDK is all we need.
# (Most monorepo workflows pull Flutter only because their packages need
# it.)
- name: Set up Dart
uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260 # v1.7.2
with:
sdk: stable
- name: Retry transient Dart build-hook failures
uses: ./src/.github/actions/use-dart-test-retry
- name: Resolve serverpod_cli dependencies
uses: ./src/.github/actions/retry
with:
command: dart pub get
working_directory: src/tools/serverpod_cli
- name: Checkout Serverpod Docs Repo
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
path: target
ref: main
repository: ${{ env.DOCS_REPOSITORY }}
# persist-credentials (default true) embeds the app token so
# `git push` to the docs repo authenticates.
token: ${{ steps.app-token.outputs.token }}
- name: Generate CLI docs
working-directory: src/tools/serverpod_cli
run: >
dart run scripts/generate_command_usages.dart
"${{ github.workspace }}/target/${{ env.CLI_DOCS_PATH }}"
- name: Detect changes in Serverpod Docs
id: check_changes
working-directory: target
run: |
git add -- "$CLI_DOCS_PATH"
git diff --cached --quiet || CHANGED=true
if [ "$CHANGED" == true ]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
fi
- name: Push changes to Serverpod Docs
if: steps.check_changes.outputs.changes_detected == 'true'
working-directory: target
run: |
git config --global user.email "serverpod@serverpod.dev"
git config --global user.name "serverpod"
git checkout -B "$SYNC_BRANCH"
git commit -m "docs: Update framework CLI command reference (serverpod@${GITHUB_SHA::7})"
git push --force origin "$SYNC_BRANCH"
- name: Create PR in Serverpod Docs
if: steps.check_changes.outputs.changes_detected == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
EXISTING_PR=$(gh pr list --repo "$DOCS_REPOSITORY" --head "$SYNC_BRANCH" --state open --json number --jq '.[0].number')
if [ -n "$EXISTING_PR" ]; then
echo "PR #$EXISTING_PR already open; branch \"$SYNC_BRANCH\" was force-updated."
else
gh pr create \
--repo "$DOCS_REPOSITORY" \
--base main \
--head "$SYNC_BRANCH" \
--title "docs: Update framework CLI command reference" \
--body "$(cat << EOF
Auto-generated update of the framework CLI command reference docs from the
command definitions in \`serverpod\`.
Triggered by: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
> This branch (\`$SYNC_BRANCH\`) is force-updated on every relevant push to
> \`main\`, so always review the latest diff. Do not push manual commits to it —
> they will be overwritten. Curated command intros (\`_<command>.md\`) are
> maintained directly on \`main\` and are preserved by the generator.
EOF
)"
fi
# Merge automatically once all required checks and reviews on the
# docs repo have passed. (A force-push disables a previously enabled
# auto-merge, so this is re-enabled on every sync.)
gh pr merge "$SYNC_BRANCH" \
--repo "$DOCS_REPOSITORY" \
--auto \
--squash