The CUE Central Registry provides a well-known location for well-known schemas, including those for YAML workflow files used by GitHub Actions. This guide shows you how to get started defining your GitHub Actions workflows in CUE using a curated module from the schema library.

The latest pre-release of the cue command is required – please upgrade to this version if it’s not already installed:

TERMINAL
$ cue version
cue version v0.13.0-alpha.3
...

Login to the Central Registry

TERMINAL
$ cue login # only during beta

The Central Registry requires authentication while it’s in beta testing, so you need to login before you can use its schemas.

Initialise your local CUE module

CUE that uses schemas and modules from the Central Registry needs to exist within its own CUE module.

TERMINAL
$ cue mod init cue.example

You can choose any module name you like - it’s easy to change it later. It makes sense for your CUE module to exist at the root of a git repository that’s hosted on GitHub, but the commands in this guide will work in any setup.

Create a workflow

Declare a GitHub Actions workflow in CUE. This one is based on an example from GitHub’s documentation:

workflow.cue
// filepath: workflow.cue

package cicd

import "test.cue.works/x1/githubactions"

workflows: example: githubactions.#Workflow & {
	name:       "learn-github-actions"
	"run-name": "${{ github.actor }} is learning GitHub Actions"
	on: ["push"]
	jobs: "check-bats-version": {
		"runs-on": "ubuntu-latest"
		steps: [
			{uses: "actions/checkout@v4"},
			{uses: "actions/setup-node@v4", with: "node-version": "20"},
			{run: "npm install -g bats"},
			{run: "bats -v"},
		]
	}
}

In later guides we’ll add more entries to the workflows struct.

The import at the top references the appropriate curated module for the workflow. Its path is currently temporary, but only while its proper location is being decided. The temporary path isn’t a problem because one important property of the Central Registry is that, once a schema is published, it will always be available at that location. When the curated module’s location is finalised and versions are published under the new path, you can use the cue refactor imports command to update your CUE easily, so it reflects the new location.

Tidy your local CUE module

TERMINAL
$ cue mod tidy

Tidying a module is an important part of using curated modules from the Central Registry. Always use cue mod tidy when you use a curated module for the first time.

Validate your workflow

TERMINAL
$ cue vet -c

Because cue vet doesn’t display any errors, you know that the curated schema has validated your workflow.

Export your workflow as YAML

Before exporting your workflow you’ll need to create a directory to hold it, as expected by GitHub Actions:

TERMINAL
$ mkdir -p .github/workflows/
$ cue export --outfile .github/workflows/workflow.yml -e workflows.example

If you chose to export the workflows.example shown above, your validated YAML workflow will look like this:

.github/workflows/workflow.yml
# filepath: .github/workflows/workflow.yml

name: learn-github-actions
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "20"
      - run: npm install -g bats
      - run: bats -v
"on":
  - push
run-name: ${{ github.actor }} is learning GitHub Actions

Run your workflow

The cue.mod and .github directories need to be stored in your git repository, along with your workflow.cue file. After recording them in a commit you can push your branch to GitHub and trigger the workflow.

Whenever you update your CUE workflow, re-run the cue export command shown above, and then use git to record any changes to these files and directories.