mirror of
https://github.com/NationalSecurityAgency/datawave.git
synced 2026-11-11 17:32:57 -10:00
129 lines
5.8 KiB
YAML
129 lines
5.8 KiB
YAML
name: Microservice Tests
|
|
|
|
on:
|
|
workflow_call:
|
|
|
|
env:
|
|
JAVA_VERSION: '11'
|
|
JAVA_DISTRIBUTION: 'zulu' #This is the default on v1 of the action for 1.8
|
|
MAVEN_OPTS: "-Djansi.force=true -Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Djava.awt.headless=true -XX:ThreadStackSize=1m -Daether.connector.basic.threads=8 -Daether.metadataResolver.threads=8 -Daether.syncContext.named.time=480"
|
|
# Released microservice parents do not set a minimum heap for Surefire forks.
|
|
JAVA_TOOL_OPTIONS: "-Xms128m"
|
|
GITHUB_REGISTRY: ghcr.io
|
|
GITHUB_USERNAME: ${{ secrets.GHCR_WRITE_USER_NAME }}
|
|
GITHUB_PASSWORD: ${{ secrets.GHCR_WRITE_ACCESS_TOKEN }}
|
|
|
|
# Only checkout is needed: the test report is written to the job summary by a
|
|
# local Python script (.github/scripts/junit_flaky_report.py), so no checks or
|
|
# pull-requests permissions are required.
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
configure-runner:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- id: set_output_step # at least one step is required in a job
|
|
run: |
|
|
echo "Determining runner to be ${{vars.RUNNER_TYPE}}"
|
|
echo "runner=${{vars.RUNNER_TYPE}}" >> $GITHUB_OUTPUT
|
|
if [[ "${{ vars.RUNNER_TYPE }}" == "self-hosted" ]]; then
|
|
echo "We have hit the true case"
|
|
echo "cache_settings=-Dmaven.build.cache.enabled=false -Dmaven.build.cache.remote.enabled=false -Dmaven.build.cache.remote.url=http://localhost:12345" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "We have reached the false case"
|
|
echo cache_settings="" >> $GITHUB_OUTPUT
|
|
fi
|
|
echo $GITHUB_OUTPUT
|
|
outputs:
|
|
runner: ${{ steps.set_output_step.outputs.runner }}
|
|
cache_settings: ${{ steps.set_output_step.outputs.cache_settings }}
|
|
# Runs the pom sorter and code formatter to ensure that the code
|
|
# is formatted and poms are sorted according to project rules. If changes are found,
|
|
# they are committed back to the branch
|
|
|
|
# Build the code and run the unit/integration tests.
|
|
build-and-test-microservices:
|
|
needs: configure-runner
|
|
runs-on: ${{ needs.configure-runner.outputs.runner }}
|
|
steps:
|
|
- name: Set owner of working dir and m2 dir recursively
|
|
#Needed because compose can leave around files owned by root.
|
|
run: |
|
|
if [[ "${{ needs.configure-runner.outputs.runner }}" == "self-hosted" ]]; then
|
|
sudo chown -R $(whoami) . ~/.m2 || true
|
|
fi
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v6
|
|
# Clean up free space
|
|
- uses: ./.github/actions/free-space
|
|
with:
|
|
tool-cache: false
|
|
# Self-hosted runners are persistent, so `docker image prune --all` deletes
|
|
# the layer cache every build depends on and can remove images a co-tenant
|
|
# job is still using. Hosted runners are disposable, so let it run there.
|
|
docker-images: ${{ needs.configure-runner.outputs.runner != 'self-hosted' }}
|
|
- name: Configure Maven Settings
|
|
run: |
|
|
mkdir -p ~/.m2
|
|
cat > ~/.m2/settings.xml <<'EOF'
|
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
|
|
<servers>
|
|
<server>
|
|
<id>github-datawave</id>
|
|
<username>${env.GITHUB_USERNAME}</username>
|
|
<password>${env.GITHUB_PASSWORD}</password>
|
|
</server>
|
|
</servers>
|
|
<mirrors>
|
|
<mirror>
|
|
<id>google-maven-central</id>
|
|
<name>Google Cloud Maven Central Mirror</name>
|
|
<url>https://maven-central.storage-download.googleapis.com/maven2/</url>
|
|
<mirrorOf>central</mirrorOf>
|
|
</mirror>
|
|
</mirrors>
|
|
</settings>
|
|
EOF
|
|
- name: Set up JDK ${{env.JAVA_VERSION}}
|
|
uses: actions/setup-java@v5
|
|
with:
|
|
distribution: ${{env.JAVA_DISTRIBUTION}}
|
|
java-version: ${{env.JAVA_VERSION}}
|
|
cache: 'maven'
|
|
overwrite-settings: false
|
|
- name: Build and Run Unit Tests
|
|
run: |
|
|
cd microservices
|
|
mvn --show-version --batch-mode --errors --no-transfer-progress "-Dstyle.color=always" -Pexamples,assemble,spotbugs ${{ needs.configure-runner.outputs.cache_settings }} -Ddeploy -Ddist -T1.0C -Dsurefire.forkCount=1 -Dsurefire.maxMemory=2048m clean install -Dsurefire.rerunFailingTestsCount=3 -Dstarters -Dservices -Dutils -DskipITs -DskipFormat
|
|
- name: Run Integration Tests
|
|
run: |
|
|
cd microservices
|
|
mvn --show-version --batch-mode --errors --no-transfer-progress "-Dstyle.color=always" -Pexamples ${{ needs.configure-runner.outputs.cache_settings }} -Ddeploy -T1.0C -DforkCount=1 -DargLine="-Xms128m -Xmx2048m" verify -Dfailsafe.rerunFailingTestsCount=3 -Dstarters -Dservices -Dutils -DskipUTs -DskipFormat -DskipSpotbugs -Denforcer.skip=true -Dcheckstyle.skip=true
|
|
# Always upload the raw surefire/failsafe XML so failures and flakes are inspectable.
|
|
- name: Upload Test Reports
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: test-reports-microservices
|
|
path: |
|
|
microservices/**/target/surefire-reports/**
|
|
microservices/**/target/failsafe-reports/**
|
|
retention-days: 14
|
|
if-no-files-found: warn
|
|
# Summarize the JUnit XML into the job summary, surfacing tests that needed
|
|
# reruns (flakes) which the rerunFailingTestsCount otherwise hides. Uses a
|
|
# local stdlib-only Python script instead of a Marketplace action.
|
|
# Non-gating: no --fail-on-* flags + continue-on-error.
|
|
- name: Publish Test Report
|
|
if: always()
|
|
continue-on-error: true
|
|
run: |
|
|
python3 .github/scripts/junit_flaky_report.py \
|
|
--title 'Microservice Test Report' \
|
|
'microservices/**/target/*-reports/TEST-*.xml'
|
|
|
|
|