Flag Evaluations
Read time: 3 minutes
Last edited: Jul 10, 2024
Overview
This topic explains how to use the Flag Evaluations GitHub Actions integration. The integration lets you evaluate LaunchDarkly feature flags as a step in your GitHub workflow jobs and use those values in later steps.
GitHub Actions is a platform that allows you to automate, customize, and execute your software development workflows in your repository. Using LaunchDarkly feature flags, you can gain additional flexibility and control over your CI/CD pipeline.
Prerequisites
To complete this procedure, you must have the following prerequisites:
- An SDK token for the LaunchDarkly environment you are using for flag evaluation. Store the token as a repository secret titled
LAUNCHDARKLY_SDK_KEY
.
Set up Flag Evaluations
To set up Flag Evaluations:
- Log in to GitHub and navigate to your repo.
- Navigate to Settings, then Secrets and click Add a new secret.
- Paste in your SDK key to the field that appears and click Save secret.
- Return to your GitHub repository to create a new Actions workflow.
- If you already have an
action.yml
file: Copy and paste theeval-flags
job declaration below into the jobs section in youraction.yml
file. - If you don't already have a workflow file: Create a new file titled
action.yml
in the.github/workflows
directory of your repository. Paste theeval-flags
job declaration below into the Edit file section.
We strongly recommend that you update the uses
attribute value to reference the most recent tag in the launchdarkly/gha-flags repository. This pins your workflow to a particular version of the launchdarkly/gha-flags
action.
- Commit this file to the default branch of your repository.
Format of a flag evaluation
The workflow evaluates the flags listed under the flags
key of the action. Each flag that the workflow evaluates must include a flag key and fallback value.
The flag key identifies the flag. The SDK serves the fallback value if LaunchDarkly is unreachable or if the flag does not have an off variation set.
Configure your SDK: Evaluating flags
In the example workflow above, the key is test-boolean-flag
and the fallback value is false
.
Use output in subsequent steps
Each of the flag keys included in the job will have their evaluation output accessible at steps.<job id>.outputs.<flag key>
.
In the example above the flag key test-boolean-flag
is available using steps.ld.outputs.test-boolean-flag
.
GitHub Actions casts all value types to string in the output.
Contexts created by the integration
Each time you execute this action, the action creates up to three contexts. You can view the created contexts on your Contexts list.
This action creates or updates contexts based on the following mappings:
- The action maps environment variables starting with
GITHUB_
to a context with the kindGitHub
. - The action maps environment variables starting with
RUNNER_
to a context with the kindGitHubRunner
. - If you pass additional variables into the action, the action maps any variables starting with
LD_
to a context with the kindGitHubCustomAttributes
.
For a list of the automatically mapped in environment variables, read GitHub's default environment variables.
Limitations
This integration currently has the following limitations:
- Use of JSON feature flags is not officially supported.
- GitHub Actions casts output to
string
type. - If no fallback value is provided for a feature flag,
null
is returned for the value. - Code References does not surface flags used in workflow files.
Troubleshooting
After you create the workflow, you can confirm that it's working correctly by pushing an empty commit and verifying that the newly created action succeeds.
If the action fails, there may be a problem with your configuration. To investigate, review the action's logs to view any error messages.