Skip to content

Replace Coveralls badge with self-hosted coverage badge on Pages #61

Replace Coveralls badge with self-hosted coverage badge on Pages

Replace Coveralls badge with self-hosted coverage badge on Pages #61

Workflow file for this run

name: CI
on:
pull_request:
push:
branches: [master]
permissions:
contents: read
pages: write
id-token: write
jobs:
test:
name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }} / SQLite
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: ['3.2', '3.3', '3.4']
rails: ['7.1.0', '7.2.0', '8.0.0']
activeadmin: ['3.2.0', '3.3.0', '3.4.0', '3.5.1']
exclude:
- rails: '8.0.0'
activeadmin: '3.2.0'
env:
RAILS: ${{ matrix.rails }}
AA: ${{ matrix.activeadmin }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rspec spec
test-mysql:
name: Ruby 3.4 / Rails 8.0.0 / AA 3.5.1 / MySQL 8.0
runs-on: ubuntu-latest
env:
RAILS: '8.0.0'
AA: '3.5.1'
DB: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USERNAME: root
DB_PASSWORD: root
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: active_admin_import_test
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost -uroot -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=10
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true
- name: Run tests
run: bundle exec rspec spec
test-postgres:
name: Ruby 3.4 / Rails 8.0.0 / AA 3.5.1 / PostgreSQL 16
runs-on: ubuntu-latest
env:
RAILS: '8.0.0'
AA: '3.5.1'
DB: postgres
DB_HOST: 127.0.0.1
DB_PORT: 5432
DB_USERNAME: postgres
DB_PASSWORD: postgres
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: active_admin_import_test
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=10
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true
- name: Run tests
run: bundle exec rspec spec
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true
- name: Run tests with coverage
run: bundle exec rspec spec
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/
- name: Generate badge.json
run: |
LAST_RUN="coverage/.last_run.json"
if [ ! -f "$LAST_RUN" ]; then
mkdir -p badge
echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json
exit 0
fi
PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)")
PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')")
if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen"
elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green"
elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow"
else COLOR="red"; fi
mkdir -p badge
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json
- name: Upload badge artifact
uses: actions/upload-artifact@v4
with:
name: coverage-badge
path: badge
deploy-coverage:
needs: coverage
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Download coverage badge
uses: actions/download-artifact@v4
with:
name: coverage-badge
path: .
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: .
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4