Continuous integration for research code: a practical setup guide
Which CI service to use, a first workflow you can copy, and how to handle data, randomness, GPUs and long runs without burning compute.

- CI installs and tests your code on a clean machine on every push, catching missing dependencies, silent result changes and breakage from new library versions.
- Use the CI built into your code host: GitHub Actions or GitLab CI. One short YAML file is enough to start.
- Test on tiny sample or synthetic data, compare numbers with tolerances and keep one regression test against a trusted result.
- Run fast tests on every push and move slow, GPU or licensed-software runs to scheduled jobs or self-hosted runners.
Continuous integration for research code means that every time someone pushes a change, a clean machine downloads the repository, installs the dependencies and runs the tests, then reports a pass or a fail on the commit. In short: put a small test suite and a tiny sample dataset in the repository, add one workflow file for GitHub Actions or GitLab CI, test on the Python, R or Julia versions your users actually have, compare numerical results with tolerances, and move anything slow or large to a scheduled job or your own runner.
Most labs test by hand: run the script, look at the figure, decide it looks right. That stops working when two people edit the same code, a dependency changes, or the person who knew what "right" looks like leaves. CI records that judgement as checks, so a broken unit conversion is caught the day it is introduced, not in the reviewer's report.
Industry teams treat CI as one half of a pipeline that also builds and ships software, and the CI/CD strategies for software developers used in commercial projects (fast feedback, small changes, automated gates before release) scale down well to a lab repository. This guide covers the research side: which service to pick, a first workflow you can copy, how to deal with data, randomness and long runs, and how to keep the whole thing cheap and green.
What does continuous integration actually do for a research project?
Continuous integration gives every change the same independent check, on a machine that has none of your local quirks. That catches three kinds of problem research code is prone to:
- "Works on my machine" bugs. A file path that only exists on your laptop, a package you installed months ago and forgot to list, an environment variable set in your shell profile.
- Silent regressions. A refactor that changes a result by a few percent without raising an error. The code still runs; only a test that checks the number notices.
- Dependency drift. A new release of NumPy, pandas or an R package changes a default or removes a function. A scheduled CI run finds out before your users do.
Four terms are enough to read any CI configuration. A workflow (GitHub) or pipeline (GitLab) is the whole automated process, stored as a YAML file in the repository. A job is a unit of work that runs on one machine. A step is one command or action inside a job. A runner is the machine that executes jobs, either hosted by the service or provided by you. The Turing Way chapter on GitHub Actions explains the same vocabulary with diagrams.
CI assumes you have something to run. If the repository has no tests yet, start with our guide to testing research code: even three tests and a smoke run of the main script make CI worthwhile.
Which CI service should a research group use?
Use the CI system built into the place where your code already lives. The Imperial College London guide to CI for research software ranks the integrated option of your version control host first, and for most labs that settles the question.
| Option | Best for | Cost to the lab | Watch out for |
|---|---|---|---|
| GitHub Actions | Code on GitHub, especially public repositories | Standard hosted runners are free for public repositories; private ones draw on a monthly minutes allowance | Hosted runners have limited CPU, memory and disk; no GPU on the free tier |
| GitLab CI/CD | Code on gitlab.com or an institutional GitLab | Compute minutes on gitlab.com; institutional instances often provide shared runners | Shared runners on a university instance may be few and busy |
| Self-hosted runner | GPU code, licensed software, large data, cluster access | Your hardware and admin time | Security: never attach a self-hosted runner to a public repository that accepts outside pull requests |
| Institutional or HPC CI services | Code that must be tested on the target supercomputer | Usually free to members | Queue times and site-specific setup; ask your RSE team first |
If your university has a research software engineering group, talk to them before building anything: many already run shared runners and keep templates for common languages. Our article on research software engineers explains how to find and work with them.
How do you set up a first CI workflow?
Start with one file that installs the project and runs the tests on one version of your language. For a Python project on GitHub, save this as .github/workflows/tests.yml:
name: tests
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- run: pip install -e ".[test]"
- run: pytest -q
Push it, open the Actions tab, and you will see the run and its log. The steps map directly to what you would do on a fresh laptop: get the code, install the language, install the project, run the tests. If the install step fails, CI has already done its job: it found a dependency missing from your project file. The layout from our guide to packaging Python research code makes the pip install -e ".[test]" line work.
For R, the r-lib project maintains ready-made actions that install R and run R CMD check; for Julia, the julia-actions set does the same with Pkg.test(). GitLab users write the equivalent in .gitlab-ci.yml, usually starting from an official language image such as python:3.12. Two habits help from day one: add a status badge to the README so readers see whether the code currently passes, and protect the main branch so pull requests cannot be merged while CI is red.
How do you test across language versions and operating systems?
Use a build matrix: one job definition that CI expands into a run per combination. Test what your users actually have, not every possible combination.
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.12"]
runs-on: ${{ matrix.os }}
Three operating systems times two versions gives six jobs per push. That is reasonable for a library other labs install; for an analysis repository that only ever runs on Linux, one OS and the oldest and newest supported versions are enough. Setting fail-fast: false lets every combination finish, so you see whether a failure is specific to Windows or to one version. The Carpentries intermediate research software lesson walks through a matrix like this step by step.
How do you handle data in CI?
Do not run CI on your real dataset. Hosted runners have limited disk and memory, downloads are slow, and research data is often confidential. Instead:
- Ship a tiny sample. A few hundred rows or one small image, checked into
tests/data/, that exercises the same code paths as the full dataset. - Generate synthetic data. A fixture that builds input with known properties, so the expected output is known by construction.
- Cache downloads. If a test needs a public reference file, download it once and cache it between runs, keyed on its checksum.
- Keep secrets out. Never commit credentials to fetch private data in CI. If a job must reach a protected store, use the service's encrypted secrets and run it only on branches inside the group, not on pull requests from forks.
Patient, participant or commercially restricted data should not leave the systems approved for it, and a hosted CI runner is not one of them. Test those pipelines on synthetic data in public CI, and run the real-data checks on a self-hosted runner inside the approved environment.
How do you check numerical results in CI?
Compare results with tolerances, fix random seeds and keep a small set of reference outputs. Exact equality on floating-point numbers will break the first time a runner uses a different CPU or a library changes its summation order.
- Tolerances. Use
numpy.testing.assert_allclose,pytest.approxorall.equalin R, and choose the tolerance from the science: how much difference would change a conclusion? - Seeds. Set the random seed explicitly in tests of stochastic code, and add at least one test that checks a statistical property (a mean within a range) rather than one exact draw.
- Regression tests. Store a small reference output from a version you trust, such as the one behind a published figure, and assert that the current code reproduces it within tolerance. When a change is meant to alter the result, update the reference in the same pull request and say why.
Run the same checks against a pinned environment as well as the latest dependencies. Our guide to reproducible environments covers lock files and containers; a container image used in CI is the same image a reviewer can use to rerun your analysis.
What about long runs, GPUs and licensed software?
Split the test suite by cost. Fast unit tests run on every push; slow integration tests and full-scale runs go to a scheduled job or a self-hosted runner.
- Mark slow tests (for example with a pytest marker) and skip them in the default job. Run them nightly or weekly with a
scheduletrigger, and on demand before a release. - GPU code needs a runner with a GPU: a self-hosted machine in the lab, a cloud instance started only for the job, or an HPC site's CI service. Keep a CPU fallback path so most tests still run on hosted runners.
- Licensed products such as MATLAB or commercial solvers can run on a self-hosted runner where the licence already lives. Check the licence terms; some vendors offer CI-specific options.
- Containers make complex but installable dependencies (compilers, MPI, system libraries) reproducible. Build the image once, publish it to a registry and run the tests inside it.
How do you keep CI fast, cheap and low-carbon?
Run only what a change needs, and stop work nobody will read. CI is not free even when it costs nothing: in a UCL research software blog post on using CI efficiently, one research repository used 1,937 runner hours in 30 days, which the author estimated at about 23 kWh a month. The same post lists the fixes:
| Setting | What it does |
|---|---|
concurrency with cancel-in-progress | Cancels the old run when you push again to the same branch |
paths / paths-ignore | Skips the test job when only docs or notebooks changed |
| Dependency caching | Reuses installed packages instead of downloading them every run |
timeout-minutes | Stops a hung job; GitHub's default job limit is six hours, far more than most test suites need |
| Job ordering | Runs a quick lint or smoke test first and the expensive matrix only if it passes |
| Schedules | Weekly rather than daily for heavy checks unless the code changes daily |
Speed also decides whether the check is used at all: when a pipeline is slow, people stop waiting for it and merge anyway.
What else can CI do besides running tests?
Once the pipeline exists, other chores fit into it at almost no extra cost:
- Linting and formatting with tools such as Ruff, lintr or JuliaFormatter, so style debates end in the config file.
- Building documentation on every change and publishing it to Pages or Read the Docs; our guide to documenting research software shows how to fail the build on broken references.
- Executing notebooks top to bottom, so tutorials and figure notebooks cannot quietly rot.
- Releases. Tagging a version can build the package and publish it, and with the Zenodo integration described in GitHub's guide to referencing and citing content each GitHub release is archived with its own DOI. Our guide to archiving code with a DOI covers the rest.
When should a lab bring in help with CI and deployment?
Bring in help when the pipeline has to do more than check code: deploy a shared web service, build mobile apps for a study, manage cloud infrastructure or meet a hospital's validation rules. At that point CI becomes CI/CD, with staging environments, deployment approvals and rollback plans, and someone needs to own it.
Options, roughly in order of cost: your institution's RSE team, a research software engineer funded on the grant, or an outside development team on a fixed scope. Whoever does the work, keep the pipeline definitions in the lab's own repository, documented, and make sure at least one person in the group can read and change them after the contract ends.
What to do this week: add CI to one repository
- Pick the repository that other people run most often.
- Make sure it installs from a clean environment with one command, and that it has at least a smoke test of the main script.
- Add the workflow file above, adapted to your language, with a
timeout-minuteslimit and dependency caching. - Add a tiny sample dataset and one regression test against a result you trust.
- Add the status badge to the README and protect the main branch.
- Move anything slower than a few minutes to a weekly scheduled job.
Questions about continuous integration for research code
What is continuous integration in research software?
Continuous integration automatically installs and tests the code on a clean machine every time someone pushes a change or opens a pull request, and reports pass or fail on the commit. It catches missing dependencies, silent changes in results and breakage from new library versions.
Is GitHub Actions free for research code?
Standard hosted runners are free for public repositories. Private repositories draw on a monthly minutes allowance that depends on the plan, and GPU or larger runners are paid. Many universities also offer shared GitLab runners.
How do I test research code that needs large data?
Do not use the full dataset in CI. Check in a tiny sample or generate synthetic data with known properties, cache public reference files, and run real-data checks on a self-hosted runner inside the environment approved for that data.
How do I test numerical results that change slightly between machines?
Compare with tolerances instead of exact equality, for example numpy.testing.assert_allclose or pytest.approx, fix random seeds, and keep a small reference output from a trusted version as a regression test.
How do I run GPU or long-running tests in CI?
Run fast unit tests on every push and move slow or GPU tests to a scheduled job or a self-hosted runner with the right hardware. Keep a CPU path so most tests still run on hosted runners.
Keep reading. More from the desk.
Testing research code: where to start
You already check your results by hand. Automated tests do the same checks every time the code changes, so a quiet bug gets caught the same day instead of in review.
Reproducible environments for research code
Sharing your code is step one. Making sure it still runs on someone else's machine, next year, is step two. The tools are mature. The hard part is choosing the right level of effort.

How to package Python research code so others can install it
A package gives research code one home, one version and one way in. This guide covers the src layout, pyproject.toml, tests, releases, citation and PyPI.