GitHub Integration
#
OverviewThis guide explains how to modify GitHub Actions workflow file to enable Change Testing reports in Pull Requests and workflow artifacts.
This is a step-by-step instruction, make sure to fulfill prerequisites and then follow steps for integration
Change Testing report highlights the number of new and modified methods detected by Drill4J, their coverage status, and identifies untested methods that may pose potential Risks.
#
Report on Pull Requests- Detects changes between the source and target branches by comparing the latest commit in the source branch with the merge base commit in the target branch.
- Displays metrics on how thoroughly changes are tested.
- Handy for
feature/*
,fix/*
branches and other shorter-lived branches - Attached to Pull Requests as comments
GitHub Pull Request Report
#
Report on branch push- Identifies changes in a branch between the latest commit and the configured baseline commit. Generally, the baseline commit is a tagged commit that follows the
tagPattern
defined in the configuration file. - Best used in long-living branches such as
main
anddevelopment
- Attached to artifacts of workflow triggered on branch push event
GitHub Workflow Report
#
Prerequisites- Familiarity with the GitHub Actions
- Familiarity with GitHub secrets and variables
- Drill4J core services deployed.
#
Steps for integration- Configure Drill4J CI/CD Integration plugin
- Configure build step to send Git metadata to Drill4J
- Configure deployment step to enable Drill4J Application Agent
- Configure tests to enable Drill4J Test Agent
- Push initial data to Drill4J
- Generate Change Testing report on Pull request
- Generate Change Testing report on branch push event
#
Configure Drill4J CI/CD Integration pluginFollow CI/CD Integration Plugin - Adding Plugin section to add plugin to your Maven or Gradle project.
Generate API key using Drill4J UI. Save it to GitHub secrets and variables as
DRILL_API_KEY
Create
DRILL_API_URL
variable in GitHub secrets and variables. Set its value to Drill4J Admin Backend service API address (e.g.https://drill4j.my-host.foo/api
). Remember to add/api
at the endCreate a personal GitHub access token (classic).
- Select
repo
scope - that is necessary to post comments on Pull Requests. - Save it to GitHub secrets and variables with the name
DRILL_BOT_GITHUB_TOKEN
. Reports will be posted in comments from the corresponding user
- Select
Set the following environment variables to GitHub workflow file
env
section:
#
Modify build step to send Git metadata to Drill4JModify build step to call send build info command. It submits commit hash, author, and branch associated with build to Drill4J. It is necessary to identify application build in the Drill4J reports and dashboards.
#
Gradle#
MavenThe
github.head_ref
property instructscheckout@v4
action to check out the last commit of the branch.By default GitHub Pull Requests create local merge commit from target branch to the source branch. It exists only inside workflow environment and is never pushed to remote. That makes it impossible to map it to the rest of repo Git history.
See GitHub documentation (#1 and #2) and checkout@v4 Readme for more info
π§ TODO: add link to Metabase dashboards to verify Git metadata is submitted and detailed reports are avaialble π§
#
Deploy the app with Drill4J Application Agent#
Option 1 - app is launched with Maven or GradleSetup Application Agent with using CI/CD Integration Plugin - Application Agent section
Add
DRILL_COMMIT_SHA
env varible following the instruction below
#
Option 2 - application is launched as a standalone Java processAdd
DRILL_APPLICATION_AGENT_URL
to GitHub secrets and variables.Set its value to URL of release's .zip file from https://github.com/Drill4J/java-agent/releases
For example:
https://github.com/Drill4J/java-agent/releases/download/v0.9.4/agent-linuxX64-0.9.4.zip
Add the following step to download agent files (above the app launch step):
See Agent Parameters Reference for a full list of parameters
Set
DRILL_COMMIT_SHA
env varible following the instruction below
#
Add DRILL_COMMIT_SHA to env variables For Pull Request, set it to the github.event.pull_request.head.sha
:
For branch push event, set it to github.sha
:
π§ TODO: add link to Metabase dashboards to verify classes and methods information is available π§
#
Run tests with Drill4J Test AgentConfigure Maven or Gradle project to use Test Agent.
Once configured, Test Agent is launched with tests tasks automatically.
Make sure your tests are launched in GitHub Action workflow. Usually it looks something like this:
#
Push initial data to Drill4JBy now, both the Application Agent and Test Agent should be configured.
As the name suggests, the Change Testing report identifies changes, so the first step is to push data to Drill4J to establish a baseline for future comparisons. Ideally, this should be an application version built from your primary branch. We'll call it main
, but the branch name doesn't matter β it could be develop
or any other long-living branch.
- Push to the
main
branch to trigger the GitHub Action workflow to launch the application. - Wait for the workflow to complete.
- Check Metabase to verify that information about the new application build is available.
#
Generate report on Pull RequestNext, you need to configure the command to generate reports on Pull Requests. These reports will include metrics for changes introduced only in the specific Pull Request, allowing you to verify that the changes are tested before merging.
- Add an additional step to your workflow file using either the Gradle or Maven configuration provided.
- Push the changes and follow the instructions to verify that the reports are being generated.
#
Gradle#
Maven#
Confirm PR Report is WorkingNow it's time to create a new branch from the main
branch.
- Checkout a new branch (e.g.,
feature/xyz
). - Make some changes to your application code.
- Push the branch and open a Pull Request from
feature/xyz
tomain
. - Wait for the workflow to complete.
The comments section of the Pull Request should include a new comment with the report.
GitHub Pull Request Report
#
Generate report on Branch pushIn addition to reports on Pull Requests, itβs useful to have reports on individual branches. These reports are attached as workflow artifacts. To configure them:
Add the
baseline
section to CI/CD integration plugin configuration section:Gradle
Maven
<plugin><groupId>com.epam.drill.integration</groupId><artifactId>drill-maven-plugin</artifactId><version>0.1.6</version><configuration><groupId>my-group</groupId><appId>my-application</appId><!-- ... and other agent parameters ... --><!-- New section --><baseline><searchStrategy>SEARCH_BY_TAG</searchStrategy><!-- Adjust to match your tag naming scheme --><tagPattern>v[0-9].[0-9].[0-9]*</tagPattern></baseline></configuration><executions><execution><goals><goal>generateChangeTestingReport</goal></goals></execution></executions></plugin>Add additional step to your GitHub workflow file:
#
Gradle#
Maven#
Confirm its workingPush some changes. Once workflow is complete, check the attachments for uploaded report:
GitHub Workflow Report
#
Examplesπ§ TODO: cleanup example action yml file π§
You can see example GitHub Drill4J integration in a demo repository with the following GitHub Action