Skip to main content

Manage data models in CI/CD

Beta

The features described in this section are currently in beta testing and are subject to change. We recommend that you don't use the features in production systems.

This article describes how to use the CDF CLI to manage a data model in a CI/CD pipeline with GitHub actions.

Prerequisites

Before you start, make sure you have completed these steps:

  1. Install the CDF CLI on your machine.
  2. Create your data model.

Step 1: Create a GitHub Action

  1. Create a Github Action to run every time you merge to the main branch.

    .github/workflows/publish-dm-on-main.yml
    name: Publish datamodel on merge to main
    on:
    push:
    branches:
    - main
    jobs:
    publish-dm:
    runs-on: ubuntu-latest
    steps:
    # We will add the next steps here

Step 2: Install the CDF CLI

  1. Add commands to install the CDF CLI in the GitHub Action.

    - name: Install Dependency & Build
    run: |
    npm install --global @cognite/cdf-cli

Step 3: Sign in with the CDF CLI

  1. In GitHub, set up the secrets.

  2. Add commands to sign in to CDF with the CDF CLI.

    - name: Signin
    run: |
    cdf signin ${{ secrets.CLI_PROJECT }} --tenant=${{ secrets.CLI_TENANT }} --cluster=${{ secrets.CLI_CLUSTER }} --client_id=${{ secrets.CLI_CLIENT_ID }} --client_secret=${{ secrets.CLI_CLIENT_SECRET }}

    Where:

    • CLI_PROJECT - The CDF project (for example, demo).
    • CLI_TENANT - The Azure Active Directory tenant (for example, cognitecli.onmicrosoft.com).
    • CLI_CLUSTER - The CDF cluster (default: api).
    • CLI_CLIENT_ID - A client ID for an application registered in your Azure AD tenant.
    • CLI_CLIENT_SECRET - A secret for an application registered in your Azure AD tenant.
note

We currently support using Azure AD to sign in to the CDF CLI.

Step 4: Publish the data model

  1. Add commands to publish the data model.

    In the example below the data model lives in datamodel.graphql within the root of the repo and you publish changes to a data model called moviedm.

    - name: Publish changes
    run: |
    cdf data-models publish --file=./datamodel.graphql --external-id=moviedm --allow-breaking-change

    The --allow-breaking-change parameter enables breaking changes, indicating that a new version of the data model will be published.

Sample GitHub Action file

.github/workflows/publish-dm-on-main.yml
name: Publish DM on merge to main
on:
push:
branches:
- main
jobs:
publish-dm:
runs-on: ubuntu-latest
steps:
- name: Install dependency & build
run: |
npm install --global @cognite/cdf-cli
- name: Signin
run: |
cdf signin ${{ secrets.CLI_PROJECT }} --tenant=${{ secrets.CLI_TENANT }} --cluster=${{ secrets.CLI_CLUSTER }} --client_id=${{ secrets.CLI_CLIENT_ID }} --client_secret=${{ secrets.CLI_CLIENT_SECRET }}
- name: Publish changes
run: |
cdf data-models publish --file=./datamodel.graphql --external-id=moviedm --allow-breaking-change