Skip to content

Commit f332c69

Browse files
committed
ci: semi-automate cli docs generation
Adds a workflow that automates updating the CLI docs, opening a PR with the updates for manual review. It's running against nightly versions right now just as a POC, will switch it over to release versions once I'm happy that it works.
1 parent 4eabbe3 commit f332c69

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: "Update Generated Docs"
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# every day at 2am UTC
7+
- cron: "0 2 * * *"
8+
9+
permissions: {}
10+
11+
jobs:
12+
update_generated_docs:
13+
runs-on: ubuntu-latest
14+
environment: Docs generation
15+
permissions:
16+
contents: write
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
ref: main
21+
22+
- run: |
23+
git clone https://github.com/gitbutlerapp/gitbutler ../gitbutler
24+
25+
- name: Compare versions
26+
id: versions
27+
run: |
28+
CURRENT_DOCS_VERSION=$(cat scripts/current_docs_version.txt)
29+
LATEST_VERSION=$(git -C ../gitbutler tag --list 'nightly/*' --sort=-version:refname | head -n 1)
30+
31+
echo "Current: $CURRENT_DOCS_VERSION"
32+
echo "Latest: $LATEST_VERSION"
33+
34+
test -n "$LATEST_VERSION"
35+
36+
echo "latest_version=$LATEST_VERSION" >> "$GITHUB_OUTPUT"
37+
38+
if [ "$LATEST_VERSION" != "$CURRENT_DOCS_VERSION" ]; then
39+
echo "should_update=true" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "should_update=false" >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Update generated docs
45+
if: steps.versions.outputs.should_update == 'true'
46+
env:
47+
LATEST_VERSION: ${{ steps.versions.outputs.latest_version }}
48+
run: |
49+
sudo apt-get update
50+
sudo apt-get install -y libdbus-1-dev libglib2.0-dev pkg-config
51+
52+
git -C ../gitbutler checkout "$LATEST_VERSION"
53+
./scripts/update-manpages.sh
54+
55+
echo "Updating scripts/current_docs_version.txt to $LATEST_VERSION"
56+
echo "$LATEST_VERSION" > scripts/current_docs_version.txt
57+
58+
git config user.name "github-actions[bot]"
59+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
60+
61+
branch="update-generated-docs-$LATEST_VERSION"
62+
git checkout -b "$branch"
63+
git add .
64+
git commit -m "Update CLI docs"
65+
git push origin "$branch"
66+
67+
echo "branch=$branch" >> "$GITHUB_ENV"
68+
69+
- name: Create pull request
70+
if: steps.versions.outputs.should_update == 'true'
71+
run: |
72+
gh pr create \
73+
--title "Update generated CLI documentation for version ${LATEST_VERSION}" \
74+
--body "Automatic docs update for ${LATEST_VERSION} @slarse @krlvi" \
75+
--base main \
76+
--head "$branch"
77+
env:
78+
GH_TOKEN: ${{ secrets.GH_CREATE_PR_PAT }}
79+
LATEST_VERSION: ${{ steps.versions.outputs.latest_version }}

scripts/current_docs_version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nightly/0.5.2077

scripts/update-manpages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ rm -f cli-docs/*
3838

3939
# Regenerate documentation using cargo
4040
echo "Regenerating CLI documentation with cargo..."
41-
cargo run --bin but-clap --features raw-clap-docs
41+
cargo run -p but-clap --bin but-clap --features raw-clap-docs
4242

4343
echo "Documentation files regenerated successfully!"
4444
echo

0 commit comments

Comments
 (0)