|
| 1 | +# This workflow uses actions that are not certified by GitHub. |
| 2 | +# They are provided by a third-party and are governed by |
| 3 | +# separate terms of service, privacy policy, and support |
| 4 | +# documentation. |
| 5 | +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake |
| 6 | +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby |
| 7 | + |
| 8 | +name: build & test |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: [ "main" ] |
| 13 | + pull_request: |
| 14 | + branches: [ "main" ] |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + test: |
| 21 | + |
| 22 | + runs-on: ubuntu-latest |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + ruby-version: ['3.4'] |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v6 |
| 29 | + - name: Set up Ruby |
| 30 | + uses: ruby/setup-ruby@v1 |
| 31 | + with: |
| 32 | + ruby-version: ${{ matrix.ruby-version }} |
| 33 | + bundler-cache: true |
| 34 | + - name: Run tests |
| 35 | + run: bundle exec rake |
| 36 | + - name: Extract coverage percentage |
| 37 | + id: coverage |
| 38 | + run: | |
| 39 | + COVERAGE=$(jq '.result.line' coverage/.last_run.json) |
| 40 | + COVERAGE_ROUNDED=$(printf "%.0f" $COVERAGE) |
| 41 | + echo "coverage=$COVERAGE_ROUNDED" >> $GITHUB_OUTPUT |
| 42 | + - name: Generate badge SVG |
| 43 | + id: badge |
| 44 | + run: | |
| 45 | + COLOR=green |
| 46 | + if [ ${{ steps.coverage.outputs.coverage }} -lt 80 ]; then |
| 47 | + COLOR=red |
| 48 | + elif [ ${{ steps.coverage.outputs.coverage }} -lt 90 ]; then |
| 49 | + COLOR=#c6bc3d |
| 50 | + fi |
| 51 | + echo "<?xml version=\"1.0\"?><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"20\"> |
| 52 | + <rect width=\"100\" height=\"20\" fill=\"#555\"/> |
| 53 | + <rect x=\"63\" width=\"37\" height=\"20\" fill=\"$COLOR\"/> |
| 54 | + <text x=\"8\" y=\"14\" fill=\"#fff\" font-family=\"Verdana\" font-size=\"11\">coverage</text> |
| 55 | + <text x=\"66\" y=\"14\" fill=\"#fff\" font-family=\"Verdana\" font-size=\"11\">${{ steps.coverage.outputs.coverage }}%</text> |
| 56 | + </svg>" > coverage-badge.svg |
| 57 | + echo "badge_path=coverage-badge.svg" >> $GITHUB_OUTPUT |
| 58 | + - name: Back push |
| 59 | + uses: jekyll-is/action-jekyll-is-backpush@v1 |
| 60 | + with: |
| 61 | + label: 'Coverage Badge' |
| 62 | + telegram-bot-token: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 63 | + telegram-user-id: ${{ secrets.MY_TG_ID }} |
0 commit comments