Cross Repository Triggering in GitHub Actions-Trigger your Test Automation project through the workflow of the Application.

Hello friends!!! Today I am going to explain you how to do cross repository triggering using GitHub Actions. First of all, let me explain my scenario.
I have a UI Test Automation project resides in a GitHub repository which is supposed to be triggered by the work flow of the web application it runs against. The web application resides in a separate repository.
Given bellow is a successful POC I did to achieve the above target. And this can also be applied for other scenarios where you need to trigger a workflow of one repository by a workflow in another repository.
I will be referring to the UI Test Automation as Test project and the Web Application as Application.
Prerequisites
- The Test Project has a workflow which is running in GitHub without any issues. Having issues in integrating your UI test automation project with GitHub??? Follow my blog on Run Maven Selenium UI Automation Tests with GitHub Actions
- The Application has a workflow which is running in GitHub without any issues.
Creating a personal access token
Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line. Let’s see how to create one.
- In GitHub click on the arrow near the profile picture in upper right corner (That’s found in any page once you logged in to GitHub). Select Settings.

2. Click on Developer settings in left sidebar.

3. Click on Personal access tokens in left sidebar.

4. Click on Generate new token.

5. Name your token

6. Select the scope for your token, for our purpose just Repo level access is enough.

7. Click Generate token.

8. Click on the copy icon to copy the token. Once you navigate off the page the token will not be visible again.

Creating a secret
Secret in GitHub is an encrypted environment variable that can be created in an organization, repository, or repository environment level.
For our purpose we need to create two secrets. We have to create them in repository level within the repository of the Application. That means the secrets has to be created in the repository of the workflow which is going to trigger another workflow.
- Navigate to the main page of the repository of the Application.

2. Click on Secrets in the left sidebar

3. Click on New repository secret.

4. Create two secrets. One as PAT_USERNAME with your username, and the other as PAT_TOKEN with the personal access token that you already generated.

Updating the workflow files
Test Project Workflow
We have to use an event called “repository_dispatch”. Given bellow is the workflow file I used for my Test Project.
name: Java CIon: repository_dispatchjobs:build:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v2- name: Set up JDK 1.8uses: actions/setup-java@v1with:java-version: 1.8- name: Build with Mavenrun: mvn test
Application workflow
From the work flow of the application, we have run a curl script. Append the existing file with following script.
For Ubuntu
run: |curl -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/YOURNAME/APPLICATION_NAME/dispatches --data '{"event_type": "build_application"}'
For Windows
run: |
curl.exe -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/YOURNAME/APPLICATION_NAME/dispatches --data '{\"event_type\": \"build_application\"}'
Replace YOURNAME with your GitHub user name
Replace APPLICATION_NAME with the repository name of your Test Application.
Result
Once the workflow of your Application is successfully completed, your Test application workflow will be triggered.
Congratulations!!! You just completed your very first cross repository triggering workflow in GitHub.
References
1. https://github.community/t/triggering-by-other-repository/16163
3. https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets