|
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 }} / SQLite |
@@ -108,3 +114,49 @@ jobs: |
108 | 114 | with: |
109 | 115 | name: coverage |
110 | 116 | path: coverage/ |
| 117 | + |
| 118 | + - name: Generate badge.json |
| 119 | + run: | |
| 120 | + LAST_RUN="coverage/.last_run.json" |
| 121 | + if [ ! -f "$LAST_RUN" ]; then |
| 122 | + mkdir -p badge |
| 123 | + echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json |
| 124 | + exit 0 |
| 125 | + fi |
| 126 | + PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)") |
| 127 | + PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')") |
| 128 | + if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen" |
| 129 | + elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green" |
| 130 | + elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow" |
| 131 | + else COLOR="red"; fi |
| 132 | + mkdir -p badge |
| 133 | + echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json |
| 134 | +
|
| 135 | + - name: Upload badge artifact |
| 136 | + uses: actions/upload-artifact@v4 |
| 137 | + with: |
| 138 | + name: coverage-badge |
| 139 | + path: badge |
| 140 | + |
| 141 | + deploy-coverage: |
| 142 | + needs: coverage |
| 143 | + if: github.ref == 'refs/heads/master' && github.event_name == 'push' |
| 144 | + runs-on: ubuntu-latest |
| 145 | + environment: |
| 146 | + name: github-pages |
| 147 | + url: ${{ steps.deployment.outputs.page_url }} |
| 148 | + steps: |
| 149 | + - name: Download coverage badge |
| 150 | + uses: actions/download-artifact@v4 |
| 151 | + with: |
| 152 | + name: coverage-badge |
| 153 | + path: . |
| 154 | + - name: Setup Pages |
| 155 | + uses: actions/configure-pages@v5 |
| 156 | + - name: Upload Pages artifact |
| 157 | + uses: actions/upload-pages-artifact@v3 |
| 158 | + with: |
| 159 | + path: . |
| 160 | + - name: Deploy to GitHub Pages |
| 161 | + id: deployment |
| 162 | + uses: actions/deploy-pages@v4 |
0 commit comments