Skip to content

Fail validation for blank changeset ids (DAT-18773) #4934

Fail validation for blank changeset ids (DAT-18773)

Fail validation for blank changeset ids (DAT-18773) #4934

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
outputs:
test_count_unit_test_java_8_ubuntu: ${{ steps.check-test-counts-java-all-ubuntu.outputs.test_count_unit_test_java_8_ubuntu }}
test_count_unit_test_java_11_ubuntu: ${{ steps.check-test-counts-java-all-ubuntu.outputs.test_count_unit_test_java_11_ubuntu }}
test_count_unit_test_java_17_ubuntu: ${{ steps.check-test-counts-java-all-ubuntu.outputs.test_count_unit_test_java_17_ubuntu }}
test_count_unit_test_java_21_ubuntu: ${{ steps.check-test-counts-java-all-ubuntu.outputs.test_count_unit_test_java_21_ubuntu }}
test_count_unit_test_java_macos: ${{ steps.check-test-counts-java-macos.outputs.test_count_unit_test_java_macos }}
test_count_unit_test_java_windows: ${{ steps.check-test-counts-java-windows.outputs.test_count_unit_test_java_windows }}
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.1.1
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
id: check-test-counts-java-all-ubuntu
if: matrix.os == 'ubuntu-20.04'
run: |
TEST_COUNT=$(find . -name '*.txt' | xargs grep -oP 'Tests run: \K[0-9]+' | awk -F ':' '{s+=$2} END {print(s)}')
echo "Total Unit tests run: $TEST_COUNT"
if [ "$TEST_COUNT" -eq 0 ]; then
echo "No Unit tests were run."
exit 1
fi
EXPECTED_TEST_COUNT=0
if [[ ${{ matrix.java }} == 8 ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_JAVA_8_UBUNTU }}
elif [[ ${{ matrix.java }} == 11 ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_JAVA_11_UBUNTU }}
elif [[ ${{ matrix.java }} == 17 ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_JAVA_17_UBUNTU }}
elif [[ ${{ matrix.java }} == 21 ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_JAVA_21_UBUNTU }}
fi
if [[ ($TEST_COUNT -lt $(($EXPECTED_TEST_COUNT - ($EXPECTED_TEST_COUNT / 100))) ) ]]; then
echo "Unit Test count is below the acceptable range of - 1% of the expected count. Expected $EXPECTED_TEST_COUNT. Actual $TEST_COUNT."
exit 1
fi
echo "test_count_unit_test_java_${{ matrix.java }}_ubuntu=$TEST_COUNT" >> $GITHUB_OUTPUT
- name: Check Unit Test Count for Java 8 macos-13
id: check-test-counts-java-macos
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
if [[ $TEST_COUNT -lt $((${{ vars.TEST_COUNT_JAVA_MACOS }} - (${{ vars.TEST_COUNT_JAVA_MACOS }} / 100))) ]] ; then
echo "MacOS Unit Test count is below the acceptable range of - 1% of the expected count. Expected ${{ vars.TEST_COUNT_JAVA_MACOS }}. Actual $TEST_COUNT."
exit 1
fi
echo "test_count_unit_test_java_macos=$TEST_COUNT" >> $GITHUB_OUTPUT
- name: Check Test Count for windows-2019
id: check-test-counts-java-windows
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
}
if (($TEST_COUNT -lt $((${{ vars.TEST_COUNT_JAVA_WINDOWS }} - (${{ vars.TEST_COUNT_JAVA_WINDOWS }} / 100))) ) ) {
Write-Host "Windows Unit Test count is below the acceptable range of - 1% of the expected count. Expected ${{ vars.TEST_COUNT_JAVA_WINDOWS }}. Actual $TEST_COUNT."
exit 1
}
echo "test_count_unit_test_java_windows=$TEST_COUNT" >> $env:GITHUB_OUTPUT
- 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
outputs:
test_count_integration_db2: ${{ steps.check-test-count-integration.outputs.test_count_integration_db2 }}
test_count_integration_h2: ${{ steps.check-test-count-integration.outputs.test_count_integration_h2 }}
test_count_integration_mariadb: ${{ steps.check-test-count-integration.outputs.test_count_integration_mariadb }}
test_count_integration_mssql: ${{ steps.check-test-count-integration.outputs.test_count_integration_mssql }}
test_count_integration_mysql: ${{ steps.check-test-count-integration.outputs.test_count_integration_mysql }}
test_count_integration_oracle: ${{ steps.check-test-count-integration.outputs.test_count_integration_oracle }}
test_count_integration_postgresql: ${{ steps.check-test-count-integration.outputs.test_count_integration_postgresql }}
test_count_integration_sqlite: ${{ steps.check-test-count-integration.outputs.test_count_integration_sqlite }}
test_count_integration_firebird: ${{ steps.check-test-count-integration.outputs.test_count_integration_firebird }}
test_count_integration_hsqldb: ${{ steps.check-test-count-integration.outputs.test_count_integration_hsqldb }}
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.1.1
with:
key: built-code-${{ github.run_number }}-${{ github.run_attempt }}
path: ./**/target
- name: Setup Python
if: ${{ matrix.testSystem == 'snowflake' }}
uses: actions/setup-python@v5.2.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
id: check-test-count-integration
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
EXPECTED_TEST_COUNT=0
if [[ ${{ matrix.testSystem }} == 'db2' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_DB2 }}
elif [[ ${{ matrix.testSystem }} == 'h2' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_H2 }}
elif [[ ${{ matrix.testSystem }} == 'hsqldb' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_HSQLDB }}
elif [[ ${{ matrix.testSystem }} == 'mariadb' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_MARIADB }}
elif [[ ${{ matrix.testSystem }} == 'mssql' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_MSSQL }}
elif [[ ${{ matrix.testSystem }} == 'mysql' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_MYSQL }}
elif [[ ${{ matrix.testSystem }} == 'oracle' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_ORACLE }}
elif [[ ${{ matrix.testSystem }} == 'postgresql' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_POSTGRESQL }}
elif [[ ${{ matrix.testSystem }} == 'sqlite' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_SQLITE }}
elif [[ ${{ matrix.testSystem }} == 'firebird' ]]; then
EXPECTED_TEST_COUNT=${{ vars.TEST_COUNT_INTEGRATION_FIREBIRD }}
fi
if [[ $TEST_COUNT -lt $(($EXPECTED_TEST_COUNT - ($EXPECTED_TEST_COUNT / 100))) ]] ; then
echo "Integration Test count is below the acceptable range of - 1% of the expected count. Expected $EXPECTED_TEST_COUNT. Actual $TEST_COUNT."
exit 1
fi
echo "test_count_integration_${{ matrix.testSystem }}=$TEST_COUNT" >> $GITHUB_OUTPUT
- 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
update-test-count-secrets:
needs: [build_tests, integration-test]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set GitHub Secret for Test Count
env:
TEST_COUNT_SECRET: ${{ secrets.TEST_COUNT_SECRET }}
run: |
echo $TEST_COUNT_SECRET | gh auth login --with-token
repository='${{ github.repository }}'
gh variable set TEST_COUNT_JAVA_11_UBUNTU --body "${{ needs.build_tests.outputs.test_count_unit_test_java_11_ubuntu }}"
gh variable set TEST_COUNT_JAVA_17_UBUNTU --body "${{ needs.build_tests.outputs.test_count_unit_test_java_17_ubuntu }}"
gh variable set TEST_COUNT_JAVA_21_UBUNTU --body "${{ needs.build_tests.outputs.test_count_unit_test_java_21_ubuntu }}"
gh variable set TEST_COUNT_JAVA_8_UBUNTU --body "${{ needs.build_tests.outputs.test_count_unit_test_java_8_ubuntu }}"
gh variable set TEST_COUNT_JAVA_MACOS --body "${{ needs.build_tests.outputs.test_count_unit_test_java_macos }}"
gh variable set TEST_COUNT_JAVA_WINDOWS --body "${{ needs.build_tests.outputs.test_count_unit_test_java_windows}}"
gh variable set TEST_COUNT_INTEGRATION_DB2 --body "${{ needs.integration-test.outputs.test_count_integration_db2 }}"
gh variable set TEST_COUNT_INTEGRATION_H2 --body "${{ needs.integration-test.outputs.test_count_integration_h2 }}"
gh variable set TEST_COUNT_INTEGRATION_HSQLDB --body "${{ needs.integration-test.outputs.test_count_integration_hsqldb }}"
gh variable set TEST_COUNT_INTEGRATION_MARIADB --body "${{ needs.integration-test.outputs.test_count_integration_mariadb}}"
gh variable set TEST_COUNT_INTEGRATION_MSSQL --body "${{ needs.integration-test.outputs.test_count_integration_mssql }}"
gh variable set TEST_COUNT_INTEGRATION_MYSQL --body "${{ needs.integration-test.outputs.test_count_integration_mysql }}"
gh variable set TEST_COUNT_INTEGRATION_ORACLE --body "${{ needs.integration-test.outputs.test_count_integration_oracle }}"
gh variable set TEST_COUNT_INTEGRATION_POSTGRESQL --body "${{ needs.integration-test.outputs.test_count_integration_postgresql }}"
gh variable set TEST_COUNT_INTEGRATION_SQLITE --body "${{ needs.integration-test.outputs.test_count_integration_sqlite }}"
gh variable set TEST_COUNT_INTEGRATION_FIREBIRD --body "${{ needs.integration-test.outputs.test_count_integration_firebird }}"