|
3 | 3 | pull_request: |
4 | 4 | push: |
5 | 5 | branches: [master] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pages: write |
| 10 | + id-token: write |
| 11 | + |
6 | 12 | jobs: |
7 | 13 | test: |
8 | 14 | name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }} |
|
24 | 30 | bundler-cache: true |
25 | 31 | - name: Run tests |
26 | 32 | run: bundle exec rspec spec |
| 33 | + |
| 34 | + - name: Generate badge.json |
| 35 | + if: matrix.ruby == '4.0' && matrix.rails == '~> 8.1.0' && matrix.activeadmin == '~> 3.5' |
| 36 | + run: | |
| 37 | + LAST_RUN="coverage/.last_run.json" |
| 38 | + if [ ! -f "$LAST_RUN" ]; then |
| 39 | + mkdir -p badge |
| 40 | + echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)") |
| 44 | + PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')") |
| 45 | + if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen" |
| 46 | + elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green" |
| 47 | + elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow" |
| 48 | + else COLOR="red"; fi |
| 49 | + mkdir -p badge |
| 50 | + echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json |
| 51 | +
|
| 52 | + - name: Upload badge artifact |
| 53 | + if: matrix.ruby == '4.0' && matrix.rails == '~> 8.1.0' && matrix.activeadmin == '~> 3.5' |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: coverage-badge |
| 57 | + path: badge |
| 58 | + |
| 59 | + deploy-coverage: |
| 60 | + needs: test |
| 61 | + if: github.ref == 'refs/heads/master' && github.event_name == 'push' |
| 62 | + runs-on: ubuntu-latest |
| 63 | + environment: |
| 64 | + name: github-pages |
| 65 | + url: ${{ steps.deployment.outputs.page_url }} |
| 66 | + |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + with: |
| 70 | + ref: gh-pages |
| 71 | + |
| 72 | + - name: Download coverage badge |
| 73 | + uses: actions/download-artifact@v4 |
| 74 | + with: |
| 75 | + name: coverage-badge |
| 76 | + path: . |
| 77 | + |
| 78 | + - name: Setup Pages |
| 79 | + uses: actions/configure-pages@v5 |
| 80 | + |
| 81 | + - name: Upload Pages artifact |
| 82 | + uses: actions/upload-pages-artifact@v3 |
| 83 | + with: |
| 84 | + path: . |
| 85 | + |
| 86 | + - name: Deploy to GitHub Pages |
| 87 | + id: deployment |
| 88 | + uses: actions/deploy-pages@v4 |
0 commit comments