Skip to content

refactor: Code readability [DHIS2-16705] (#19451) #39854

refactor: Code readability [DHIS2-16705] (#19451)

refactor: Code readability [DHIS2-16705] (#19451) #39854

Workflow file for this run

name: Test
env:
# This is to make sure Maven don't timeout fetching dependencies. See: https://github.com/actions/virtual-environments/issues/1499
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=125
on:
push:
branches:
- master
pull_request:
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: maven
- name: Run unit tests
run: mvn clean test --threads 2C --batch-mode --no-transfer-progress --update-snapshots --file ./dhis-2/pom.xml --activate-profiles unit-test
timeout-minutes: 30
- name: Run dependency analysis
run: mvn dependency:analyze --file ./dhis-2/pom.xml
timeout-minutes: 2
- name: Report coverage to codecov
uses: codecov/codecov-action@v3
with:
directory: ./dhis-2
flags: unit
fail_ci_if_error: false
verbose: true
# delete the next 2 steps once we are confident in the coverage setup
- name: Tar jacoco coverage report to debug
run: tar -cvf coverage.tar dhis-2/dhis-test-coverage/target/site/jacoco-aggregate
- uses: actions/upload-artifact@v4
name: Upload jacoco coverage report to debug
with:
name: unit-test-coverage
path: coverage.tar
retention-days: 5
- name: Generate surefire aggregate report
run: mvn surefire-report:report-only -Daggregate=true --batch-mode --no-transfer-progress --file ./dhis-2/pom.xml --projects -dhis-test-coverage
# tar due to https://github.com/actions/upload-artifact/blob/3cea5372237819ed00197afe530f5a7ea3e805c8/README.md?plain=1#L254
- name: Tar surefire individual reports
run: find . -name "surefire-reports" -type d -exec find {} -type f -name "*.xml" -printf '%p\0' \; | tar --null --files-from=- -cvf surefire_reports.tar
- name: Archive surefire reports
uses: actions/upload-artifact@v4
with:
name: unit-test-surefire-reports
path: |
dhis-2/target/site/surefire-report.html
surefire_reports.tar
retention-days: 5
integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: maven
- name: Run integration tests
run: mvn clean test --threads 2C --batch-mode --no-transfer-progress --update-snapshots --file ./dhis-2/pom.xml --activate-profiles integration-test
timeout-minutes: 30
- uses: actions/upload-artifact@v4
name: Upload test logs on failure
if: failure()
with:
name: integration-test-logs
path: "**/target/test.log"
if-no-files-found: error # check our logging configuration if that happens
retention-days: 3
- name: Report coverage to codecov
uses: codecov/codecov-action@v3
with:
directory: ./dhis-2
flags: integration
fail_ci_if_error: false
verbose: true
# delete the next 2 steps once we are confident in the coverage setup
- name: Tar jacoco coverage report to debug
run: tar -cvf coverage.tar dhis-2/dhis-test-coverage/target/site/jacoco-aggregate
- uses: actions/upload-artifact@v4
name: Upload jacoco coverage report to debug
with:
name: integration-test-coverage
path: coverage.tar
retention-days: 5
- name: Generate surefire aggregate report
run: mvn surefire-report:report-only -Daggregate=true --batch-mode --no-transfer-progress --file ./dhis-2/pom.xml --projects -dhis-test-coverage
# tar due to https://github.com/actions/upload-artifact/blob/3cea5372237819ed00197afe530f5a7ea3e805c8/README.md?plain=1#L254
- name: Tar surefire individual reports
run: find . -name "surefire-reports" -type d -exec find {} -type f -name "*.xml" -printf '%p\0' \; | tar --null --files-from=- -cvf surefire_reports.tar
- name: Archive surefire reports
uses: actions/upload-artifact@v4
with:
name: integration-test-surefire-reports
path: |
dhis-2/target/site/surefire-report.html
surefire_reports.tar
retention-days: 5
integration-h2-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: maven
- name: Run integration h2 tests
run: mvn clean test --threads 2C --batch-mode --no-transfer-progress --update-snapshots --file ./dhis-2/pom.xml --activate-profiles integration-h2-test
timeout-minutes: 30
- uses: actions/upload-artifact@v4
name: Upload test logs on failure
if: failure()
with:
name: integration-h2-test-logs
path: "**/target/test.log"
if-no-files-found: error # check our logging configuration if that happens
retention-days: 3
- name: Report coverage to codecov
uses: codecov/codecov-action@v3
with:
directory: ./dhis-2
flags: integration-h2
fail_ci_if_error: false
verbose: true
# delete the next 2 steps once we are confident in the coverage setup
- name: Tar jacoco coverage report to debug
run: tar -cvf coverage.tar dhis-2/dhis-test-coverage/target/site/jacoco-aggregate
- uses: actions/upload-artifact@v4
name: Upload jacoco coverage report to debug
with:
name: integration-h2-test-coverage
path: coverage.tar
retention-days: 5
- name: Generate surefire aggregate report
run: mvn surefire-report:report-only -Daggregate=true --batch-mode --no-transfer-progress --file ./dhis-2/pom.xml --projects -dhis-test-coverage
# tar due to https://github.com/actions/upload-artifact/blob/3cea5372237819ed00197afe530f5a7ea3e805c8/README.md?plain=1#L254
- name: Tar surefire individual reports
run: find . -name "surefire-reports" -type d -exec find {} -type f -name "*.xml" -printf '%p\0' \; | tar --null --files-from=- -cvf surefire_reports.tar
- name: Archive surefire reports
uses: actions/upload-artifact@v4
with:
name: integration-h2-test-surefire-reports
path: |
dhis-2/target/site/surefire-report.html
surefire_reports.tar
retention-days: 5
send-slack-message:
runs-on: ubuntu-latest
if: |
always() &&
contains(needs.*.result, 'failure') &&
github.ref == 'refs/heads/master'
needs: [unit-test, integration-test, integration-h2-test]
steps:
- uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_BACKEND_WEBHOOK }}
SLACK_CHANNEL: "team-backend"
SLACK_MESSAGE: "Latest test run on master failed and needs investigation :detective-duck:. \n Commit message: ${{ github.event.head_commit.message }}"
SLACK_COLOR: "#ff0000"