Skip to content

Execute Spotbugs

Execute Spotbugs #154

Workflow file for this run

# GHA to run Spotbugs against top level Java agent projects. Both HTML and XML files are generated for each project
# and attached to the workflow run page under the "Artifacts" section. The files are downloaded as a zip (per project).
# The XML file can be analyzed inside the Spotbugs GUI: https://spotbugs.readthedocs.io/en/stable/running.html
name: Execute Spotbugs
on:
workflow_dispatch:
inputs:
agent-ref:
description: 'The ref (branch, SHA, tag) to run spotbugs on'
required: false
default: 'main'
type: string
schedule:
- cron: '0 9 * * *'
jobs:
spotbugs:
timeout-minutes: 15
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.agent-ref || github.ref || 'main' }}
- name: Configure AWS Credentials
if: ${{ env.AWS_KEY != '' }}
uses: aws-actions/configure-aws-credentials@v1-node16
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: Build newrelicJar
run: ./gradlew $GRADLE_OPTIONS clean jar
- name: Execute Spotbugs
run: ./gradlew $GRADLE_OPTIONS spotbugsMain
- uses: actions/upload-artifact@v3
with:
name: all-spotbugs-results
path: '**/build/spotbugs/main.*'
retention-days: 5
- uses: actions/upload-artifact@v3
with:
name: newrelic-agent-spotbugs-results
path: 'newrelic-agent/build/spotbugs/main.*'
retention-days: 5
- uses: actions/upload-artifact@v3
with:
name: newrelic-weaver-spotbugs-results
path: 'newrelic-weaver/build/spotbugs/main.*'
retention-days: 5
- uses: actions/upload-artifact@v3
with:
name: agent-bridge-spotbugs-results
path: 'agent-bridge/build/spotbugs/main.*'
retention-days: 5
- uses: actions/upload-artifact@v3
with:
name: agent-model-spotbugs-results
path: 'agent-model/build/spotbugs/main.*'
retention-days: 5
- uses: actions/upload-artifact@v3
with:
name: newrelic-api-spotbugs-results
path: 'newrelic-api/build/spotbugs/main.*'
retention-days: 5
publish:
needs: spotbugs
runs-on: ubuntu-20.04
concurrency: gh-pages
env:
BRANCH_NAME: ${{ inputs.agent-ref || 'main' }}
steps:
- name: Checkout GhPages branch
uses: actions/checkout@v3
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: Clear any artifacts from previous runs
run: |
rm -rf gh-pages/spotbugs/${{ env.BRANCH_NAME }}
# Download reports
- name: Download spotbugs reports 1
uses: actions/download-artifact@v3
with:
name: newrelic-agent-spotbugs-results
path: gh-pages/spotbugs/${{ env.BRANCH_NAME }}/newrelic-agent-spotbugs-results
- name: Download spotbugs reports 2
uses: actions/download-artifact@v3
with:
name: newrelic-weaver-spotbugs-results
path: gh-pages/spotbugs/${{ env.BRANCH_NAME }}/newrelic-weaver-spotbugs-results
- name: Download spotbugs reports 3
uses: actions/download-artifact@v3
with:
name: agent-bridge-spotbugs-results
path: gh-pages/spotbugs/${{ env.BRANCH_NAME }}/agent-bridge-spotbugs-results
- name: Download spotbugs reports 4
uses: actions/download-artifact@v3
with:
name: agent-model-spotbugs-results
path: gh-pages/spotbugs/${{ env.BRANCH_NAME }}/agent-model-spotbugs-results
- name: Download spotbugs reports 5
uses: actions/download-artifact@v3
with:
name: newrelic-api-spotbugs-results
path: gh-pages/spotbugs/${{ env.BRANCH_NAME }}/newrelic-api-spotbugs-results
# By default, GH-Pages only recognizes index.html files as landing pages.
# This can be reconfigured at the repository level, but not at the directory level.
# So copy the main.html files generated by spotbugs into index.html files.
- name: Copy the main.html files into index.html files
run: |
cd gh-pages/spotbugs/${{ env.BRANCH_NAME }}
cp newrelic-agent-spotbugs-results/main.html newrelic-agent-spotbugs-results/index.html
cp newrelic-weaver-spotbugs-results/main.html newrelic-weaver-spotbugs-results/index.html
cp agent-bridge-spotbugs-results/main.html agent-bridge-spotbugs-results/index.html
cp agent-model-spotbugs-results/main.html agent-model-spotbugs-results/index.html
cp newrelic-api-spotbugs-results/main.html newrelic-api-spotbugs-results/index.html
- name: Generate index page
run: |
python gh-pages/utils/writeIndexPage.py gh-pages/spotbugs/${{ env.BRANCH_NAME }}
# Used for cleanup and to ensure a file is always changed so the commit succeeds.
- name: Add date file
run: echo $(date -u +%s) > gh-pages/spotbugs/${{ env.BRANCH_NAME }}/date.txt
- name: Commit and push test reports to gh-pages
run: |
cd gh-pages
git add -f spotbugs/*
git commit -m "Update test reports spotbugs project"
git push
- name: Summary step
run: echo "[View spotbugs results](https://newrelic.github.io/newrelic-java-agent/spotbugs/${{ env.BRANCH_NAME }})" >> $GITHUB_STEP_SUMMARY