Cross Repository Maven-based Test Execution using GitHub Action Workflow

Wavda Aniva
3 min readApr 13, 2022

Cross Repository Maven-based Test Execution using GitHub Action Workflow

In this article I will be sharing how we can run maven-based test in your test repository using GitHub Action by triggering from another repository (e.g. your application repository).

Pre-Requisites

  1. Maven-based test project (e.g. my-test project)
  2. Application project in a separate GitHub repository (e.g. my-app project)

Setup Test Execution Workflow

1. Create a new .yml file within workflow folder for executing test using maven in your test project e.g. selenium-test.yml

2. The following selenium-test.yml configuration will execute your test every time a new workflow dispatch has been triggered

name: selenium
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn test

3. Another option is to use template .yml workflow file for maven from Actions > New Workflow > select “Configure” for Publish Java Package with Maven

4. Make sure your test project can be executed successfully using GitHub Action workflow by clicking Run Workflow

Setup Test Execution Trigger from App Project

This steps will allow your Test Project to be executed every time there are code push in your Application Project

1. Generate Personal Access Token for your Test Project through Your GitHub Account Profile > Settings > Developer Settings > Select “Personal Access Tokens” and Generate Token with “Repo” scope

2. Copy the newly generated token into your Application Project’s Action Secrets with:

  • TEST_TOKEN as PERSONAL ACCESS TOKEN
  • TEST_USERNAME as TEST PROJECT’S REPO OWNER NAME

3. Create new .yml workflow file within your Application Project

4. This workflow will trigger your Test Project every time there are code push action to your Application Project by creating a POST request to create a workflow dispatch event. Specify which branch you’d like to execute the workflow on in “ref” data (e.g. “ref”:”main”)

name: Trigger Test
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Trigger Test
run: |
curl -XPOST \
-u "${{secrets.TEST_USERNAME}}:${{secrets.TEST_TOKEN}}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/OWNER/my-test/actions/workflows/selenium-test.yml/dispatches \
-d '{"ref":"main"}'

5. The application project workflow will return a response that looks like this once it succeed triggering the test project workflow.

I hope this article can somehow be useful for you 😃 I am still in my very early exploration phase on GitHub Action and there will be a lot more to learn along the way which I am very excited about 😸

This article has been my main lead throughout the learning process, but some adjustments still needs to be done as the POST request for GitHub workflow dispatch has changed quite a bit over the years.

--

--

Wavda Aniva

A curious potato exploring new things on software quality