GitHub code references
Read time: 3 minutes
Last edited: Dec 14, 2024
Code references are only available to customers on select plans. To learn more, read about our pricing. To upgrade your plan, contact Sales.
If you're on a Developer or Foundation plan, instead you can use the Flag Code References in Pull Request GitHub Action.
LaunchDarkly has multiple integrations with GitHub Actions. To learn more, read about the LaunchDarkly integrations Find Code References in Pull Request and Flag Evaluations.
Overview
This topic explains how to use the ld-find-code-refs
utility with GitHub Actions to automatically populate code references in LaunchDarkly. To learn more about the utility and check for the latest version, read LaunchDarkly Code References with GitHub code references.
Prerequisites
To complete this procedure, you must have the following prerequisites:
- An API access token with write permissions for the
code-reference-repository
resource, either through the built-in Writer role or a custom role. The token must be stored as a repository secret titledLD_ACCESS_TOKEN
. To learn more, read API access tokens and Code reference actions.
Set up GitHub code references
To set up GitHub code references:
- Log into GitHub and navigate to your repo.
- Navigate to Settings then Secrets and click Add a new secret.
- Paste in your access token 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 thelaunchDarklyCodeReferences
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 the following code in the Edit file section:
We strongly recommend that you update the second uses
attribute value to reference the most recent tag in the launchdarkly/find-code-references repository. This pins your workflow to a particular version of the launchdarkly/find-code-references
action.
- Commit this file under a new branch and submit as a PR to your code reviewers to be merged into your main branch.
You do not need to have this branch merged into the main branch for code references to appear in the LaunchDarkly user interface (UI). Code references will appear for this newly created branch.
As shown in the example above, the workflow should run on the push
event and contain an action provided by the launchdarkly/find-code-references repository.
Include the LD_ACCESS_TOKEN
as a secret, and include a new environment variable containing your LaunchDarkly project key. This is represented by YOUR_PROJECT_KEY
in the above example. Do not use an environment's SDK key, mobile key, or client-side ID for this purpose. To learn how to find your project key, read Project keys.
Troubleshooting
After you create the workflow, you can confirm that it's working correctly by creating a new pull request with the workflow file 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.
Additional configuration options
You can configure find-code-references
with additional inputs to enable more functionality. You can find additional configuration options at the bottom of the LaunchDarkly Code References marketplace page.
In addition to inputs, you can skip searching files and directories using a .ldignore
file.
You can also use the .launchdarkly/coderefs.yaml
file for advanced configuration options, such as configuring custom delimiters and aliases for your flag keys.