Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 1 addition & 90 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '*.md'

permissions:
contents: write
contents: read
pull-requests: write

jobs:
Expand Down Expand Up @@ -39,98 +39,9 @@ jobs:
- name: Lint
run: pnpm lint

- 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
env:
SKIP_CLI_TESTS: 'true'

- name: Commit generated CLI docs
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add src/content/docs/cli/commands.mdx
if git diff --cached --quiet; then
echo "No changes to CLI docs"
else
git commit -m "Update auto-generated CLI documentation"
git push
fi

- name: Build
run: pnpm build

- name: Comment CLI Test Results on PR
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = './cli-test-report.json';

let body = '### CLI Documentation Generator\n\n';

if (!fs.existsSync(path)) {
body += '⚠️ No test report found (tests may have been skipped)\n';
} else {
const report = JSON.parse(fs.readFileSync(path, 'utf8'));

const allPassed = report.testsFailed === 0;
const emoji = allPassed ? '✅' : '❌';

body += `| Metric | Value |\n`;
body += `|--------|-------|\n`;
body += `| CLI Version | \`${report.cliVersion}\` |\n`;
body += `| Commands Generated | ${report.commandsGenerated.length} |\n`;
body += `| Tests | ${emoji} ${report.testsPassed}/${report.testsRun} passed |\n`;

if (report.errors.length > 0) {
body += `\n<details><summary>❌ ${report.errors.length} Error(s)</summary>\n\n`;
for (const error of report.errors) {
body += `- **${error.command}** (${error.phase}): ${error.message}\n`;
}
body += `\n</details>\n`;
}

if (report.commandsGenerated.length > 0) {
body += `\n<details><summary>📚 Commands documented</summary>\n\n`;
body += report.commandsGenerated.map(c => `- \`${c}\``).join('\n');
body += `\n</details>\n`;
}
}

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('### CLI Documentation Generator'));

if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}

preview:
name: Preview Deployment
runs-on: ubuntu-latest
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/update-cli-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Loading