Once you've created a LaunchDarkly access token, store the newly created access token as a repository secret titled
LD_ACCESS_TOKEN. Under Settings > Secrets in your GitHub repo, you'll see a link to "Add a new secret". Click that and paste in your access token and click "Save secret".
GitHub secret configuration
Next, create a new Actions workflow in your selected GitHub repository. If you don't already have a workflow file, you'll need to create a new file titled
main.workflow in the
.github directory of your repository. Under "Edit new file", paste the following code:
workflow "Find flag references" on = "push" resolves = "find_flags" action "find_flags" secrets = "LD_ACCESS_TOKEN" env = LD_PROJ_KEY = "$YOUR_PROJECT_KEY" uses = "docker://launchdarkly/ld-find-code-refs-github-action:1.0.0"
If you already have a
main.workflow file, copy and paste the above to the bottom of your
main.workflow file. If you wish to verify that you've pasted the above correctly, you can go into the visual editor and ensure that there are no syntax errors.
Commit this file under a new branch. Submit as a PR to your code reviewers to be merged into your master branch. You do not need to have this branch merged into the master for code references to appear in the LaunchDarkly UI for your flags; code references will appear for this newly created branch.
As shown in the above example, the workflow should run on the
push event, and contain an action which uses
docker://launchdarkly/ld-find-code-refs-github-action as its action provider. The
LD_ACCESS_TOKEN configured in the previous step should be included as a secret, as well as a new environment variable containing your LaunchDarkly project key.
Once your workflow has been created, the best way to confirm that the workflow is executing correctly is to create a new pull request with the workflow file and verify that the newly created action succeeds.
If the action fails, there may be a problem with your configuration. To investigate, dig into the action's logs to view any error messages.
GitHub Action running
GitHub Action succeeded
ld-find-code-refs may be configured with additional environment variables to enable more functionality.
A LaunchDarkly personal access token with writer-level access, or access to the
code-reference-repository custom role resource. Should be supplied as a GitHub repository secret.
A LaunchDarkly project key. The flag finder will search this project for code references in this project.
A regular expression (PCRE) defining the files and directories which the flag finder should exclude. Partial matches are allowed. Examples:
The number of context lines above and below a code reference for the flag finder to send to LaunchDarkly.
If < 0, no source code will be sent to LaunchDarkly.
If 0, only the lines containing flag references will be sent.
If > 0, will send that number of context lines above and below the flag reference.
A maximum of 5 context lines may be provided. Defaults to 2
Set the base URL of the LaunchDarkly server for this configuration. Defaults to https://app.launchdarkly.com
Enables verbose default logging. Defaults to
Specifies additional delimiters used to match flag keys. Must be a non-control ASCII character. If more than one character is provided in delimiters, each character will be treated as a separate delimiter. Will only match flag keys with surrounded by any of the specified delimeters. This option may also be specified multiple times for multiple delimiters. By default, only flags delimited by single-quotes, double-quotes, and backticks will be matched. Default:
Here's an example of a workflow configured to exclude the vendor directory and send 1 line of context above and below each code reference for each flag in the "default" project:
workflow "Find flag references" on = "push" resolves = "find_flags" action "find_flags" secrets = "LD_ACCESS_TOKEN" env = LD_PROJ_KEY = "$YOUR_PROJECT_KEY" LD_EXCLUDE = "vendor/" LD_CONTEXT_LINES = "1" uses = "docker://launchdarkly/ld-find-code-refs-github-action:1.0.0"