Using the CLI with a public repository

Background

Launchable uses an API token for authentication between Launchable CLI and Launchable API. However, an API token usually can not be used for Open Source project since anyone can send a Pull Request and retrieve the Token.
To solve the problem, Launchable prepares another authentication mechanism called tokenless authentication. Instead of a static token, tokenless authentication uses a CI/CD service provider's public API to verify if tests are actually running. With tokenless authentication, OSS contributes optimize test execution without a static Launchable API token.

Prerequisites

    A project needs to be hosted on a public GitHub repository
    Currently, tokenless authentication supports GitHub Actions only

Preparation

    1.
    Sign up and create an organization and a workspace
    2.
    Contact us and tell in which project you enable tokenless authentication
    3.
    Set some extra environment variables on GitHub Actions

Environment Variables

Three environment variables need to be set to enable tokenless authentication:
    LAUNCHABLE_ORGANIZATION: Launchable organization name
    LAUNCHABLE_WORKSPACE: Launchable workspace name
    GITHUB_PR_HEAD_SHA: A pull request head SHA, which can be retrieved from ${{ github.event.pull_request.head.sha }}

Examples

Here's example of a GitHub Actions configuration with tokenless authentication:
1
name: Efficient pull request validation for Gradle example
2
3
on:
4
pull_request:
5
paths:
6
- gradle/**
7
8
env:
9
LAUNCHABLE_ORGANIZATION: "examples"
10
LAUNCHABLE_WORKSPACE: "gradle"
11
12
jobs:
13
build:
14
runs-on: ubuntu-latest
15
16
steps:
17
- uses: actions/[email protected]
18
with:
19
fetch-depth: 0
20
- uses: actions/setup-[email protected]
21
- name: Set up JDK 1.8
22
uses: actions/setup-[email protected]
23
with:
24
java-version: 1.8
25
26
- name: Pull request validation
27
run: |
28
# Get Launchable CLI installed. If you can, make it a part of the builder image to speed things up
29
pip3 install --user launchable~=1.0 > /dev/null
30
export PATH=~/.local/bin:$PATH
31
32
set -x
33
34
# Tell Launchable about the build you are producing and testing
35
launchable record build --name $BUILD_NAME --source ..
36
37
# Find 25% of the relevant tests to run for this change
38
launchable subset --target 25% --build $GITHUB_RUN_ID gradle src/test/java > subset.txt
39
40
function record() {
41
# Record test results
42
launchable record test --build $GITHUB_RUN_ID gradle build/test-results/test
43
}
44
45
trap record EXIT
46
47
# Run gradle with the subset of tests
48
./gradlew test $(< subset.txt)
49
working-directory: ./gradle
50
env:
51
GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
Copied!
For more examples and see how it works from an actual GitHub project, visit launchableinc/examples.
Last modified 1mo ago