diff --git a/.github/actions/generate-report/action.yml b/.github/actions/generate-report/action.yml new file mode 100644 index 00000000..b3787523 --- /dev/null +++ b/.github/actions/generate-report/action.yml @@ -0,0 +1,58 @@ +name: 'Generate the Report' +description: 'Generates the report using the log-file-name file present just inside the sample folder path provided , given Validation Folder is there inside the sample folder as well' +inputs: + lang: + description: 'The language or framework in which SDK is written needs to be given as an input' + required: true + sample-folder-name: + description: 'The name of the sample folder' + required: true + log-file-name: + description: 'The name of the generated log file' + required: true +outputs: + result-pdf-name: + description: 'the name of the final generated pdf report' + value: ${{steps.generate.outputs.pdfname}} +runs: + using: 'composite' + steps: + - name: Setup Python v3.12 for report generation only + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - name: Installing required python libraries and running the python programs to generate pdf report + id: generate + run : | + export EXPECTED_RES_LANG=${{inputs.lang}} + if [[ "${{inputs.lang}}" == "dotnet" ]] || [[ "${{inputs.lang}}" == "dotnetstandard" ]]; then + export EXPECTED_RES_LANG=csharp + fi + echo $EXPECTED_RES_LANG + python --version + echo "Before Running Report Generation" + cd ${{inputs.sample-folder-name}} + python -m pip install --upgrade pip + python -m venv newve + if [[ "$(uname -s)" == "Linux" ]]; then + echo "In LINUX" + source newve/bin/activate + elif [[ "$(uname -s)" == "Darwin" ]]; then + echo "In MAC" + source newve/bin/activate + else + echo "In Windows" + source newve/Scripts/activate + fi + echo $VIRTUAL_ENV + pip install json2html + pip install xhtml2pdf + pip install bs4 + cd Validation + python sample_code_log_processor.py -l ../../${{inputs.sample-folder-name}}/${{inputs.log-file-name}} -o ../../${{inputs.sample-folder-name}}/${{inputs.lang}}_actual_results.json + python response_code_validator.py -e ExpectedResults/${EXPECTED_RES_LANG}_expected_results.json -a ../../${{inputs.sample-folder-name}}/${{inputs.lang}}_actual_results.json -o ${{inputs.lang}}_validation_results.json + python json_to_prettified_html.py -i ${{inputs.lang}}_validation_results.json -o ${{inputs.lang}}_validation_results.html + cp ${{inputs.lang}}_validation_results.pdf ../ #copying the file to flaatten the directory of the upload artifact,Github Actions doesn't support that as of jun 2024 + echo "pdfname=${{inputs.lang}}_validation_results.pdf" >> $GITHUB_OUTPUT + shell: bash + diff --git a/.github/workflows/java-workflow.yml b/.github/workflows/java-workflow.yml new file mode 100644 index 00000000..f3545bf9 --- /dev/null +++ b/.github/workflows/java-workflow.yml @@ -0,0 +1,83 @@ +name: JAVA BUILDS +on: + push: + pull_request: + workflow_dispatch: +env: + CLIENT_FOLDER: 'cybersource-rest-client-java' + SAMPLE_FOLDER: 'cybersource-rest-samples-java' +jobs: + complete-job: + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest,macos-latest,windows-latest] + java-version: ['8','11','16','17','18','19','20','21','22'] + distribution: ['temurin'] + runs-on: ${{matrix.operating-system}} + steps: + - name: Making separate folders + run: | + rm -rf $CLIENT_FOLDER + rm -rf $SAMPLE_FOLDER + mkdir $CLIENT_FOLDER $SAMPLE_FOLDER + - name: Checkout the cybersource-rest-client-java repo + uses: actions/checkout@v4 + with: + path: ${{env.CLIENT_FOLDER}} + - name: Checkout the cybersource-rest-samples-java repo + uses: actions/checkout@v4 + with: + repository: 'CyberSource/cybersource-rest-samples-java' + ref: 'master' + path: ${{env.SAMPLE_FOLDER}} + - name: Setup Java 8 to Build the Client + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '8' + - name: Build the Java Client + run: | + mvn -version + java -version + cd $CLIENT_FOLDER + mvn clean install + - name: Setup Java version to Build the samples + uses: actions/setup-java@v2 + with: + distribution: ${{matrix.distribution}} + java-version: ${{matrix.java-version}} + - name: Replace the Version of cybersource-rest-client-java in samples' pom file + run: | + cd $CLIENT_FOLDER + RESTCLIENT_SDK_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo $RESTCLIENT_SDK_VERSION + cd ../$SAMPLE_FOLDER + perl -i -spe "BEGIN{undef $/;} s|com\.cybersource<\/groupId>\s*cybersource-rest-client-java<\/artifactId>\s*.*?<\/version>|com.cybersource\n cybersource-rest-client-java\n \${version}|g" -- -version=$RESTCLIENT_SDK_VERSION pom.xml + cat pom.xml + - name: Build the Sample Project and Run the Samples + run: | + mvn -version + java -version + cd $SAMPLE_FOLDER + mvn -X -e clean install + echo "Running Samples" + java -jar target/SampleCode.jar > output.log + - name: Using Report Generation Action + id: report-generation + uses: ./cybersource-rest-client-java/.github/actions/generate-report + with: + lang: java + sample-folder-name: ${{env.SAMPLE_FOLDER}} + log-file-name: output.log + - name: Upload Test Reports + uses: actions/upload-artifact@v4 + with: + name: sample-run-report-${{matrix.operating-system}}-${{matrix.distribution}}-java-ver-${{matrix.java-version}} + path: | + ${{env.SAMPLE_FOLDER}}/${{steps.report-generation.outputs.result-pdf-name}} + +#Adding Comment \ No newline at end of file diff --git a/.gitignore b/.gitignore index a530464a..714cdef5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ hs_err_pid* target .gradle build + +#Adding DS Store files to ignore +.DS_Store diff --git a/README.md b/README.md index 0debeb94..c95c3b70 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Java Client SDK for the CyberSource REST API +[![JAVA BUILDS](https://github.com/CyberSource/cybersource-rest-client-java/actions/workflows/java-workflow.yml/badge.svg)](https://github.com/CyberSource/cybersource-rest-client-java/actions/workflows/java-workflow.yml) + ## Description The CyberSource Java client provides convenient access to the [CyberSource REST API](https://developer.cybersource.com/api/reference/api-reference.html) from your Java application. diff --git a/pom.xml b/pom.xml index 4be745bd..1fba4d81 100644 --- a/pom.xml +++ b/pom.xml @@ -279,7 +279,7 @@ - 1.7 + 1.8 ${java.version} ${java.version} 1.9.0