add command framework #4
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: "rustdoc" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| merge_group: | |
| jobs: | |
| rustdoc: | |
| runs-on: ubuntu-latest | |
| env: | |
| RUSTDOCFLAGS: "-D warnings" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| # Make sure the actual branch is checked out when running on pull requests | |
| ref: ${{ github.head_ref }} | |
| repository: ${{github.event.pull_request.head.repo.full_name || github.repository }} | |
| - name: Set up Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| override: true | |
| - name: Install Rust problem matchers | |
| uses: r7kamura/rust-problem-matchers@v1 | |
| - name: Use dependency cache | |
| uses: Swatinem/rust-cache@v2 | |
| - name: cargo doc | |
| uses: actions-rs/cargo@v1 | |
| with: | |
| command: doc | |
| args: --no-deps --all-features | |
| - name: Upload documentation artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: rustdoc | |
| path: target/doc/ | |
| retention-days: 7 | |
| - name: Comment on PR with artifact link | |
| if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const runId = context.runId; | |
| const repoOwner = context.repo.owner; | |
| const repoName = context.repo.repo; | |
| const artifactUrl = `https://github.com/${repoOwner}/${repoName}/actions/runs/${runId}`; | |
| const message = `📚 **Documentation Preview** | |
| The rustdoc documentation has been generated for this PR. | |
| You can download the \`rustdoc\` artifact from the [workflow run](${artifactUrl}) to preview the documentation locally. | |
| To view the documentation: | |
| 1. Download and extract the artifact | |
| 2. Open \`index.html\` in your browser`; | |
| // Find existing comment | |
| const comments = await github.rest.issues.listComments({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('📚 **Documentation Preview**') | |
| ); | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| comment_id: botComment.id, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: message | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: message | |
| }); | |
| } |