Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Execute tests only for changed modules on non-default branchs #10036

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
30a887e
Add dashboard for endpoint monitoring
ole-ve Dec 7, 2024
f584586
Update dashboard
ole-ve Dec 7, 2024
1acbe40
Make number of top endpoints a variable
ole-ve Dec 7, 2024
c9732aa
Debug: Append something to job summary
ole-ve Dec 7, 2024
0bb5333
Append per-module coverage to job summary (hardcoded module)
ole-ve Dec 7, 2024
c273d60
Temporarily add current branch to push triggering branches
ole-ve Dec 7, 2024
c2d0dfc
draft for module coverage
ole-ve Dec 7, 2024
48a4396
Extract jacoco gradle config from build.gradle to jacoco.gradle
ole-ve Dec 10, 2024
2e4d796
Only test changed modules
ole-ve Dec 10, 2024
739f60a
Parse and append per-module coverage results
ole-ve Dec 10, 2024
fd39101
Temporarily remove codacy coverage report upload
ole-ve Dec 10, 2024
5a409be
Upload whole build coverage report directory
ole-ve Dec 10, 2024
9e7d3cf
Temporarily fix tested modules
ole-ve Dec 10, 2024
5083184
temporarily add ArchitectureTest to have at least one test
ole-ve Dec 16, 2024
27b68ba
fix GH variable name of default branch
ole-ve Dec 16, 2024
d2a6f33
clone default branch if not running for the base branch
ole-ve Dec 16, 2024
5cbeac4
prefix branch name to compare with "origin/"
ole-ve Dec 16, 2024
f7e1408
remove null tasks from dependant list
ole-ve Dec 16, 2024
49c151f
correctly type testedModules as ArrayList
ole-ve Dec 16, 2024
e3def21
(temporarily) directly set TEST_MODULE_TAGS instead of evaluating wit…
ole-ve Dec 16, 2024
43b65eb
Add logging on executed test tags
ole-ve Dec 16, 2024
476c792
quote TEST_MODULE_TAGS
ole-ve Dec 16, 2024
786d172
log gradle command
ole-ve Dec 16, 2024
b31f0c8
Revert "log gradle command"
ole-ve Dec 16, 2024
2fd5936
split into includeModules and includeTags
ole-ve Dec 16, 2024
f394c70
change buildagent thresholds to match module-only results
ole-ve Dec 16, 2024
e022592
Move basePath from jacoco.gradle to build.gradle
ole-ve Dec 16, 2024
7dd9730
ensure module-specific jacoco task runs after "rootTask"
ole-ve Dec 16, 2024
98227e8
add comment on including junit tags logic
ole-ve Dec 16, 2024
c860849
create jacoco report for full Artemis bundle also when testing specif…
ole-ve Dec 16, 2024
6453837
remove debugging step from pipeline
ole-ve Dec 16, 2024
9c4348f
adapt expected number of server starts
ole-ve Dec 16, 2024
42b9f88
use finalizedBy instead of mustRunAfter
ole-ve Dec 16, 2024
39f568d
make report paths explicit
ole-ve Dec 16, 2024
d67a9b4
adjust per-module covered instruction threshold for fileupload
ole-ve Dec 16, 2024
e15e05f
remove hardcoded TEST_MODULE_TAGS from test pipeline
ole-ve Dec 16, 2024
78f77a5
move jacoco-parser to .ci-dir and rename to execute.py
ole-ve Dec 16, 2024
ad657cf
move jacoco.gradle to gradle-dir
ole-ve Dec 16, 2024
cfc2f38
move changed-modules.sh to .dir directory
ole-ve Dec 16, 2024
8b6aa0c
fix logic of number of server starts script
ole-ve Dec 16, 2024
1f54c61
update isolated coverage threshold per module
ole-ve Dec 16, 2024
be4da5e
move generate_code_cov_table to subfolder
ole-ve Dec 16, 2024
49ddd27
move get_changed_modules.sh to supporting scripts
ole-ve Dec 16, 2024
46280fe
move parse_module_coverage to supporting scripts
ole-ve Dec 16, 2024
1cad26f
add documentation to get_changed_modules.sh
ole-ve Dec 16, 2024
bfd2c8d
use test filters instead of "include" to ensure test results are crea…
ole-ve Dec 16, 2024
6e0baa5
println for missing coverage message
ole-ve Dec 16, 2024
5ab2996
add info on return type of get_changed_modules.sh
ole-ve Dec 16, 2024
7fd0ad0
refactor: separate concerns in parse_module_coverage.py
ole-ve Dec 16, 2024
2a2b8d7
rename get_changed_modules.sh to test_changed_modules.sh
ole-ve Dec 16, 2024
5de1c8a
Revert "rename get_changed_modules.sh to test_changed_modules.sh"
ole-ve Dec 16, 2024
9de9c3a
fix issues with parse_module_coverage.py
ole-ve Dec 16, 2024
4cdb0fa
remove branch input validation
ole-ve Dec 16, 2024
e1748af
generate full reports when no input modules specified
ole-ve Dec 16, 2024
240aef1
change message to be more explicit about skipping coverage verification
ole-ve Dec 16, 2024
b1042a4
add debugging
ole-ve Dec 17, 2024
e668fb9
Revert "add debugging"
ole-ve Dec 17, 2024
3cdfda7
log command
ole-ve Dec 17, 2024
42d0b82
move test module tags further into the command
ole-ve Dec 17, 2024
53ca8d0
add stacktrace logging
ole-ve Dec 17, 2024
20a43df
explicitly run all or only-specific tests
ole-ve Dec 17, 2024
ce82e2e
remove unused file
ole-ve Dec 17, 2024
4ccaa0a
fix module name in error message
ole-ve Dec 17, 2024
7d3cc92
remove fixed branch
ole-ve Dec 17, 2024
8c58a39
change upload artifact path
ole-ve Dec 17, 2024
dbe638e
add codacy step again
ole-ve Dec 17, 2024
830d2bd
fix jacoco report output location for aggregated report
ole-ve Dec 17, 2024
7e59059
rename jacocoCoverageReport.xml to jacocoTestReport.xml
ole-ve Dec 17, 2024
631e229
include tests into determination of changed modules
ole-ve Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Prerequisites:
- [ ] Test 2

### Test Coverage
<!-- Please add the test coverages for all changed files modified in this PR here. You can use `supporting_script/generate_code_cov_table/generate_code_cov_table.py` to automatically generate the coverage table from the corresponding artefacts of your branch (follow the ReadMe for setup details). -->
<!-- Please add the test coverages for all changed files modified in this PR here. You can use `supporting_script/code-coverage/generate_code_cov_table/generate_code_cov_table.py` to automatically generate the coverage table from the corresponding artefacts of your branch (follow the ReadMe for setup details). -->
<!-- Alternatively you can execute the tests locally (see build.gradle and package.json) or look into the corresponding artefacts. -->
<!-- The line coverage must be above 90% for changes files, and you must use extensive and useful assertions for server tests and expect statements for client tests. -->
<!-- Note: Confirm in the last column that you have implemented extensive assertions for server tests and expect statements for client tests. -->
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ updates:

# Check for version updates for Python dependencies (coverage)
- package-ecosystem: "pip"
directory: "/supporting_scripts/generate_code_cov_table"
directory: "/supporting_scripts/code-coverage/generate_code_cov_table"
schedule:
interval: "weekly"
reviewers:
Expand Down
43 changes: 34 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ on:
- develop
- main
- release/*
- feature/grafana-endpoint-monitoring
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
tags: '[0-9]+.[0-9]+.[0-9]+'
paths-ignore:
- 'README.md'
Expand Down Expand Up @@ -60,16 +61,35 @@ jobs:
${{ env.java }}
cache: 'gradle'
- name: Java Tests
run: set -o pipefail && ./gradlew --console=plain test jacocoTestReport -x webapp jacocoTestCoverageVerification | tee tests.log
run: |
set -o pipefail

DEFAULT_BRANCH="${{ github.event.repository.default_branch }}"
CURRENT_BRANCH="${{ github.ref_name }}"

if [[ "$DEFAULT_BRANCH" != "$CURRENT_BRANCH" ]]; then
# Explicitly fetch as the clone action only clones the current branch
git fetch origin "$DEFAULT_BRANCH"

chmod +x ./supporting_scripts/get_changed_modules.sh
CHANGED_MODULES=$(./supporting_scripts/get_changed_modules.sh "origin/$DEFAULT_BRANCH")

# Restrict executed tests to changed modules if there is diff between this and the base branch
if [ -n "${CHANGED_MODULES}" ]; then
IFS=,
TEST_MODULE_TAGS=$(echo "-DincludeModules=${CHANGED_MODULES[*]}")

echo "Executing tests for modules: $CHANGED_MODULES"
./gradlew --console=plain test jacocoTestReport -x webapp jacocoTestCoverageVerification "$TEST_MODULE_TAGS" | tee tests.log
exit 0
fi
fi

echo "Executing all tests"
./gradlew --console=plain test jacocoTestReport -x webapp jacocoTestCoverageVerification | tee tests.log
- name: Print failed tests
if: failure()
run: grep "Test >.* FAILED\$" tests.log || echo "No failed tests."
- name: "Codacy: Report coverage"
uses: codacy/codacy-coverage-reporter-action@master
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: build/reports/jacoco/test/jacocoTestReport.xml
if: (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) && (success() || failure()) && github.event.pull_request.user.login != 'dependabot[bot]'
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
- name: Annotate Server Test Results
uses: ashley-taylor/junit-report-annotations-action@f9c1a5cbe28479439f82b80a5402a6d3aa1990ac
if: always() && github.event.pull_request.user.login != 'dependabot[bot]'
Expand All @@ -92,8 +112,13 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: Coverage Report Server Tests
path: build/reports/jacoco/test/html/

path: build/reports/jacoco/
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
- name: Append Per-Module Coverage to Job Summary
if: success() || failure()
run: |
AGGREGATED_REPORT_FILE=./module_coverage_report.md
python3 ./supporting_scripts/code-coverage/per_module_cov_report/parse_module_coverage.py build/reports/jacoco $AGGREGATED_REPORT_FILE
cat $AGGREGATED_REPORT_FILE > $GITHUB_STEP_SUMMARY

server-tests-mysql:
needs: [ server-tests ]
Expand Down
81 changes: 28 additions & 53 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,38 @@ modernizer {
exclusions = ["java/util/Optional.get:()Ljava/lang/Object;"]
}

// Allow using in jacoco.gradle
ext {
includedTestTags = System.getProperty("includeTags")
includedTags = !includedTestTags ? new String[]{} : includedTestTags.split(",") as String[]
includedModulesTag = System.getProperty("includeModules")
includedModules = !includedModulesTag ? new String[]{} : includedModulesTag.split(",") as String[]

runAllTests = includedTags.size() == 0 && includedModules.size() == 0
BasePath = "de/tum/cit/aet/artemis"
}

// Execute the test cases: ./gradlew test
// Execute only architecture tests: ./gradlew test -DincludeTags="ArchitectureTest"
// Execute tests only for specific modules: ./gradlew test -DincludeModules="atlas". Using this flag, "includeTags" will be ignored.
test {
if (System.getProperty("includeTags")) {
useJUnitPlatform {
includeTags System.getProperty("includeTags")
if (runAllTests) {
useJUnitPlatform()
exclude "**/*IT*", "**/*IntTest*"
} else if (includedModules.size() == 0) {
// not running all tests, but not module-specific ones -> use tags
useJUnitPlatform() {
includeTags includedTags
}
} else {
useJUnitPlatform()
exclude "**/*IT*", "**/*IntTest*"
// Always execute "shared"-folder when executing module-specifc tests
includedModules += "shared"
filter { testFilter ->
includedModules.each { val ->
testFilter.includeTestsMatching("de.tum.cit.aet.artemis.$val.*")
}
}
}

testLogging {
Expand All @@ -144,59 +166,12 @@ tasks.register("testReport", TestReport) {
testResults.from(test)
}

jacoco {
toolVersion = "0.8.12"
}

jar {
enabled = false
}

private excludedClassFilesForReport(classDirectories) {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it,
exclude: [
"**/de/tum/cit/aet/artemis/**/domain/**/*_*",
"**/de/tum/cit/aet/artemis/core/config/migration/entries/**",
"**/gradle-wrapper.jar/**"
]
)
}))
}

jacocoTestReport {
reports {
xml.required = true
}
// we want to ignore some generated files in the domain folders
afterEvaluate {
excludedClassFilesForReport(classDirectories)
}
}

jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = "INSTRUCTION"
value = "COVEREDRATIO"
// TODO: in the future the following value should become higher than 0.92
minimum = 0.892
}
limit {
counter = "CLASS"
value = "MISSEDCOUNT"
// TODO: in the future the following value should become less than 10
maximum = 65
}
}
}
// we want to ignore some generated files in the domain folders
afterEvaluate {
excludedClassFilesForReport(classDirectories)
}
}
check.dependsOn jacocoTestCoverageVerification
// Dynamic generation of jacoco test report generation-/coverage verification-tasks (per-module)
apply from: "gradle/jacoco.gradle"

configurations {
providedRuntime
Expand Down
Loading
Loading