Skip to content
refs
History
4.9 KBRaw

Run CI

refs CI runs the jobs of a pipeline in containers on Cloudflare. A pipeline runs on a push, on a pull request, or when you start it. This document shows you how to add a pipeline, keep secrets, and protect deploys.

For each key of the pipeline file, see CI configuration.

Before you begin

  • Have write access to the repository.

Add a pipeline

  1. In the repository, create the file .refs/ci.yml:

    on:
      push:
        branches: [main]
      pull_request:
      manual:
    
    jobs:
      test:
        image: node
        timeout_minutes: 20
        steps:
          - name: Install
            run: npm ci
          - name: Test
            run: npm test
    
  2. Commit and push the file.

The push to main starts a run. Open the Runs tab of the repository to see it. A dot next to the last commit shows the result of its run.

How a run works

  1. refs reads .refs/ci.yml at the commit. If the file is not valid, the run fails and lists each problem with the path of the key.
  2. refs starts each job whose needs jobs succeeded. Jobs without needs start at once.
  3. Each job checks out the commit in a new container, then runs its steps in order with bash.
  4. A failed step stops the job. A job that fails, is skipped, is cancelled or times out makes each job that needs it skip.

Each job gets these environment variables: CI=true, REFS_SHA, REFS_REF, REFS_JOB and REFS_RUN_ID.

refs runs at most 2 job containers at the same time across the server. Other jobs wait in the queue.

Start a run by hand

If the pipeline has the manual trigger:

  1. Open the Runs tab.
  2. In Branch, select a branch.
  3. Click Start run.

To stop a run, open it and click Cancel run. To run a finished run again, open it and use the button next to the run title.

Trusted and untrusted runs

refs decides if a run is trusted from who started it, not from the branch. An agent can change .refs/ci.yml, so a run that an agent starts is untrusted.

Run started by Trust Secrets
A person, push to a protected branch Trusted Organization, repository and environment secrets
A person, push to a different branch Trusted Organization and repository secrets
A person, pull request from the same repository Trusted Organization and repository secrets
A person, manual start Trusted Same as a push to that branch
An agent push, an agent pull request or an agent start Untrusted None
A pull request from a fork Untrusted None

An untrusted run shows This run is untrusted with the reason. Its jobs get no secrets, and each job with an environment waits for a person.

Add secrets

A job gets only the secrets that it names in its secrets key, as environment variables. refs stores each value sealed. Nobody can read a value back, and refs masks it in the logs.

To add a repository secret:

  1. Open the repository and click Settings.
  2. In Name, enter a name in capital letters, digits and _, for example NPM_TOKEN.
  3. Optional: In Scope, select an environment.
  4. In Value, paste the value.
  5. Click Save secret.

To share a secret with all repositories of a namespace, go to CI secrets in the sidebar. A repository secret with the same name wins over an organization secret. An environment secret wins over both.

Protect deploys with environments

An environment holds the rules for a deploy, for example production. A job joins an environment with the environment key.

  1. Open the repository and click Settings.
  2. Click Environments.
  3. In the environment form, enter a name in Name.
  4. Optional: In Branches that may deploy, enter branch patterns, for example main, release/**. Leave it empty to allow each branch.
  5. Optional: In Wait before a deploy (minutes), enter a delay.
  6. Keep A person approves each deploy selected to make each deploy wait for a person.
  7. Click Create environment.

When a job with an environment is ready, refs checks these rules in order:

  1. If the environment does not exist, the job does not run.
  2. If the branch does not match the allowed patterns, the job does not run.
  3. If the run is untrusted, or the environment requires approval, the job waits. A person with write access clicks Approve or Reject on the run page.

Environment secrets go only to a job in a trusted run that a person approved, or to a job in a run from a push by a person to a protected branch.

Protect branches

A protected branch gives a push by a person access to environment secrets without an approval.

  1. Open Settings.
  2. In Branch patterns, one per line, enter patterns, for example main and release/**.
  3. Click Save protected branches.

In a pattern, * matches inside one path segment, and ** matches across segments.

What's next