zdl-kotlin: working jvm and js versions #7
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
| name: Verify Main and Publish Coverage | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build and test with coverage | |
| run: ./gradlew build koverHtmlReport koverLog | |
| - name: Print coverage to console | |
| run: ./gradlew koverPrintCoverage | |
| if: always() | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: coverage-reports | |
| path: | | |
| build/reports/kover/ | |
| build/reports/tests/ | |
| - name: Checkout badges branch | |
| uses: actions/checkout@v4 | |
| if: github.event_name != 'pull_request' | |
| with: | |
| ref: badges | |
| path: badges | |
| - name: Generate coverage badge | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| # Extract coverage percentage from Kover log output | |
| COVERAGE=$(./gradlew koverPrintCoverage --console=plain | grep "application line coverage:" | grep -oP '\d+\.\d+' | awk '{printf "%.0f", $1}') | |
| echo "Coverage: $COVERAGE%" | |
| # Generate badge color based on coverage | |
| if [ "$COVERAGE" -ge 80 ]; then | |
| COLOR="brightgreen" | |
| elif [ "$COVERAGE" -ge 60 ]; then | |
| COLOR="yellow" | |
| else | |
| COLOR="red" | |
| fi | |
| # Create badge directory if it doesn't exist | |
| mkdir -p badges | |
| # Download badge from shields.io | |
| curl -o badges/coverage.svg "https://img.shields.io/badge/coverage-${COVERAGE}%25-${COLOR}" | |
| echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV | |
| - name: Commit and push coverage badge | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| cd badges | |
| if [[ `git status --porcelain` ]]; then | |
| git config --global user.name 'github-actions' | |
| git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| git add coverage.svg | |
| git commit -m "Update coverage badge: ${{ env.COVERAGE }}%" | |
| git push | |
| fi | |