Unit Tests #1604
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Unit Tests | |
on: | |
workflow_dispatch: | |
inputs: | |
agent-ref: | |
description: 'The ref (branch, SHA, tag?) to run the tests on' | |
required: false | |
default: 'main' | |
type: string | |
workflow_call: | |
inputs: | |
agent-ref: | |
description: 'The ref (branch, SHA, tag?) to run the tests on' | |
required: false | |
default: 'main' | |
type: string | |
jobs: | |
unit-test: | |
name: Java ${{ matrix.java-version }} | |
timeout-minutes: 150 | |
runs-on: ubuntu-20.04 | |
strategy: | |
# max-parallel: 1 ## used to force sequential vs. concurrent | |
fail-fast: false | |
matrix: | |
java-version: [ 8, 11, 17, 21, 23 ] | |
steps: | |
- name: Checkout Java agent | |
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4 | |
with: | |
ref: ${{ inputs.agent-ref || github.ref || 'main' }} | |
- name: Configure AWS Credentials | |
if: ${{ env.AWS_KEY != '' }} | |
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # pin@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-2 | |
- name: Setup environment | |
uses: ./.github/actions/setup-environment | |
- name: Run unit tests that do not require a forked JVM (attempt 1) | |
id: run_tests_1 | |
continue-on-error: true | |
timeout-minutes: 20 | |
run: ./gradlew $GRADLE_OPTIONS test -x :functional_test:test -x :newrelic-scala3-api:test -x :newrelic-scala-api:test -x :newrelic-scala-cats-api:test -x :newrelic-cats-effect3-api:test -x :newrelic-scala-monix-api:test -x :newrelic-scala-zio-api:test -x :newrelic-scala-zio2-api:test -Ptest8 -PnoInstrumentation -PnonForkedTests --continue | |
- name: Run unit tests that do not require a forked JVM (attempt 2) | |
id: run_tests_2 | |
continue-on-error: true | |
timeout-minutes: 20 | |
if: steps.run_tests_1.outcome == 'failure' | |
run: ./gradlew $GRADLE_OPTIONS test -x :functional_test:test -x :newrelic-scala3-api:test -x :newrelic-scala-api:test -x :newrelic-scala-cats-api:test -x :newrelic-cats-effect3-api:test -x :newrelic-scala-monix-api:test -x :newrelic-scala-zio-api:test -x :newrelic-scala-zio2-api:test -Ptest8 -PnoInstrumentation -PnonForkedTests --continue | |
- name: Run unit tests that do not require a forked JVM (attempt 3) | |
timeout-minutes: 20 | |
if: steps.run_tests_2.outcome == 'failure' | |
run: ./gradlew $GRADLE_OPTIONS test -x :functional_test:test -x :newrelic-scala3-api:test -x :newrelic-scala-api:test -x :newrelic-scala-cats-api:test -x :newrelic-cats-effect3-api:test -x :newrelic-scala-monix-api:test -x :newrelic-scala-zio-api:test -x :newrelic-scala-zio2-api:test -Ptest8 -PnoInstrumentation -PnonForkedTests --continue | |
- name: Upload coverage to Codecov | |
if: matrix.java-version == '17' | |
uses: codecov/codecov-action@6d798873df2b1b8e5846dba6fb86631229fbcb17 # pin@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: '**/build/reports/jacoco/test/jacocoTestReport.xml' | |
fail_ci_if_error: false #default is false, but being explicit about what to expect. | |
- name: Capture Jacoco reports | |
if: matrix.java-version == '17' | |
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # pin@v4 | |
with: | |
name: non-forked-jacoco-reports-java-${{ matrix.java-version }} | |
path: | | |
**/build/reports/jacoco/** | |
- name: Capture build reports (non forked) | |
# If previous step fails, run this step regardless | |
if: failure() | |
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # pin@v4 | |
with: | |
name: non-forked-tests-results-java-${{ matrix.java-version }} | |
# The regex for the path below will capture unit test HTML reports generated by gradle for all | |
# related modules: (agent-bridge, newrelic-java, newrelic-api, etc). | |
# However, it's critical that the previous build step does a ./gradlew clean or the regex will capture test reports | |
# that were leftover in unrelated modules for functional and instrumentation tests. | |
path: | | |
**/build/reports/tests/* | |
- name: Run unit tests that require a forked JVM (attempt 1) | |
id: run_forked_tests_1 | |
continue-on-error: true | |
timeout-minutes: 20 | |
run: ./gradlew $GRADLE_OPTIONS test -x :functional_test:test -x :newrelic-scala3-api:test -x :newrelic-scala-api:test -x :newrelic-scala-cats-api:test -x :newrelic-cats-effect3-api:test -x :newrelic-scala-monix-api:test -x :newrelic-scala-zio-api:test -x :newrelic-scala-zio2-api:test -Ptest8 -PnoInstrumentation -PforkedTests --continue | |
- name: Run unit tests that require a forked JVM (attempt 2) | |
id: run_forked_tests_2 | |
continue-on-error: true | |
timeout-minutes: 20 | |
if: steps.run_forked_tests_1.outcome == 'failure' | |
run: ./gradlew $GRADLE_OPTIONS test -x :functional_test:test -x :newrelic-scala3-api:test -x :newrelic-scala-api:test -x :newrelic-scala-cats-api:test -x :newrelic-cats-effect3-api:test -x :newrelic-scala-monix-api:test -x :newrelic-scala-zio-api:test -x :newrelic-scala-zio2-api:test -Ptest8 -PnoInstrumentation -PforkedTests --continue | |
- name: Run unit tests that require a forked JVM (attempt 3) | |
id: run_forked_tests_3 | |
timeout-minutes: 20 | |
if: steps.run_forked_tests_2.outcome == 'failure' | |
run: ./gradlew $GRADLE_OPTIONS test -x :functional_test:test -x :newrelic-scala3-api:test -x :newrelic-scala-api:test -x :newrelic-scala-cats-api:test -x :newrelic-cats-effect3-api:test -x :newrelic-scala-monix-api:test -x :newrelic-scala-zio-api:test -x :newrelic-scala-zio2-api:test -Ptest8 -PnoInstrumentation -PforkedTests --continue | |
- name: Upload coverage to Codecov | |
if: matrix.java-version == '17' | |
uses: codecov/codecov-action@6d798873df2b1b8e5846dba6fb86631229fbcb17 # pin@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: '**/build/reports/jacoco/test/jacocoTestReport.xml' | |
fail_ci_if_error: false #default is false, but being explicit about what to expect. | |
- name: Capture Jacoco reports | |
if: matrix.java-version == '17' | |
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # pin@v4 | |
with: | |
name: forked-jacoco-reports-java-${{ matrix.java-version }} | |
path: | | |
**/build/reports/jacoco/** | |
- name: Capture build reports (forked) | |
if: failure() | |
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # pin@v4 | |
with: | |
name: forked-tests-results-java-${{ matrix.java-version }} | |
# The regex for the path below will capture unit test HTML reports generated by gradle for all | |
# related modules: (agent-bridge, newrelic-java, newrelic-api, etc). | |
# However, it's critical that the previous build step does a ./gradlew clean or the regex will capture test reports | |
# that were leftover in unrelated modules for functional and instrumentation tests. | |
path: | | |
**/build/reports/tests/* | |
- name: Checkout GhPages branch | |
if: ${{ failure() }} | |
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4 | |
with: | |
ref: 'gh-pages' | |
path: 'gh-pages' | |
- name: Configure Git | |
if: ${{ failure() }} | |
run: | | |
git config --global user.name "GitHub Actions Bot" | |
git config --global user.email "[email protected]" | |
- name: Download test reports Java ${{ matrix.java-version }} | |
if: ${{ failure() }} | |
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # pin@v4 | |
with: | |
name: unit-tests-results-java-${{ matrix.java-version }} | |
path: gh-pages/reports/${{ inputs.agent-ref }}/${{ github.run_id }}/unit-tests-results-java-${{ matrix.java-version }} | |
- name: Set up Python | |
if: ${{ failure() }} | |
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # pin@v5 | |
#This step executes a Python script that reads and writes html. | |
#The script requires the beautifulsoup dependency, which parses html. | |
#For details, view the utils/README.md on the gh-pages branch. | |
- name: Generate Test Reports page | |
if: ${{ failure() }} | |
run: | | |
pip install beautifulsoup4 | |
python gh-pages/utils/writeTestsFailuresPage.py gh-pages/reports/${{ inputs.agent-ref }}/${{ github.run_id }}/unit-tests-results-java-${{ matrix.java-version }} | |
- name: Commit and push test reports to gh-pages | |
if: ${{ failure() }} | |
run: | | |
cd gh-pages | |
git add -f reports/* | |
git commit -m "Update test reports" | |
git pull --rebase | |
git push | |
index: | |
name: Write Index Pages | |
needs: unit-test | |
if: ${{ failure() }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout GhPages branch | |
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4 | |
with: | |
ref: 'gh-pages' | |
path: 'gh-pages' | |
- name: Configure Git | |
run: | | |
git config --global user.name "GitHub Actions Bot" | |
git config --global user.email "[email protected]" | |
- name: Set up Python | |
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # pin@v5 | |
- name: Generate Index Pages | |
run: | | |
python gh-pages/utils/writeIndexPage.py gh-pages/reports/${{ inputs.agent-ref }} | |
python gh-pages/utils/writeIndexPage.py gh-pages/reports/${{ inputs.agent-ref }}/${{ github.run_id }} | |
#For cleanup purposes | |
- name: Add date file | |
run: | | |
date -u +%s > gh-pages/reports/${{ inputs.agent-ref }}/date.txt | |
date -u +%s > gh-pages/reports/${{ inputs.agent-ref }}/${{ github.run_id }}/date.txt | |
- name: Commit and push test reports to gh-pages | |
run: | | |
cd gh-pages | |
git add -f reports/* | |
git commit -m "Update test reports" | |
git push | |
- name: Gh Pages Summary | |
run: | | |
echo "[View test reports](https://newrelic.github.io/newrelic-java-agent/reports/${{ inputs.agent-ref }}/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY |