Skip to content

DAT-17704

DAT-17704 #2836

Workflow file for this run

name: Run Tests
on:
workflow_call:
workflow_dispatch:
inputs:
archive_test_results:
description: 'If set to true, the unit and integration test results will be archived to the build artifacts page.'
required: false
default: 'false'
push:
branches:
- master
pull_request_target:
types:
- opened
- reopened
- synchronize
paths-ignore:
- '**.md'
jobs:
authorize:
#concurrent runs for pull requests from forked repositories will be canceled, while runs for pull requests from the master repository won't be affected.
#for a pull_request against master: the concurrency check will cancel commit A so that commit B check can run.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref == 'master' && (github.event_name == 'push' && 'push-to-master' || github.event_name == 'pull_request' && 'merge-to-master') || github.event_name == 'pull_request_target' && github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.base_ref == 'master' }}
environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true
setup:
name: setup
needs: authorize
runs-on: ubuntu-20.04
outputs:
timestamp: ${{ steps.get-date.outputs.date }}
latestMergeSha: ${{ steps.get-sha.outputs.latestMergeSha }}
thisBranchName: ${{ steps.get-branch-name.outputs.thisBranchName }}
setupSuccessful: "true"
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- name: Get current date
id: get-date
run: |
echo "date=$(date +'%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_OUTPUT
- name: Get Latest Merge Commit SHA
id: get-sha
run: |
latest_merge_sha=`(git rev-parse HEAD)`
echo "latestMergeSha=${latest_merge_sha}" >> $GITHUB_OUTPUT
- name: Get Current BranchName
id: get-branch-name
run: |
# this logic checks if the branch is from a forked repository PR or not. Where -n is the inverse of -z (not empty)
if [ -n "${GITHUB_HEAD_REF}" ];
then
branch_name=${GITHUB_HEAD_REF}
else
branch_name=${{ github.ref_name }}
fi
modified_branch_name=`(echo $branch_name | tr '/_' '-')`
echo "thisBranchName=$modified_branch_name" >> $GITHUB_OUTPUT
echo $modified_branch_name
build_tests:
name: Run Test for (Java ${{ matrix.java }} ${{ matrix.os }})
needs: setup
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-13, windows-2019 ]
java: [ 8, 11, 17, 21 ]
exclude:
# exclude non-java 8 on macos and windows builds
- os: macos-13
java: 11
- os: windows-2019
java: 11
- os: macos-13
java: 17
- os: windows-2019
java: 17
- os: macos-13
java: 21
- os: windows-2019
java: 21
runs-on: ${{ matrix.os }}
env:
OS_TYPE: ${{ matrix.os }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Built Code Cache
if: ${{ matrix.java == 17}}
uses: actions/cache@v4.0.2
with:
key: built-code-${{ github.run_number }}-${{ github.run_attempt }}
path: ./**/target
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: 'maven'
# look for dependencies in maven
- name: maven-settings-xml-action
uses: whelk-io/maven-settings-xml-action@v22
with:
repositories: |
[
{
"id": "liquibase",
"url": "https://maven.pkg.github.com/liquibase/liquibase",
"releases": {
"enabled": "false"
},
"snapshots": {
"enabled": "true",
"updatePolicy": "always"
}
},
{
"id": "liquibase-pro",
"url": "https://maven.pkg.github.com/liquibase/liquibase-pro",
"releases": {
"enabled": "false"
},
"snapshots": {
"enabled": "true",
"updatePolicy": "always"
}
}
]
servers: |
[
{
"id": "liquibase-pro",
"username": "liquibot",
"password": "${{ secrets.LIQUIBOT_PAT }}"
},
{
"id": "liquibase",
"username": "liquibot",
"password": "${{ secrets.LIQUIBOT_PAT }}"
}
]
# getting from build results page. If we remove 0-snapshot then we will need settings.xml
- name: Build & Test Java below 11
if: ${{ matrix.java == 8 || matrix.java == 11}}
run: |
./mvnw -B "-Dbuild.repository.owner=liquibase" "-Dbuild.repository.name=liquibase" "-Dbuild.branch=${{ needs.setup.outputs.thisBranchName }}" "-Dbuild.number=${{ github.run_number }}" "-Dbuild.commit=${{ needs.setup.outputs.latestMergeSha }}" "-DtrimStackTrace=false" -P 'skip-integration-tests' -pl '!liquibase-cdi-jakarta' clean test package surefire-report:report
- name: Build & Test Java 11+
if: ${{ matrix.java != 8 && matrix.java != 11}}
run: |
./mvnw -B "-Dbuild.repository.owner=liquibase" "-Dbuild.repository.name=liquibase" "-Dbuild.branch=${{ needs.setup.outputs.thisBranchName }}" "-Dbuild.number=${{ github.run_number }}" "-Dbuild.commit=${{ needs.setup.outputs.latestMergeSha }}" "-DtrimStackTrace=false" -P 'skip-integration-tests' clean test package surefire-report:report
- name: Check Unit Test Count for Java 8, 11, 17, 21 Ubuntu
if: matrix.os != 'macos-13' && matrix.os != 'windows-2019'
run: |
if [[ "${{ matrix.os }}" != "macos-13" ]]; then
TEST_COUNT=$(find . -name '*.txt' | xargs grep -oP 'Tests run: \K[0-9]+' | awk -F ':' '{s+=$2} END {print(s)}')
fi
echo "Total Unit tests run: $TEST_COUNT"
if [ "$TEST_COUNT" -eq 0 ]; then
echo "No Unit tests were run."
exit 1
fi
echo "TEST_COUNT_JAVA_UBUNTU=$TEST_COUNT" >> $GITHUB_ENV
- name: Check Unit Test Count for Java 8 macos-13
if: matrix.os == 'macos-13'
shell: bash
run: |
TEST_COUNT=$(grep -r -o -E 'Tests run: [0-9]+' . | awk -F: '{s+=$NF} END {print s}')
echo "Total Unit tests run: $TEST_COUNT"
if [ -z "$TEST_COUNT" ] || [ "$TEST_COUNT" -eq 0 ]; then
echo "No test result files found or test count is zero."
exit 1
fi
echo "TEST_COUNT_JAVA_MACOS=$TEST_COUNT" >> $GITHUB_ENV
- name: Read threshold values for macos-13 and ubuntu-20.04
if: matrix.os != 'macos-13' && matrix.os != 'windows-2019'
run: |
THRESHOLDS=$(cat ${{ github.workspace }}/.github/test_counts.json)
echo "UBUNTU_THRESHOLD=$(echo $THRESHOLDS | jq -r '.TEST_COUNT_JAVA_UBUNTU')" >> $GITHUB_ENV
echo "MACOS_THRESHOLD=$(echo $THRESHOLDS | jq -r '.TEST_COUNT_JAVA_MACOS')" >> $GITHUB_ENV
- name: Notify slack if Test Count decreases for macos-13 and ubuntu-20.04
if: env.TEST_COUNT_JAVA_WINDOWS && env.TEST_COUNT_JAVA_WINDOWS < env.WINDOWS_THRESHOLD || env.TEST_COUNT_JAVA_UBUNTU && env.TEST_COUNT_JAVA_UBUNTU < env.UBUNTU_THRESHOLD || env.TEST_COUNT_JAVA_MACOS && env.TEST_COUNT_JAVA_MACOS < env.MACOS_THRESHOLD
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.NIGHTLY_BUILDS_SLACK_WEBHOOK }}
SLACK_MESSAGE: 'OSS Unit Test count decreased. Please check the unit tests and integration test results.'
SLACK_ICON_EMOJI: ":robot_face:"
SLACK_COLOR: 'danger'
# separate step for windows due to different os
- name: Read threshold values for windows-2019
if: matrix.os == 'windows-2019'
shell: pwsh
run: |
$THRESHOLDS = Get-Content "${{ github.workspace }}/.github/test_counts.json" -Raw | ConvertFrom-Json
$WINDOWS_THRESHOLD = $THRESHOLDS.TEST_COUNT_JAVA_WINDOWS
echo "WINDOWS_THRESHOLD=$WINDOWS_THRESHOLD" >> $GITHUB_ENV
- name: Check Test Count for windows-2019
if: matrix.os == 'windows-2019'
shell: pwsh
run: |
$TEST_COUNT = (Get-ChildItem -Recurse -Filter "*.txt" | Select-String -Pattern 'Tests run: (\d+)' | ForEach-Object { $_.Matches.Groups[1].Value } | Measure-Object -Sum).Sum
Write-Output "Total Unit tests run: $TEST_COUNT"
if ($TEST_COUNT -eq 0) {
Write-Output "No Unit tests were run."
exit 1
}
echo "TEST_COUNT_JAVA_WINDOWS=$TEST_COUNT" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
- name: Notify slack if Test Count decreases for windows-2019
if: env.TEST_COUNT_JAVA_WINDOWS && env.TEST_COUNT_JAVA_WINDOWS < env.WINDOWS_THRESHOLD
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.NIGHTLY_BUILDS_SLACK_WEBHOOK }}
SLACK_MESSAGE: 'OSS Unit Test count decreased. Please check the unit tests and integration test results.'
SLACK_ICON_EMOJI: ":robot_face:"
SLACK_COLOR: 'danger'
- name: Remove Original Jars for *nix
if: env.OS_TYPE != 'windows-2019'
run: |
find . -name original-*.jar -exec rm {} \;
- name: Upload Artifacts for build.yml
if: ${{ matrix.java == 17 && matrix.os == 'ubuntu-20.04'}}
uses: actions/upload-artifact@v3
with:
name: temp-artifact
path: |
./**/target/*.jar
- name: Archive Test Results
if: ${{ inputs.archive_test_results == 'true' }}
uses: actions/upload-artifact@v3
with:
name: liquibase-test-results-jdk${{ matrix.java }}
path: |
./**/target/surefire-reports
./**/target/site
- name: Save Jacoco Report for Sonar
if: ${{ matrix.java == 17 && matrix.os == 'ubuntu-20.04'}}
uses: actions/upload-artifact@v3
with:
name: liquibase-jacoco-test-results
path: |
./liquibase-standard/target/jacoco.exec
- name: Archive Modules
if: ${{ matrix.java == 17 && matrix.os == 'ubuntu-20.04'}}
uses: actions/upload-artifact@v3
with:
name: liquibase-modules
path: |
*/target/*-0-SNAPSHOT.jar
integration-test:
name: Integration Test
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
testSystem:
- db2
- h2
#- h2:1.4
- hsqldb
- mariadb
- mssql
- mysql
- oracle
- postgresql
- sqlite
- firebird
needs: build_tests
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}
- name: Prepare
id: prepare
uses: actions/github-script@v7
with:
script: |
core.setOutput("testResultsArtifact", "liquibase-test-results-integration-${{ matrix.testSystem }}".replace(/[^a-zA-Z0-9\-_]/g, "_"));
- name: Set up JDK 17
if: ${{ matrix.testSystem != 'snowflake' }}
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Set up JDK 11 # get rid of this after https://github.com/snowflakedb/snowflake-jdbc/issues/589 is fixed
if: ${{ matrix.testSystem == 'snowflake' }}
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: 'maven'
# getting from build results page. If we remove 0-snapshot then we will need settings.xml
- name: Restore Built Code Cache
uses: actions/cache@v4.0.2
with:
key: built-code-${{ github.run_number }}-${{ github.run_attempt }}
path: ./**/target
- name: Setup Python
if: ${{ matrix.testSystem == 'snowflake' }}
uses: actions/setup-python@v5.1.0
with:
python-version: '3.12.1'
- name: Start & Configure LocalStack
if: ${{ matrix.testSystem == 'snowflake' }}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
pip install localstack awscli-local
DEBUG=1 DOCKER_FLAGS='-e SF_LOG=trace' IMAGE_NAME=localstack/snowflake localstack start -d
echo "Waiting for LocalStack startup..."
localstack wait -t 30
echo "Startup complete"
echo "TH_DB_ADMIN=test" >> $GITHUB_ENV
echo "TH_DB_PASSWD=test" >> $GITHUB_ENV
echo "TH_DB=snowflake" >> $GITHUB_ENV
echo "TH_SNOW_URL=jdbc:snowflake://http://snowflake.localhost.localstack.cloud:4566" >> $GITHUB_ENV
- name: Run Tests
run: ./mvnw -B clean verify -DtrimStackTrace=false -Dliquibase.sdk.testSystem.test=${{ matrix.testSystem }} -Dliquibase.sdk.testSystem.acceptLicenses=${{ matrix.testSystem }} -Dliquibase.sdk.testSystem.snowflake.url=${{ env.TH_SNOW_URL }} -Dliquibase.sdk.testSystem.snowflake.username=${{ env.TH_DB_ADMIN }} -Dliquibase.sdk.testSystem.snowflake.password=${{ env.TH_DB_PASSWD }} -Dtest=*IntegrationTest,*ExecutorTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dsurefire.failIfNoTests=false
- name: Check Test Count
run: |
TEST_COUNT=$(find . -name '*.txt' | xargs grep -oP 'Tests run: \K[0-9]+' | awk -F ':' '{s+=$2} END {print(s)}')
echo "Total integration tests run: $TEST_COUNT"
if [ "$TEST_COUNT" -eq 0 ]; then
echo "No integration tests were run."
exit 1
fi
echo "TEST_COUNT_INTEGRATION=$TEST_COUNT" >> $GITHUB_ENV
- uses: actions/checkout@v4
- name: Read threshold values from test_counts.json
id: read-thresholds
run: |
THRESHOLDS=$(cat ${{ github.workspace }}/.github/test_counts.json)
echo "INTEGRATION_THRESHOLD=$(echo $THRESHOLDS | jq -r '.TEST_COUNT_INTEGRATION')" >> $GITHUB_ENV
- name: Notify slack if Test Count decreases
if: |
env.TEST_COUNT_INTEGRATION && env.TEST_COUNT_INTEGRATION < env.INTEGRATION_THRESHOLD
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.NIGHTLY_BUILDS_SLACK_WEBHOOK }}
SLACK_MESSAGE: 'OSS Unit Test count decreased. Please check the unit tests and integration test results.'
SLACK_ICON_EMOJI: ":robot_face:"
SLACK_COLOR: 'danger'
- name: Archive Test Results
if: ${{ inputs.archive_test_results == 'true' }}
uses: actions/upload-artifact@v3
with:
name: ${{ steps.prepare.outputs.testResultsArtifact }}
path: |
./**/target/surefire-reports
- name: Save Jacoco Report for Sonar
uses: actions/upload-artifact@v3
with:
name: liquibase-integration-jacoco-test-results-${{ matrix.testSystem }}
path: |
./liquibase-integration-tests/target/jacoco.exec
sonar:
needs: [ build_tests, integration-test ]
uses: liquibase/build-logic/.github/workflows/sonar-test-scan.yml@v0.7.8
with:
thisBranchName: ${{ needs.setup.outputs.thisBranchName }}
thisSha: ${{ needs.setup.outputs.thisSha }}
liquibaseBranchName: ${{ needs.setup.outputs.liquibaseBranchName }}
pullRequestNumber: ${{ github.event.pull_request.number }}
pullRequestBranchName: ${{ github.event.pull_request.head.ref }}
pullRequestBaseBranchName: ${{ github.event.pull_request.base.ref }}
testedClassesModuleName: liquibase-standard
dbPlatforms: h2,hsqldb,mariadb,mssql,mysql,oracle,postgresql,sqlite,firebird,db2
secrets: inherit
run-build-publish-file:
needs: [ build_tests,integration-test ]
uses: liquibase/liquibase/.github/workflows/build.yml@master
secrets: inherit