|
| 1 | +name: Check CLI Documentation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-docs: |
| 9 | + name: Verify CLI documentation is up-to-date |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: "3.10" |
| 19 | + |
| 20 | + - name: Install dependencies |
| 21 | + run: | |
| 22 | + python3 -m pip install --upgrade pip |
| 23 | + pip install -e . |
| 24 | +
|
| 25 | + - name: Generate current CLI documentation |
| 26 | + run: | |
| 27 | + typer pyaxm.cli utils docs --name pyaxm-cli --output /tmp/cli.md |
| 28 | +
|
| 29 | + - name: Compare with existing documentation |
| 30 | + id: compare_docs |
| 31 | + run: | |
| 32 | + # Calculate MD5 hashes for both files |
| 33 | + OLD_HASH=$(md5sum docs/cli.md | awk '{ print $1 }') |
| 34 | + NEW_HASH=$(md5sum /tmp/cli.md | awk '{ print $1 }') |
| 35 | + |
| 36 | + # Compare hashes |
| 37 | + if [ "$OLD_HASH" != "$NEW_HASH" ]; then |
| 38 | + echo "docs_outdated=true" >> $GITHUB_OUTPUT |
| 39 | + exit 1 |
| 40 | + else |
| 41 | + echo "CLI documentation is up-to-date." |
| 42 | + echo "Hash: $OLD_HASH" |
| 43 | + echo "docs_outdated=false" >> $GITHUB_OUTPUT |
| 44 | + fi |
| 45 | + |
| 46 | + - name: Comment on PR if documentation is outdated |
| 47 | + if: ${{ steps.compare_docs.outputs.docs_outdated == 'true' }} |
| 48 | + uses: actions/github-script@v6 |
| 49 | + with: |
| 50 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + script: | |
| 52 | + const pull_request_number = context.issue.number; |
| 53 | + const comment = `🚨 **CLI Documentation Check Failed** 🚨 |
| 54 | +
|
| 55 | +The CLI documentation in \`docs/cli.md\` is not up-to-date with the current code. |
| 56 | + |
| 57 | +**What to do:** |
| 58 | +1. Run the following command locally to update the documentation: |
| 59 | + ```bash |
| 60 | + typer pyaxm.cli utils docs --name pyaxm-cli --output docs/cli.md |
| 61 | + ``` |
| 62 | +2. Commit the updated \`docs/cli.md\` file |
| 63 | +3. Push your changes to update this pull request |
| 64 | + |
| 65 | +This ensures that the documentation always reflects the actual CLI functionality.`; |
| 66 | + |
| 67 | + github.rest.issues.createComment({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + issue_number: pull_request_number, |
| 71 | + body: comment |
| 72 | + }); |
0 commit comments