Guides

Run Tenon in CI

Check your model and test your components in a GitLab pipeline or a GitHub Actions workflow, with the same commands you run locally.

This guide sets up a pipeline that runs your project’s workflow on every change: it builds your component, checks and model-checks your Flex model, tests each component, and traces your requirements into a dashboard you can open from the run. Tenon writes the pipeline for GitLab CI, GitHub Enterprise Cloud (github.com included) or GitHub Enterprise Server. Every job runs the same tenon commands as tenon workflow run does on your machine, so a result in CI means what it means locally.

Before you begin

  • A Tenon project in your repository, with a workflow that runs cleanly on your machine. The Quickstart gets you there.
  • Runners that can run containers. On GitLab, that’s the Docker or Kubernetes executor: a component that talks through a message broker gets the broker as a job service, which the shell executor can’t run. On GitHub Enterprise Cloud, GitHub’s hosted ubuntu-latest runners work as they are. On GitHub Enterprise Server, you need self-hosted Linux runners with Docker, at runner version 2.327.1 or later.
  • A container registry your runners can pull from, and that you can push to. GitHub jobs log in to it, so they need a username and a read-only token for it.
  • A license server your runners can reach, with floating seats. A CI job runs on a different machine each time, so it can’t use a node-locked seat.
  • Your bundle, unpacked, for its root-pub.pem, the trust root your pipeline needs.

1. Push Tenon’s image

Every job in the pipeline runs in Tenon’s image, which holds Tenon and the Verifier together. The Verifier runs inside the job itself, so the pipeline needs no Docker-in-Docker. Log in to your registry, then push the image from your unpacked bundle. It’s pushed as <registry/repo>:<version>, and nothing is installed on your machine.

Push Tenon's image
docker login registry.example.comcd tenon-1.6.1-acme-macos-arm64./install.sh --push-image registry.example.com/tenon

The image is the same whichever platform’s bundle you push it from.

2. Add the variables

The pipeline reads its image, license server and trust root from your CI settings, so none of them is committed. Set them for the project, or once for a GitLab group or a GitHub organization to cover every project in it.

In GitLab, open Settings > CI/CD > Variables, and add three variables:

TENON_IMAGE
The image you pushed, such as registry.example.com/tenon:<version>.
FLEX_LICENSE_SERVER
Your license server’s address, as your runners reach it: https://licensing.example.com.
FLEX_LICENSE_ROOT_PUBKEY
Your trust root. Make it a File variable, and paste in the contents of the bundle’s root-pub.pem.

In GitHub, open Settings > Secrets and variables > Actions. Add four variables and one secret. The trust root is a public key, so only the registry token needs to be a secret:

TENON_IMAGE
The image you pushed, such as registry.example.com/tenon:<version>.
TENON_IMAGE_PULL_USERNAME
The username your jobs log in to the registry with.
FLEX_LICENSE_SERVER
Your license server’s address, as your runners reach it: https://licensing.example.com.
FLEX_LICENSE_ROOT_PUBKEY
Your trust root. Paste in the contents of the bundle’s root-pub.pem; each job writes it to a file before it sets up licensing.
TENON_IMAGE_PULL_TOKEN (a secret)
A read-only token for that username.

GitHub needs both TENON_IMAGE_PULL_USERNAME and TENON_IMAGE_PULL_TOKEN. If either is empty, it rejects the whole workflow with “Unexpected value ’’” before any job starts.

The license server records each job’s seat as held by tenon-ci. In GitLab, to record something more useful, such as the project’s path, add a fourth variable, TENON_CLI_SEAT_HOLDER, with the value $CI_PROJECT_PATH.

3. Generate the pipeline

From your project folder, run tenon workflow ci for your workflow. The first time, Tenon asks which platform hosts your code, and saves the answer as [ci] platform in tenon.toml. It defaults to GitLab, or to GitHub Enterprise Cloud when your repository has a .github/workflows/ folder and no .gitlab-ci.yml. It then asks how CI builds your component: the image to build it in, the build command, which runs from the repository root, and the binaries the test jobs need, as paths from the project folder. It saves those answers in [ci.build], so it doesn’t ask again.

Generate the pipeline
cd flextenon workflow ci System

For GitLab, Tenon writes .gitlab-ci.yml at the root of your repository. If your repository already has a .gitlab-ci.yml that Tenon didn’t write, Tenon asks whether to replace it or to add its jobs to your pipeline instead. For GitHub, Tenon writes .github/workflows/tenon.yml, which runs beside any workflows you already have. It runs for pull requests, for pushes to your default branch, and by hand from the Actions tab, and a newer commit on a pull request cancels the run for the older one.

When it’s done, Tenon prints the file it wrote, its jobs, and the variables the pipeline reads. Commit the pipeline file and flex/tenon.toml, and push.

4. Read the results

Each run has four kinds of job. build-component runs your build command, and design draws the diagrams and runs the model check. design fails when a protocol is Ill-formed, and with require_proven on, when one isn’t Proven. With it off, a protocol that’s Indeterminate or Unsupported is a warning: an allowed failure in GitLab, and a warning annotation in GitHub. Each verify-<Component> job tests one component and fails when it isn’t conformant.

Last, reports traces your requirements and builds the dashboard. It runs even when an earlier job failed, so a red pipeline still shows you what broke.

Every job keeps its results under flex/reports/, with the dashboard at index.html. In GitLab, they’re job artifacts: in a merge request, the Tenon reports link opens them, and component tests also appear in the pipeline’s Tests tab. In GitHub, download the tenon-reports artifact from the run’s summary page. It holds every job’s results. Each job’s own results are there too, as reports-<job>.

When a job fails, its log shows the command that failed. Run the same command on your machine, from the project folder, to see the problem and fix it: tenon workflow show prints every command the pipeline runs.

Run the failing step locally
tenon workflow show Systemtenon verify component components/Radar --flex ../../spec

5. Keep the pipeline up to date

When you change the workflow, run tenon workflow ci again, and commit the new pipeline file. Change the workflow rather than editing the YAML, so that the pipeline and your local runs stay the same. To move to another platform, change [ci] platform in tenon.toml and run it again. Tenon leaves the old platform’s file in place, and tells you it can be deleted.

When you upgrade Tenon, push the new release’s image, and point TENON_IMAGE at the new version. tenon upgrade doesn’t run in CI: the image is how a pipeline gets a new Tenon.

Move the pipeline to a new release
./install.sh --push-image registry.example.com/tenon

Add Tenon to an existing GitLab pipeline

When your repository already has a .gitlab-ci.yml, Tenon can keep its jobs in a separate file, flex/tenon.gitlab-ci.yml, that your pipeline includes. That’s the default answer when Tenon asks. Tenon saves the choice as [ci] gitlab = "brownfield" in tenon.toml, and offers to add the include: to your .gitlab-ci.yml. If your file already has an include:, add the line to it yourself:

.gitlab-ci.yml
include:
  - local: 'flex/tenon.gitlab-ci.yml'

The jobs are named tenon:design, tenon:verify-Radar and so on, so they can’t clash with yours, and they run in GitLab’s standard build and test stages. If your pipeline lists its own stages:, add build and test to it; Tenon warns you when they’re missing. Tenon’s jobs pick up your default runner tags and your auto-cancel setting, and nothing else from your default: section, so your before_script, retry and timeout don’t change how they run. Your top-level variables: reach them, as they reach every included job.

To go back to a standalone .gitlab-ci.yml, set gitlab = "greenfield" under [ci], or delete the key to be asked again.

Run on GitHub Enterprise Server

With [ci] platform = "github-server", Tenon writes the same .github/workflows/tenon.yml, set up for self-hosted runners. Its jobs run on runners labeled self-hosted, linux and x64. If your runners use other labels, change the runs-on: lines; the comment above them in the file says so. The jobs use only the versions of GitHub’s actions that GitHub Enterprise Server supports, and they read the same variables and secret as on GitHub Enterprise Cloud.

GitHub Enterprise Server can’t give a job service its own command. So when one of your test brokers has a command in its env.toml, that component’s test job runs on the runner itself: it logs in to your registry, then starts the broker and Tenon’s image with docker run, and removes them when the job is done. Brokers without a command run as ordinary job services.

Test one component without a workflow

To run a single component test in GitLab without a workflow, start from your bundle’s ci/gitlab-ci.yml. It’s one job that runs tenon verify component, with your license server already filled in, so it needs only TENON_IMAGE and FLEX_LICENSE_ROOT_PUBKEY. Point it at the folder holding your component’s verifier.yaml, and build your component first. Alternatively, run tenon verify component setup in the component’s folder: its last step writes a GitLab or GitHub pipeline for that component, test brokers included.

Next steps