GitHub
GitHub is one of the most popular places to store code nowadays. You can integrate Perfecto with GitHub using GitHub Actions.
The examples in the following procedure are based on a Quantum project. The project is located here: https://github.com/Perfecto-Quantum/Quantum-Starter-Kit
Step-by-step instructions
-
Log in to your GitHub profile and click Repositories: https://github.com/<Your_Account>?tab=repositories
-
On the Repositories tab, click New.
-
In the Create a new repository dialog box, name your repo and click Create repository.
-
In the newly created repository, import your code.
In this example, we selected the second option (creating a new repository on the command line).
To create a new repository on the command line:
-
Open the command line and navigate to the project.
-
Run the following commands:
Copygit init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/<your_account>/Quantum-GHA.git
git push -u origin main
-
-
In GitHub, make sure the code is uploaded.
-
In GitHub, click Actions.
-
On the Get started with GitHub Actions, select one of the options displayed.. In the case of our example, we need Java with Maven. Setting the project up with this workflow generates the following YAML file:
CopyYAML file
#Maven
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B package --file pom.xmlThis file has a built-in setup to run/trigger your test on every push and pull request. You can change that by either deleting the unneeded rows or commenting them out. For demo purposes, we left them intact in the above code snippet.
-
To integrate with the CI Dashboard in Perfecto, do the following:
-
Delete
package
. -
Add the following line:
Copyclean install
-
At the end, add the following line:
Copy-Dreportium-job-name=GitHubActionsJob -Dreportium-job-number=$GITHUB_RUN_NUMBER -Dreportium-job-branch=QuantumBranch_GitHubActions
Your file should now look similar to the following:
CopyYAML file with CI Dashboard integration
#Maven
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B clean install --file pom.xml -Dreportium-job-name=GitHubActionsJob -Dreportium-job-number=$GITHUB_RUN_NUMBER -Dreportium-job-branch=QuantumBranch_GitHubActionsIn the updated YAML file above,
GITHUB_RUN_NUMBER
is used. This is a variable taken from GitHub and processed to Perfecto Smart Reporting. All GitHub variables are available here: https://docs.github.com/en/actions/learn-github-actions/variables
-
-
To save the file and start your first GitHub Actions, click Start commit.
-
In the Commit new file dialog box, select Commit directly to the
main
branch and then click Commit new file. -
Make sure the file was created.
-
In GitHub, go back to the Actions tab and make sure the workflow run icon is rotating.
When the run finishes successfully, the workflow icon turns green.
-
Update the YAML file by adding the following:
Copyschedule:
# * is a special character in YAML so you have to quote this string
- cron: '30 5,17 * * *'CopyYAML file with schedule information
#Maven
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '* 11 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B clean install --file pom.xml -Dreportium-job-name=GitHubActionsJob -Dreportium-job-number=$GITHUB_RUN_NUMBER -Dreportium-job-branch=QuantumBranch_GitHubActions
For more information on scheduling, see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows.