feat: add AWS_REGION input to coverage workflow #14
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: Unit Tests | |
| on: | |
| push: | |
| pull_request: | |
| paths-ignore: | |
| - "**.md" | |
| workflow_call: | |
| inputs: | |
| java_version: | |
| description: "Java version" | |
| required: false | |
| default: "17" | |
| type: string | |
| minimum_coverage: | |
| description: "Minimum coverage percentage" | |
| required: false | |
| default: "0" | |
| type: string | |
| coverage_results_path: | |
| description: "Path to the JaCoCo coverage results file" | |
| required: false | |
| default: "food-main/target/jacoco-report/jacoco.xml" | |
| type: string | |
| jacoco_csv_file: | |
| description: "Path to the JaCoCo CSV file" | |
| required: false | |
| default: "food-main/target/jacoco-report/jacoco.csv" | |
| type: string | |
| test_command: | |
| description: "Test command" | |
| required: false | |
| default: "mvn clean verify" | |
| type: string | |
| AWS_REGION: | |
| description: "AWS Region" | |
| required: false | |
| default: "us-east-1" | |
| type: string | |
| env: | |
| AWS_REGION: ${{ inputs.AWS_REGION }} | |
| jobs: | |
| coverage: | |
| permissions: write-all | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| - name: Set up Java JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: "temurin" | |
| java-version: ${{ inputs.java_version }} | |
| cache: "maven" | |
| # cache-dependency-path: 'sub-project/pom.xml' # optional | |
| - name: Runs test | |
| run: ${{ inputs.test_command }} | |
| # Para evitar erros com permissão de escrita | |
| # https://stackoverflow.com/a/75250838/3929980 | |
| # generates coverage-report.md and publishes as checkrun | |
| - name: JaCoCo Code Coverage Report | |
| id: jacoco_reporter | |
| uses: PavanMudigonda/jacoco-reporter@v5.0 | |
| with: | |
| coverage_results_path: ${{ inputs.coverage_results_path }} | |
| coverage_report_name: Coverage | |
| coverage_report_title: JaCoCo | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| skip_check_run: false | |
| minimum_coverage: ${{ inputs.minimum_coverage }} | |
| fail_below_threshold: false | |
| publish_only_summary: false | |
| # Publish Coverage Job Summary # Optional | |
| - name: Add Jacocoo report to workflow run summary | |
| run: | | |
| echo "| Outcome | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Code Coverage % | ${{ steps.jacoco_reporter.outputs.coverage_percentage }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| :heavy_check_mark: Number of Lines Covered | ${{ steps.jacoco_reporter.outputs.covered_lines }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| :x: Number of Lines Missed | ${{ steps.jacoco_reporter.outputs.missed_lines }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Total Number of Lines | ${{ steps.jacoco_reporter.outputs.total_lines }} |" >> $GITHUB_STEP_SUMMARY | |
| # uploads the coverage-report.md artifact # Optional | |
| - name: Upload Code Coverage Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: code-coverage-report-markdown | |
| path: "*/coverage-results.md" | |
| retention-days: 90 | |
| - name: Generate JaCoCo Badge | |
| id: jacoco | |
| uses: cicirello/jacoco-badge-generator@v2 | |
| with: | |
| jacoco-csv-file: ${{ inputs.jacoco_csv_file }} | |
| generate-branches-badge: true | |
| generate-coverage-badge: true | |
| - name: Check for modified files | |
| id: git-check | |
| run: echo ::set-output name=modified::$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi) | |
| - name: Update changes in GitHub repository | |
| if: steps.git-check.outputs.modified == 'true' | |
| uses: EndBug/add-and-commit@v9.1.4 | |
| with: | |
| author_name: GitHub Actions | |
| author_email: github-actions[bot]@users.noreply.github.com | |
| committer_name: GitHub Actions | |
| committer_email: github-actions[bot]@users.noreply.github.com | |
| message: "[GitHub Actions] Autogenerated JaCoCo coverage badge" | |
| fetch: false | |