GitHub Actions
LabScale jobs or workflows can be triggered remotely by CICD pipelines via the LabScale CLI. Using the LabScale CLI to invoke a GitHub action.
Acquire the CLI Key
In order to start jobs or workflows within LabScale, you will need to make calls to the LabScale service via the LabScale CLI. For this example, you only require the CLI access keys required to authenticate with the LabScale service and we will use the GitHub workflow to fetch the CLI and invoke it.
- In the sidebar of the LabScale application, click on the Admin menu item.
- Then click on the CLI Keys menu item.
- Cick on the CREATE A NEW KEY button in the upper right side of the page. You will see the New Access Kye dialog. Copy the Secret Key.
- On GitHub, open Settings and then Secrets and variables. Select Actions.
- Click the New repository secret button. Enter LABSCALE_AUTH_TOKEN as the Name, and then paste the Secret Key from the task above into the Secret box.
- On the same GitHub page, click on the Variables tab (next to Secrets).
- CLick on the New repository variable button.
- Enter LABSCALE_CLIENT_ID into the Name field, then copy and paste the Client ID from the New Access Key dialog into the Value box.
- Finally, create another variable named LABSCALE_TEAM_ID and copy the Team ID from the New Access Key dialog into the Value box.
Configure a GitHub Workflow
GitHub allows you to create Workflows that perform GitHub Actions. This can be used to kick off automation in LabScale whenever pull events occur in the GitHub repo. Below is an example GitHub worklow. Replace the_release_id
, the_pool_id
, and the_workflow_id
with the release ID of the project artifact being built, the pool ID for the device pool where the job will be sent, and the LabScale workflow ID for the workflow that conatins the list of jobs to execute, then save it as example-labscale.yaml
to your repo's .github/workflow
folder.
# This is a basic workflow to help you get started with Actions
name: Trigger Device Tests via LabScale
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: ["main"]
pull_request:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Install labscale-cli
- name: Install labscale-cli
run: |
curl -s 'https://files.labscale.com/cli/installer/labscale-cli-install.tgz' | tar xzf -
./labscale-cli-install.sh ''
# Runs a set of commands using the runners shell
- name: Trigger workflow in LabScale
shell: bash
env:
# Environment varaibles required by the LabScale CLI
LABSCALE_BROKER_URL: tls://broker.labscale.com:443
LABSCALE_TEAM_ID: ${{ vars.LABSCALE_TEAM_ID }}
LABSCALE_CLIENT_ID: ${{ vars.LABSCALE_CLIENT_ID }}
LABSCALE_SECRET_TOKEN: ${{ secrets.LABSCALE_AUTH_TOKEN }}
run: |
./labscale-cli/labscale-cli config -show
./labscale-cli/labscale-cli trigger -releaseId "the_release_id" -buildNumber ${{ github.run_number }} -deviceTypeId '000000000000' -poolId "the_pool_id" -workflowId "the_workflow_id" -exitOnComplete