Skip to content

Enterprise · Code references

Set up with GitHub Actions

A workflow file, two secrets and one variable make every push to the default branch update the flag's code references.

Builds on:Code references

Video coming soon

Set up with GitHub Actions

Before you start

  • A system client token with the scopes Code references write and Evaluate (Overview).
  • Admin rights on the GitHub repository, to add secrets and variables.

Add the workflow

  1. Download fluxgate-code-refs.github.yml.
  2. Save it in your repository as .github/workflows/fluxgate-code-refs.yml.
  3. If your default branch is not main, change branches: [main] to its name.
  4. In GitHub, open Settings, Secrets and variables, Actions. On Secrets, add FLUXGATE_URL (your API URL, such as https://flags.example.com/api/v1) and FLUXGATE_TOKEN (the system client token).
  5. On Variables, add FLUXGATE_VERSION: the FluxGate release whose CLI the job downloads, such as v2.0.1. The job downloads it from https://flux.forgeopslabs.com/downloads/releases/<version>/.
  6. Commit the workflow to the default branch. The run FluxGate code references starts.

The job downloads the CLI archive for the runner, checks it against SHA256SUMS from the same release, and runs:

bash
fluxgate code-refs scan --context-lines 1 --default-branch <default branch>

Deleted branches

The workflow also runs when a branch is deleted. Its prune job runs:

bash
fluxgate code-refs prune --branch <deleted branch>

It deletes the stored scan of that branch. It never deletes the default branch, and a branch that was never scanned is skipped. A daily job on the backend also deletes branch scans that got no upload for 30 days.

Scan more branches

The workflow scans pushes to the default branch. To keep references of other long-lived branches, such as a release branch, add them to branches:

yaml
on:
  push:
    branches: [main, release]

Removal issues

The workflow can also open one issue per flag whose code should be removed. See Open removal issues.

Optional variables

VariableMeaning
FLUXGATE_DOWNLOAD_BASEDownload the CLI and SHA256SUMS from here instead of https://flux.forgeopslabs.com/downloads/releases/<version>, for example a mirror inside your network
FLUXGATE_CONTEXT_LINESLines sent above and below each match, 0 to 5. Default 1. Use 0 to send no code
FLUXGATE_SCAN_ARGSExtra scan arguments, separated by spaces and written without quotes, for example --exclude generated/**

Check the result

Open the job log. The last step prints the server's answer with refCount and unknownKeys: keys found in the code that name no flag of the team. Then open a flag in FluxGate: the Code references card lists the files and lines.