GitHub Actions Integration
GitHub Actions Integration
Introduction
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository or deploy merged pull requests to production.
GitHub Actions also lets you run workflows when other events happen in your repository. GitHub provides Linux, Windows, and macOS virtual machines to run your workflows, or you can host your own self-hosted runners in your own data center or cloud infrastructure.
Integrating Leapwork and GitHub Actions
The following step by step process guides you to integrate Leapwork and GitHub Actions:
- Create a new Workflow
.github/workflows/main.ymlfile in your GitHub Repository. - Copy the following contents into
.github/workflows/main.ymlfile:
name: Test Leapwork Action
on:
push:
branches:
- main
permissions: write-all
jobs:
run-action:
name: Test with Leapwork
runs-on: self-hosted
environment: test_environment
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Call Leapwork GitHub Action
uses: leapwork/Github-action@v1.0
with:
leapworkApiUrl: ${{ vars.LEAPWORK_API_URL }}
leapworkApiKey: ${{ secrets.LEAPWORK_API_KEY }}
leapworkSchedule: ${{ vars.LEAPWORK_SCHEDULE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
You can change the branch name, and environment in the above yml file.
Creating an Environment
To create an Environment, where your environment variables will reside, follow the below steps:
Click Settings.
Click New environment, enter the name of your choice for the environment, for example: Development.
Click Configure environment. This will be the name you will need to provide in the environment property in the yml file. You will be redirected to the environment configuration page as below.
The environment is created now.
Adding Environment variables and secrets
You can add the required environment variables and secrets on the environment configuration page.
- On the environment configuration page, under Environment variables section, click Add variable and add the below variables one by one.
LEAPWORK_API_URL- your Leapwork controller REST API URL, such ashttp://<controller-ip>:<port>/apiLEAPWORK_SCHEDULE- the name of your Leapwork schedule.
- Add the below secret under the Environment secrets section.
- Note: Here you can keep the API access key for Leapwork because you may not want to expose it in plain text. If that is not the concern, you can also add it in the Variables section as mentioned in the previous step.
LEAPWORK_API_KEY- the API key to access the REST API, also referred to as the "Access Key".
The Workflow requires a Runner to execute. In this case, you will need to host your own Runner where your Leapwork Controller is installed. Alternatively, you can setup your Runner on another machine, which can communicate with the Leapwork Controller.
Create Runner
- From Repository Home, go to Actions > Runners. Click Self-hosted runners tab on the page and click New Runner.
- Click New self-hosted runner.
- Select the Operating system on the next page. In this case, it is Windows and x64 Architecture.
- Launch a new PowerShell terminal with Administrative rights and ‘cd’ to your ‘C:\’ drive by executing the ‘cd C:\’ command.
- Execute command ‘mkdir actions-runner; cd actions-runner’. This creates a new folder with the name ‘actions-runner’ on your C drive and switch into that folder.
- Execute the below command.
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.311.0/actions-runner-win-x64-2.311.0.zip -OutFile actions-runner-win-x64-2.311.0.zip
The ZIP package downloads, which contains the installation files in your actions-runner folder.
- Execute the below optional but recommended command, which validates if the file you downloaded using the previous command is not corrupted.
if((Get-FileHash -Path actions-runner-win-x64-2.311.0.zip -Algorithm SHA256).Hash.ToUpper() -ne 'e629628ce25c1a7032d845f12dfe3dced630ca13a878b037dde77f5683b039dd'.ToUpper()){ throw 'Computed checksum did not match' }
If there is no additional message displayed once the verification is done, go to the next step. If you get an error message, delete the folder created in step ‘4’ and try again.
- Extract the files from the downloaded ZIP file.
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.311.0.zip", "$PWD")
- Configure the Runner on the machine.
- Execute the below command.
./config.cmd --url https://github.com/ YOUR_GITHUB_USERNAME/YOUR_REPOSITORY_NAME --token THE_TOKEN_WILL_BE_AUTO_FILLED_HERE
- Enter the name of the runner group to add this runner to: [press Enter for Default]: Press Enter. You can go with Default.
- Enter the name of the runner: [press Enter for LW-WIN-0487]: Provide any name for your Runner, or just accept the default one.
- Skip the step to provide additional tags.
- In Runner Settings options, select ‘Y’ when asked to run the Runner as a Service. This option will start Runner as a service automatically and you won’t need to run it manually each time you want to use it.
Would you like to run the runner as a service? (Y/N) [press Enter for N]: Y
5. Accept the default value in the next step.
User account to use for the service [press Enter for NT AUTHORITY\NETWORK SERVICE]:
- Your PowerShell Console should look like this:
Your setup is now complete and GitHub Actions is configured to run a schedule every time a new change is pushed to your repository.
References
- For more details on GitHub Actions, see: Understanding GitHub Actions - GitHub Docs.
- For more information on Runners, see: GitHub Actions Runner.
For any clarification, contact our Priority Support.