|
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 }} |
9 | 15 | runs-on: ubuntu-latest |
10 | 16 | strategy: |
11 | 17 | fail-fast: false |
12 | 18 | matrix: |
13 | | - ruby: ['3.2.0', '3.3.0', '3.4.0'] |
14 | | - rails: ['7.1.0', '7.2.0'] |
| 19 | + ruby: ['3.2', '3.3', '3.4'] |
| 20 | + rails: ['7.1.0', '7.2.0', '8.0.0'] |
15 | 21 | activeadmin: ['3.2.0', '3.3.0', '3.4.0', '3.5.0'] |
| 22 | + exclude: |
| 23 | + - rails: '8.0.0' |
| 24 | + activeadmin: '3.2.0' |
16 | 25 | env: |
17 | 26 | RAILS: ${{ matrix.rails }} |
18 | 27 | AA: ${{ matrix.activeadmin }} |
|
24 | 33 | bundler-cache: true |
25 | 34 | - name: Run tests |
26 | 35 | run: bundle exec rspec spec |
| 36 | + |
| 37 | + - name: Generate badge.json |
| 38 | + if: matrix.ruby == '3.4' && matrix.rails == '8.0.0' && matrix.activeadmin == '3.5.0' |
| 39 | + run: | |
| 40 | + LAST_RUN="coverage/.last_run.json" |
| 41 | + if [ ! -f "$LAST_RUN" ]; then |
| 42 | + mkdir -p badge |
| 43 | + echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | + PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)") |
| 47 | + PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')") |
| 48 | + if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen" |
| 49 | + elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green" |
| 50 | + elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow" |
| 51 | + else COLOR="red"; fi |
| 52 | + mkdir -p badge |
| 53 | + echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json |
| 54 | +
|
| 55 | + - name: Upload badge artifact |
| 56 | + if: matrix.ruby == '3.4' && matrix.rails == '8.0.0' && matrix.activeadmin == '3.5.0' |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + name: coverage-badge |
| 60 | + path: badge |
| 61 | + |
| 62 | + deploy-coverage: |
| 63 | + needs: test |
| 64 | + if: github.ref == 'refs/heads/master' && github.event_name == 'push' |
| 65 | + runs-on: ubuntu-latest |
| 66 | + environment: |
| 67 | + name: github-pages |
| 68 | + url: ${{ steps.deployment.outputs.page_url }} |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Download coverage badge |
| 72 | + uses: actions/download-artifact@v4 |
| 73 | + with: |
| 74 | + name: coverage-badge |
| 75 | + path: coverage |
| 76 | + |
| 77 | + - name: Setup Pages |
| 78 | + uses: actions/configure-pages@v5 |
| 79 | + |
| 80 | + - name: Upload Pages artifact |
| 81 | + uses: actions/upload-pages-artifact@v3 |
| 82 | + with: |
| 83 | + path: coverage |
| 84 | + |
| 85 | + - name: Deploy to GitHub Pages |
| 86 | + id: deployment |
| 87 | + uses: actions/deploy-pages@v4 |
0 commit comments