|
| 1 | +name: RubyCritic |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI RSpec Tests"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + rubycritic: |
| 11 | + name: RubyCritic |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + actions: read |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 23 | + |
| 24 | + - name: Download coverage artifact |
| 25 | + uses: actions/download-artifact@v4 |
| 26 | + with: |
| 27 | + name: coverage |
| 28 | + path: tmp/coverage |
| 29 | + run-id: ${{ github.event.workflow_run.id }} |
| 30 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Set up Ruby |
| 33 | + uses: ruby/setup-ruby@v1 |
| 34 | + with: |
| 35 | + ruby-version: 3.3.4 |
| 36 | + bundler-cache: true |
| 37 | + |
| 38 | + - name: Get PR number |
| 39 | + id: pr |
| 40 | + run: | |
| 41 | + if [ "${{ github.event.workflow_run.event }}" = "pull_request" ]; then |
| 42 | + PR_NUMBER=$(gh pr list --head "${{ github.event.workflow_run.head_branch }}" --json number --jq '.[0].number') |
| 43 | + echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 44 | + echo "is_pr=true" >> $GITHUB_OUTPUT |
| 45 | + else |
| 46 | + echo "number=${{ github.event.workflow_run.run_number }}" >> $GITHUB_OUTPUT |
| 47 | + echo "is_pr=false" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | + env: |
| 50 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Run RubyCritic on changed files |
| 53 | + run: | |
| 54 | + mkdir -p tmp/rubycritic/pr-${{ steps.pr.outputs.number }} |
| 55 | + files=$(git diff --name-only origin/development...HEAD -- '*.rb' | xargs) |
| 56 | + if [ -n "$files" ]; then |
| 57 | + bundle exec rubycritic --no-browser --format html --path tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/changed $files |
| 58 | + else |
| 59 | + mkdir -p tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/changed |
| 60 | + echo "No Ruby files changed" > tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/changed/index.html |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Run RubyCritic on full codebase |
| 64 | + run: | |
| 65 | + bundle exec rubycritic --no-browser --format html --path tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/full app lib |
| 66 | +
|
| 67 | + - name: Copy coverage report |
| 68 | + run: | |
| 69 | + cp -r tmp/coverage tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/coverage |
| 70 | +
|
| 71 | + - name: Create index page |
| 72 | + run: | |
| 73 | + cat > tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/index.html << EOF |
| 74 | + <!DOCTYPE html> |
| 75 | + <html> |
| 76 | + <head><title>Code Quality Reports - PR #${{ steps.pr.outputs.number }}</title></head> |
| 77 | + <body> |
| 78 | + <h1>Code Quality Reports - PR #${{ steps.pr.outputs.number }}</h1> |
| 79 | + <ul> |
| 80 | + <li><a href="coverage/index.html">Code Coverage Report</a></li> |
| 81 | + <li><a href="changed/overview.html">RubyCritic - Changed Files</a></li> |
| 82 | + <li><a href="full/overview.html">RubyCritic - Full Codebase</a></li> |
| 83 | + </ul> |
| 84 | + </body> |
| 85 | + </html> |
| 86 | + EOF |
| 87 | +
|
| 88 | + - name: Deploy to GitHub Pages |
| 89 | + uses: peaceiris/actions-gh-pages@v4 |
| 90 | + with: |
| 91 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + publish_dir: tmp/rubycritic |
| 93 | + destination_dir: rubycritic |
| 94 | + keep_files: true |
| 95 | + |
| 96 | + - name: Comment PR with report links |
| 97 | + if: ${{ steps.pr.outputs.is_pr == 'true' }} |
| 98 | + uses: actions/github-script@v7 |
| 99 | + with: |
| 100 | + script: | |
| 101 | + const prNumber = ${{ steps.pr.outputs.number }}; |
| 102 | + const repoOwner = context.repo.owner; |
| 103 | + const repoName = context.repo.repo; |
| 104 | + const baseUrl = `https://${repoOwner}.github.io/${repoName}/rubycritic/pr-${prNumber}`; |
| 105 | +
|
| 106 | + const body = `## Code Quality Reports |
| 107 | +
|
| 108 | + | Report | Link | |
| 109 | + |--------|------| |
| 110 | + | Code Coverage | [View Report](${baseUrl}/coverage/index.html) | |
| 111 | + | RubyCritic - Changed Files | [View Report](${baseUrl}/changed/overview.html) | |
| 112 | + | RubyCritic - Full Codebase | [View Report](${baseUrl}/full/overview.html) | |
| 113 | + `; |
| 114 | +
|
| 115 | + github.rest.issues.createComment({ |
| 116 | + owner: repoOwner, |
| 117 | + repo: repoName, |
| 118 | + issue_number: prNumber, |
| 119 | + body: body |
| 120 | + }); |
0 commit comments