diff --git a/.github/workflows/oidc-conformance-test.yml b/.github/workflows/oidc-conformance-test.yml index e7d329b62b..657fcecd50 100644 --- a/.github/workflows/oidc-conformance-test.yml +++ b/.github/workflows/oidc-conformance-test.yml @@ -127,11 +127,19 @@ jobs: "${asset_url}" fi + - name: Download Jacoco Agent + id: download_jacoco + run: | + curl -vLJO -H 'Accept: application/octet-stream' https://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.12/jacoco-0.8.12.zip + - name: Run IS run: | PRODUCT_IS_ZIP=$(find ./ -name wso2is* -type f -printf "%f\n") + ROOT_DIR=$(pwd) + touch jacoco.exec + echo "PRODUCT_IS_DIR=${PRODUCT_IS_ZIP%.zip}" >> $GITHUB_ENV cd ./product-is/oidc-conformance-tests - python3 ./configure_is.py ../../$PRODUCT_IS_ZIP + python3 ./configure_is.py ../../$PRODUCT_IS_ZIP $ROOT_DIR $ROOT_DIR/jacoco.exec - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -158,6 +166,11 @@ jobs: - name: Run Tests run: bash ./product-is/oidc-conformance-tests/test_runner.sh + + - name: Stop IS + id: stop_is + run: | + sh ./product-is/oidc-conformance-tests/${{ env.PRODUCT_IS_DIR }}/bin/wso2server.sh stop - name: Test Results run: | @@ -192,6 +205,13 @@ jobs: with: name: test-logs path: ./*log.txt + + - name: Archive Jacoco results + uses: actions/upload-artifact@v3 + if: always() + with: + name: jacoco-exec + path: ./jacoco.exec - name: Send Email if: always() diff --git a/oidc-conformance-tests/configure_is.py b/oidc-conformance-tests/configure_is.py index c9732b5fe5..a9b8b2c12c 100644 --- a/oidc-conformance-tests/configure_is.py +++ b/oidc-conformance-tests/configure_is.py @@ -34,6 +34,8 @@ } # path to product is zip file path_to_is_zip = str(sys.argv[1]) +path_to_jacoco_agent = str(sys.argv[2]) +path_to_jacoco_exec = str(sys.argv[3]) # use dcr to register a client @@ -328,6 +330,10 @@ def unpack_and_run(zip_file_name): print("Extracting " + zip_file_name) zip_file.extractall() + with ZipFile(path_to_jacoco_agent + "/jacoco-0.8.12.zip", 'r') as jacoco_agent_zip: + print("Extracting " + path_to_jacoco_agent) + jacoco_agent_zip.extractall(path_to_jacoco_agent + "/jacoco-0.8.12") + dir_name = '' # start identity server print("\nStarting Server") @@ -339,6 +345,8 @@ def unpack_and_run(zip_file_name): dir_name = line break + agent_line = "-javaagent:" + path_to_jacoco_agent + "/jacoco-0.8.12/lib/jacocoagent.jar" + "=destfile=" + path_to_jacoco_exec + ",append=true,includes=org.wso2.carbon.idp.mgt*:org.wso2.carbon.sts*:org.wso2.carbon.user.core*:org.wso2.carbon.user.mgt*:org.wso2.carbon.claim.mgt*:org.wso2.carbon.identity.*:org.wso2.carbon.xkms.mgt* \\" + add_jacoco_agent("./" + dir_name + "/bin/wso2server.sh", "-Dwso2.server.standalone=true \\", agent_line) os.chmod("./" + dir_name + "/bin/wso2server.sh", 0o777) append_toml_config("./config/oidc_deployment_config.toml", "./" + dir_name + "/repository/conf/deployment.toml") process = subprocess.Popen("./" + dir_name + "/bin/wso2server.sh", stdout=subprocess.PIPE) @@ -355,6 +363,20 @@ def unpack_and_run(zip_file_name): print() raise +def add_jacoco_agent(file, line_to_check, line_to_replace): + try: + with open(file, 'rb') as src, open(file + ".back", 'wb') as dst: dst.write(src.read()) + # Read the content from the source TOML file + with open(file + ".back") as fin, open(file, 'w') as fout: + for line in fin: + lineout = line + if line.strip() == line_to_check: + lineout = f"{line_to_check}\n{line_to_replace}\n" + fout.write(lineout) + except FileNotFoundError as e: + print(f"The file does not exist: {e}") + except IOError as e: + print(f"An error occurred: {e}") # Append additional toml configs to the existing deployment toml file. def append_toml_config(source_file, destination_file):