Skip to content

Commit

Permalink
GitHub action dat 15968 (#86)
Browse files Browse the repository at this point in the history
* chore(sonar-test-scan.yml): update Maven commands in Sonar test scan workflow

- Change the Maven command from "mvn -B verify -P '!run-proguard' -DskipITs -Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT" to "mvn -B package -P 'sonar,!run-proguard' -DskipTests -Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT" to only package the project and exclude running tests.
- Update the Maven command in the "run" step from "mvn -B verify sonar:sonar -P '!run-proguard' -DskipTests -Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT" to "mvn -B sonar:sonar -P 'sonar,!run-proguard' -DskipTests -Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT" to only run Sonar analysis and exclude running tests.

These changes improve the efficiency of the Sonar test scan workflow by skipping unnecessary steps and focusing on the required tasks.

* fix(sonar-test-scan.yml): remove unnecessary argument '--classfiles' from jacococli.jar command

The '--classfiles' argument is not needed in the jacococli.jar command as it is already configured to use the correct class files directory. Removing this argument improves the clarity and simplicity of the command.

* chore(sonar-test-scan.yml): generate dump classes during the Sonar test scan to improve code coverage accuracy
chore(sonar-test-scan.yml): update jacococli.jar command to include classfiles path for code coverage report generation

* chore(sonar-test-scan.yml): add lt -ltr command to list files in the target directory after jacoco report generation

* refactor(sonar-test-scan.yml): improve file path handling for jacoco.exec files
feat(sonar-test-scan.yml): add support for dynamic module name for jacoco.exec file paths

* fix(sonar-test-scan.yml): update jacococli.jar path to match the location of the tested classes module

* chore(sonar-test-scan.yml): remove unnecessary mkdir command to improve build process efficiency
chore(sonar-test-scan.yml): add ls commands to debug build process and check file structure before and after jacoco merge

* chore(sonar-test-scan.yml): update jacoco unzip command to use quiet mode for less verbose output
chore(sonar-test-scan.yml): remove unnecessary 'lt' command from jacoco report step

* chore(sonar-test-scan.yml): remove unnecessary ls commands to improve readability and reduce noise in the workflow
chore(sonar-test-scan.yml): update jacoco version to v0.8.10 to ensure compatibility with the latest release
chore(sonar-test-scan.yml): update jacoco file paths to match the new jacoco version and project structure

* chore(sonar-test-scan.yml): add command to list files in the target directory for debugging purposes

* chore(sonar-test-scan.yml): add working directory configuration to Sonar test scan jobs

The working directory configuration is added to the Sonar test scan jobs in the `.github/workflows/sonar-test-scan.yml` file. This allows the jobs to run in the specified directory, which is determined by the `testedClassesModuleName` input.

* chore(create-release.yml): update sonar-push.yml version to v0.4.4 for better compatibility and bug fixes
chore(extension-attach-artifact-release.yml): update get_draft_release.sh, sign_artifact.sh, and upload_asset.sh versions to v0.4.4 for better compatibility and bug fixes
chore(extension-release-published.yml): update extension-release-prepare.yml version to v0.4.4 for better compatibility and bug fixes
chore(os-extension-test.yml): update sonar-pull-request.yml version to v0.4.4 for better compatibility and bug fixes
chore(package-deb.yml): update package-deb-pom.xml and related scripts versions to v0.4.4 for better compatibility and bug fixes
chore(pom-release-published.yml): update extension-release-prepare.yml version to v0.4.4 for better compatibility and bug fixes
chore(pro-extension-test.yml): update sonar-pull-request.yml version to v0.4.4 for better compatibility and bug fixes
chore(sonar-test-scan.yml): remove unnecessary ls command and improve code readability

* fix(sonar-test-scan.yml): skip running tests during the build process to improve build time and avoid unnecessary test execution

* chore(sonar-test-scan.yml): remove unnecessary jacoco download and extraction steps
chore(sonar-test-scan.yml): remove unnecessary jacoco cli execution step

* chore(sonar-test-scan.yml): remove unnecessary step to generate dump classes

The step to generate dump classes was removed as it is no longer needed in the workflow.

* chore(sonar-test-scan.yml): add step to generate dump classes during the workflow

The `Generate dump classes` step was added to the workflow. This step runs the command `mvn -B clean install -DskipTests -P 'sonar,!run-proguard' "-Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT"` in the `${{ inputs.testedClassesModuleName }}` directory. This step is necessary to generate dump classes for the SonarQube analysis.

* chore(sonar-test-scan.yml): add step to generate Jacoco report after merging results to improve code coverage analysis

* chore(sonar-test-scan.yml): rename step name from "Generate dump classes" to "Generate classes" for clarity

* chore(sonar-test-scan.yml): add step to save Jacoco reports as an artifact for further analysis

* chore(sonar-test-scan.yml): add support for configurable classes artifact name
feat(sonar-test-scan.yml): download classes artifact and merge jacoco reports using jacococli.jar

The changes in this commit include:
- Added a new input parameter `classesArtifactName` to the workflow file `sonar-test-scan.yml` to specify the name of the classes artifact.
- Added a new step to download the classes artifact using the `actions/download-artifact` action.
- Modified the existing step to merge the jacoco reports to use the `jacococli.jar` tool.
- Added new steps to download the `jacococli.jar` tool, move it to the appropriate location, and merge the jacoco reports using the tool.
- Added a new step to generate the jacoco report in XML format.

These changes were made to improve the SonarQube scan workflow by allowing the use of a configurable classes artifact name and using the `jacococli.jar` tool for merging the jacoco reports.

* fix(sonar-test-scan.yml): change jacococli.jar command to use merged.exec instead of aggregate.exec for generating jacoco.xml report

* chore(sonar-test-scan.yml): remove unused classesArtifactName input variable to simplify configuration
chore(sonar-test-scan.yml): downgrade java-version to 11 to match project requirements
chore(sonar-test-scan.yml): remove unnecessary download classes step as it is not used in the workflow
chore(sonar-test-scan.yml): update merge integration and unit tests reports step to create target directory if it doesn't exist

* chore(sonar-test-scan.yml): remove unused input variables for unitTestReportArtifactName and integrationTestReportArtifactName
chore(sonar-test-scan.yml): update artifact names for downloading test reports to match new naming convention

* chore(sonar-test-scan.yml): add conditional step to always generate classes during the workflow

The conditional step was added to ensure that the classes are always generated during the workflow execution, regardless of the previous steps' outcomes. This is necessary to ensure that the generated classes are up to date and reflect any changes made in the codebase.

* fix(sonar-test-scan.yml): fix path for creating directory and moving files to match the input variable

fix(sonar-test-scan.yml): fix path for unzipping jacoco-0.8.10.zip and moving jacococli.jar to match the input variable

fix(sonar-test-scan.yml): fix path for changing directory to match the input variable

* chore(sonar-test-scan.yml): update default value of databasePlatforms input to only include mysql
fix(sonar-test-scan.yml): fix working directory for Generate classes and Merge integration and unit tests reports steps
fix(sonar-test-scan.yml): fix classfiles path in jacococli.jar report command

* refactor(sonar-test-scan.yml): simplify file path and directory structure for jacoco coverage reports
feat(sonar-test-scan.yml): add support for merging and generating jacoco coverage reports for different integration test databases

* fix(sonar-test-scan.yml): update jacoco report classfiles path to point to the correct directory

The classfiles path for generating the jacoco report was pointing to the wrong directory. This commit updates the path to point to the correct directory, `../liquibase-standard/target/`, to ensure that the jacoco report is generated correctly.

* chore(sonar-test-scan.yml): add support for custom sonarRootPath and testedClassesModuleName inputs

The `sonar-test-scan.yml` workflow file has been modified to include support for two new inputs: `sonarRootPath` and `testedClassesModuleName`.

The `sonarRootPath` input allows specifying the root path of the project to be scanned by Sonar. It is an optional input with a default value of `.` (current directory).

The `testedClassesModuleName` input allows specifying the name of the module containing the tested classes. It is an optional input with no default value.

These changes provide flexibility in configuring the Sonar scan for different project structures and module setups.

* chore(sonar-test-scan.yml): remove unnecessary working-directory configuration
chore(sonar-test-scan.yml): add working-directory configuration to specify the root path for Sonar scan

* chore(sonar-test-scan.yml): remove unnecessary commands and improve Jacoco report generation

The following changes were made:
- Removed the `pwd` and `ls` commands for debugging purposes
- Removed the `Save Jacoco Reports` step as it is no longer needed
- Improved the Jacoco report generation by specifying the classfiles and sourcefiles directories
- Added a `cat jacoco.xml` command to display the contents of the generated Jacoco report

* chore(sonar-test-scan.yml): add debug output to print current working directory and list files in it
chore(sonar-test-scan.yml): archive test results by uploading jacoco.xml file as an artifact

* chore(sonar-test-scan.yml): remove unnecessary echo statement and add support for generating HTML coverage report

The unnecessary echo statement that prints the "Tested classes module name" has been removed to reduce noise in the workflow logs.

Support for generating HTML coverage reports has been added. The jacococli.jar command is now executed twice, once to generate the XML report and once to generate the HTML report. The HTML report is generated for both the root module and the specified tested classes module, if provided. The generated HTML reports are then archived as artifacts.

* chore(sonar-test-scan.yml): update jacoco report command to generate HTML report in a 'site' directory

* chore(sonar-test-scan.yml): add default value 'root' for testedClassesModuleName input parameter
fix(sonar-test-scan.yml): fix path to source files in jacococli.jar report command
feat(sonar-test-scan.yml): change artifact name to 'liquibase-jacoco-merged-results' for upload-artifact step

* chore(sonar-test-scan.yml): remove unused artifact upload step

The artifact upload step for archiving Jacoco merged results was removed as it was no longer needed.

* chore(sonar-test-scan.yml): set default working directory for sonar-scan job to the specified sonarRootPath input value to ensure correct execution context

* chore(sonar-test-scan.yml): add ls -ltr command to debug workflow
chore(sonar-test-scan.yml): create target directory if it doesn't exist to prevent mv command failure

* chore(sonar-test-scan.yml): update artifact download paths to use dynamic sonarRootPath input variable for better flexibility and maintainability
chore(sonar-test-scan.yml): remove unnecessary ls -ltr command in the SonarCloud analysis step

* fix(sonar-test-scan.yml): update jacoco report command to use correct classfiles path for root module
fix(sonar-test-scan.yml): update jacoco report command to use correct classfiles path for non-root modules
  • Loading branch information
jandroav authored Sep 29, 2023
1 parent 3614bf0 commit 9938664
Showing 1 changed file with 65 additions and 51 deletions.
116 changes: 65 additions & 51 deletions .github/workflows/sonar-test-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ on:
type: string
required: false
default: -Dsonar.coverage.exclusions='**/test/**/*.*, **/pom.xml'
unitTestReportArtifactName:
description: 'The name of the unit test report artifact'
type: string
required: false
integrationTestReportArtifactName:
description: 'The name of the integration test report artifact'
sonarRootPath:
description: 'The name of the tested classes module'
type: string
required: false
default: .
testedClassesModuleName:
description: 'The name of the tested classes module'
type: string
required: false
default: 'root'
dbPlatforms:
description: 'The database platforms to be tested'
type: string
required: false
default: mssql,mysql,oracle,postgresql,hsqldb,
default: mysql

env:
MAVEN_VERSION: '3.8.7'
Expand All @@ -57,6 +55,9 @@ jobs:
sonar-scan:
name: Sonar Scan
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ./${{ inputs.sonarRootPath }}

steps:
- uses: actions/checkout@v3
Expand All @@ -66,7 +67,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 11
distribution: 'temurin'
cache: 'maven'
overwrite-settings: false
Expand Down Expand Up @@ -121,71 +122,71 @@ jobs:
- name: Download unit tests report
uses: actions/download-artifact@v3
with:
name: ${{ inputs.unitTestReportArtifactName }}
path: unit-tests
name: liquibase-jacoco-test-results
path: ${{ inputs.sonarRootPath }}/unit-tests

- name: Download mssql integration tests report
if: contains(inputs.dbPlatforms, 'mssql')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-mssql
path: integration-tests/mssql
name: liquibase-integration-jacoco-test-results-mssql
path: ${{ inputs.sonarRootPath }}/integration-tests/mssql

- name: Download mysql integration tests report
if: contains(inputs.dbPlatforms, 'mysql')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-mysql
path: integration-tests/mysql
name: liquibase-integration-jacoco-test-results-mysql
path: ${{ inputs.sonarRootPath }}/integration-tests/mysql

- name: Download oracle integration tests report
if: contains(inputs.dbPlatforms, 'oracle')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-oracle
path: integration-tests/oracle
name: liquibase-integration-jacoco-test-results-oracle
path: ${{ inputs.sonarRootPath }}/integration-tests/oracle

- name: Download postgresql integration tests report
if: contains(inputs.dbPlatforms, 'postgresql')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-postgresql
path: integration-tests/postgresql
name: liquibase-integration-jacoco-test-results-postgresql
path: ${{ inputs.sonarRootPath }}/integration-tests/postgresql

- name: Download h2 integration tests report
if: contains(inputs.dbPlatforms, 'h2')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-h2
path: integration-tests/h2
name: liquibase-integration-jacoco-test-results-h2
path: ${{ inputs.sonarRootPath }}/integration-tests/h2

- name: Download hsqldb integration tests report
if: contains(inputs.dbPlatforms, 'hsqldb')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-hsqldb
path: integration-tests/hsqldb
name: liquibase-integration-jacoco-test-results-hsqldb
path: ${{ inputs.sonarRootPath }}/integration-tests/hsqldb

- name: Download mariadb integration tests report
if: contains(inputs.dbPlatforms, 'mariadb')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-mariadb
path: integration-tests/mariadb
name: liquibase-integration-jacoco-test-results-mariadb
path: ${{ inputs.sonarRootPath }}/integration-tests/mariadb

- name: Download sqlite integration tests report
if: contains(inputs.dbPlatforms, 'sqlite')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-sqlite
path: integration-tests/sqlite
name: liquibase-integration-jacoco-test-results-sqlite
path: ${{ inputs.sonarRootPath }}/integration-tests/sqlite

- name: Download firebird integration tests report
if: contains(inputs.dbPlatforms, 'firebird')
uses: actions/download-artifact@v3
with:
name: ${{ inputs.integrationTestReportArtifactName }}-firebird
path: integration-tests/firebird
name: liquibase-integration-jacoco-test-results-firebird
path: ${{ inputs.sonarRootPath }}/integration-tests/firebird

- name: Cache SonarCloud packages
if: always()
Expand All @@ -195,60 +196,74 @@ jobs:
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Generate dump classes
- name: Generate classes
if: always()
run: |
mvn -B clean install surefire-report:report -P 'sonar,!run-proguard' "-Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT"
working-directory: ./${{ inputs.testedClassesModuleName }}
mvn -B clean install -DskipTests -P 'sonar,!run-proguard' "-Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT"
- name: Merge integration and unit tests reports
if: always()
env:
testedClassesModuleName: ${{ inputs.testedClassesModuleName }}
run: |
mkdir -p target
mv unit-tests/jacoco.exec target/jacoco-unit.exec
mv unit-tests/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-unit.exec
if [ -d "integration-tests/mssql" ]; then
mv integration-tests/mssql/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-mssql-aggregate.exec
mv integration-tests/mssql/jacoco.exec target/jacoco-mssql-aggregate.exec
fi
if [ -d "integration-tests/mysql" ]; then
mv integration-tests/mysql/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-mysql-aggregate.exec
mv integration-tests/mysql/jacoco.exec target/jacoco-mysql-aggregate.exec
fi
if [ -d "integration-tests/oracle" ]; then
mv integration-tests/oracle/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-oracle-aggregate.exec
mv integration-tests/oracle/jacoco.exec target/jacoco-oracle-aggregate.exec
fi
if [ -d "integration-tests/postgresql" ]; then
mv integration-tests/postgresql/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-postgresql-aggregate.exec
mv integration-tests/postgresql/jacoco.exec target/jacoco-postgresql-aggregate.exec
fi
if [ -d "integration-tests/h2" ]; then
mv integration-tests/h2/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-h2-aggregate.exec
mv integration-tests/h2/jacoco.exec target/jacoco-h2-aggregate.exec
fi
if [ -d "integration-tests/hsqldb" ]; then
mv integration-tests/hsqldb/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-hsqldb-aggregate.exec
mv integration-tests/hsqldb/jacoco.exec target/jacoco-hsqldb-aggregate.exec
fi
if [ -d "integration-tests/mariadb" ]; then
mv integration-tests/mariadb/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-mariadb-aggregate.exec
mv integration-tests/mariadb/jacoco.exec target/jacoco-mariadb-aggregate.exec
fi
if [ -d "integration-tests/sqlite" ]; then
mv integration-tests/sqlite/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-sqlite-aggregate.exec
mv integration-tests/sqlite/jacoco.exec target/jacoco-sqlite-aggregate.exec
fi
if [ -d "integration-tests/firebird" ]; then
mv integration-tests/firebird/jacoco.exec ./${{ inputs.testedClassesModuleName }}/target/jacoco-firebird-aggregate.exec
mv integration-tests/firebird/jacoco.exec target/jacoco-firebird-aggregate.exec
fi
wget -q https://github.com/jacoco/jacoco/releases/download/v0.8.10/jacoco-0.8.10.zip
unzip -qq ./jacoco-0.8.10.zip
mv ./lib/jacococli.jar ./${{ inputs.testedClassesModuleName }}/target/jacococli.jar
chmod +x ./${{ inputs.testedClassesModuleName }}/target/jacococli.jar
cd ./${{ inputs.testedClassesModuleName }}
mvn jacoco:merge@cli-merge-results
cd ./target
java -jar jacococli.jar report aggregate.exec --classfiles=../../${{ inputs.testedClassesModuleName }}/target/classdumps
unzip -qq jacoco-0.8.10.zip
mv lib/jacococli.jar target/jacococli.jar
chmod +x target/jacococli.jar
cd target
java -jar jacococli.jar merge *.exec --destfile merged.exec
if [ "${{ env.testedClassesModuleName }}" = "root" ]; then
echo "Tested classes module name: root module"
java -jar jacococli.jar report merged.exec --classfiles ./classes --sourcefiles src --xml jacoco.xml
java -jar jacococli.jar report merged.exec --classfiles ./classes --sourcefiles src --html site
else
echo "Tested classes module name: ${{ env.testedClassesModuleName }}"
java -jar jacococli.jar report merged.exec --classfiles ../${{ env.testedClassesModuleName }}/target/ --sourcefiles ../${{ env.testedClassesModuleName }}/src/ --xml jacoco.xml
java -jar jacococli.jar report merged.exec --classfiles ../${{ env.testedClassesModuleName }}/target/ --sourcefiles ../${{ env.testedClassesModuleName }}/src/ --html site
fi
- name: Sonar Branch Scan
if: always() && !github.event.pull_request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
LIQUIBASE_PRO_LICENSE_KEY: ${{ secrets.PRO_LICENSE_KEY }}
working-directory: ./${{ inputs.testedClassesModuleName }}
run: |
mvn -B sonar:sonar -P 'sonar,!run-proguard' -DskipTests -Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT \
${{ inputs.mavenArgs }} \
Expand All @@ -268,7 +283,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
LIQUIBASE_PRO_LICENSE_KEY: ${{ secrets.PRO_LICENSE_KEY }}
working-directory: ./${{ inputs.testedClassesModuleName }}
run: |
mvn -B sonar:sonar -P 'sonar,!run-proguard' -DskipTests -Dliquibase.version=${{ inputs.liquibaseBranchName }}-SNAPSHOT \
${{ inputs.mavenArgs }} \
Expand All @@ -285,4 +299,4 @@ jobs:
-Dsonar.organization=${{ github.repository_owner }} \
-Dsonar.host.url='https://sonarcloud.io' \
-Dsonar.scm.provider=git \
-Daws.region="us-east-1"
-Daws.region="us-east-1"

0 comments on commit 9938664

Please sign in to comment.