Ruby #827
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow uses actions that are not certified by GitHub. | |
| # They are provided by a third-party and are governed by | |
| # separate terms of service, privacy policy, and support | |
| # documentation. | |
| # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake | |
| # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby | |
| name: Ruby | |
| on: | |
| push: | |
| schedule: | |
| # * is a special character in YAML so you have to quote this string | |
| - cron: '13 13 * * *' # really? No @daily? | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Run tests with coverage | |
| run: make coverage | |
| - name: Run rubocop | |
| run: make rubocop | |
| - name: Extract and update coverage badge | |
| run: | | |
| # Extract coverage percentage from SimpleCov's .last_run.json | |
| if [ ! -f coverage/.last_run.json ]; then | |
| echo "Error: coverage/.last_run.json not found" | |
| exit 1 | |
| fi | |
| # Use sed for better portability - account for optional spaces after colon | |
| COVERAGE=$(sed -n 's/.*"coverage": *\([0-9.]*\).*/\1/p' coverage/.last_run.json | head -1) | |
| if [ -z "$COVERAGE" ]; then | |
| echo "Error: Could not extract coverage percentage" | |
| echo "Contents of coverage/.last_run.json:" | |
| cat coverage/.last_run.json | |
| exit 1 | |
| fi | |
| COVERAGE_INT=$(printf "%.0f" "$COVERAGE") | |
| echo "Coverage: $COVERAGE_INT%" | |
| # Determine badge color based on coverage | |
| if [ "$COVERAGE_INT" -ge 90 ]; then | |
| COLOR="brightgreen" | |
| elif [ "$COVERAGE_INT" -ge 80 ]; then | |
| COLOR="green" | |
| elif [ "$COVERAGE_INT" -ge 70 ]; then | |
| COLOR="yellowgreen" | |
| elif [ "$COVERAGE_INT" -ge 60 ]; then | |
| COLOR="yellow" | |
| else | |
| COLOR="red" | |
| fi | |
| # Create badge JSON for shields.io endpoint | |
| mkdir -p .github/badges | |
| cat > .github/badges/coverage.json << EOF | |
| { | |
| "schemaVersion": 1, | |
| "label": "coverage", | |
| "message": "${COVERAGE_INT}%", | |
| "color": "$COLOR" | |
| } | |
| EOF | |
| # Configure git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Commit and push if changed | |
| git add .github/badges/coverage.json | |
| if git diff --staged --quiet; then | |
| echo "No changes to coverage badge" | |
| else | |
| git commit -m "Update coverage badge: ${COVERAGE_INT}%" | |
| # Pull any changes before pushing | |
| git pull --rebase origin ${{ github.ref_name }} || true | |
| git push || { | |
| echo "Warning: Failed to push badge update" | |
| exit 0 | |
| } | |
| fi |