Update CLI Docs #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |