Skip to content
Latchkey

How to Log Experiments to a Tracker in GitHub Actions

Authenticate the tracker from a secret and tag each CI run with the commit SHA so every logged metric traces back to the code that produced it.

Export the tracker API key from a secret and set run metadata (commit, branch) from the GitHub context. Weights and Biases and MLflow both read the key from an environment variable, so no interactive login is needed.

Steps

  • Store the tracker API key as a repository secret.
  • Export it and pass the commit SHA as run metadata.
  • Log metrics from the training step.

Workflow

.github/workflows/ci.yml
jobs:
  train:
    runs-on: [self-hosted, gpu]
    env:
      WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}
      WANDB_RUN_GROUP: ci
    steps:
      - uses: actions/checkout@v4
      - run: pip install -e . wandb
      - name: Train and log
        run: python train.py --max-steps 50 --wandb-tags "sha:${GITHUB_SHA}"

Gotchas

  • Set an offline mode for PRs from forks, where secrets are unavailable.
  • Tag runs with the commit SHA so a metric regression maps to a specific change.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →