Continuous integration and continuous deployment in SourceCraft

Continuous Integration/Continuous Deployment is a set of practices and tools you can use to automatically change, test, and deploy code. The approach allows you to continuously improve software quality and speed up development.

Continuous integration (CI)

CI is there for frequent and regular integration of code changes into the main branch of the repository. Each commit goes through automatic checks, e.g., unit tests and static code analysis. Thus you can make sure your commit is correct and the code is stable. This reduces the risks of integration issues, and the developers get the feedback faster.

Continuous deployment (CD)

The CD approach is built around automated code deployment on product servers after a code quality test. Be confident that your apps are always deployed and have the latest updates and fixes.

CI/CD configuration

SourceCraft has a built-in mechanism for the CI/CD processes.

The CI/CD configuration is set up for a particular repository and stored in the root of the repository in a file named .src.ci.yaml.

General format of the .src.ci.yaml configuration file:

on:
  pull_request:
    - workflows: [<list_of_workflows>]
      filter:
        source_branches: [<list_of_source_branches>]
        target_branches: [<list_of_target_branches>]
        paths: [<list_of_paths>]

  push:
    - workflows: [<list_of_workflows>]
      filter:
        branches: [<list_of_branches>]
        paths: [<list_of_paths>]

workflows:
  <workflow_name>:

    tasks:
      - name: <job_name>
        
        cubes:
          - name: <cube_name>
            image: <Docker_image_path>
            script:
              - <executed_script>
...

The configuration file supports secrets. For details, see Using the value of a secret in CI/CD.

See the templates repository in SourceCraft for the full specification of the .src.ci.yaml file.

Trigger events (on)

Under on, you can configure the repository events that will start the CI/CD workflows.

Such events may include pushing changes to a remote repository branch or creating a pull request.

You can configure different workflows for different events. You can also configure triggers for specific branches or paths in the repository.

For more information, see the CI/CD reference Trigger events (on).

Workflows

The workflows section lists CI/CD workflows.

A workflow helps to organize tasks related to a certain CI/CD stage into a logical sequence. For example, you can run one workflow to build, test, or otherwise check your code, and another one, for release.

For more information, see the CI/CD reference Workflows.

Tasks

The tasks section defines a list of tasks that are part of the workflow.

Each task contains a series of minimal logical actions, the cubes. The result of a task is when all its cubes are completed.

In tasks, you can use environment variables as well as secrets.

Cubes

The cubes section lists the minimal logical actions, cubes, to execute in the task.

In cubes, you can use environment variables as well as secrets.

For more information about tasks and cubes, see the CI/CD reference Tasks.

Environment variables in CI/CD

The SourceCraft CI/CD processes support environment variables. You can set the variables under the following items in the .src.ci.yaml configuration file:

  • Task: To provide the variables to all cubes linked to the task.
  • Cube: To provide the variables to the specified cube.

Also, you can use predefined environment variables.

Warning

Do not store any confidential data, such as passwords, access keys, or tokens, in environment variables; instead, use secrets.

Example of a configuration with environment variables

tasks:
  - name: my-task
    # Defines the variables to go to all the cubes associated with the task.
    env:
      TASK_VAR: test-var-'test'-\"test\"
      MULTILINE_VAR: |
        multi-var
        multi-var
        this is my multi-var

    cubes:
      - name: my-cube
        # Defines the variables to go only to a specific cube.
        env:
          CUBE_VAR: "you can see me here only"
          SECRET_VAR: ${{ secrets.<secret_name> }}
        script:
          - echo "$TASK_VAR"
          - echo "$MULTILINE_VAR"
          - echo "$CUBE_VAR"
          - echo "$SECRET_VAR"

For more information about using environment variables, see Processing environment variables in SourceCraft.

Predefined environment variables

SourceCraft automatically sets values for some environment variables. You can use them in your CI/CD processes.

Variable

Description

CI

Indicates the task is running in a CI environment, which is always true.

SOURCECRAFT_CI

Indicates the task is running in the SourceCraft CI/CD, which is always true.

SOURCECRAFT_ROOT_DIRECTORY

Path to the directory housing files associated with the task in progress

SOURCECRAFT_WORKSPACE

Path to the directory to clone the repository to. This directory is also the default directory (workdir) for cubes with a container

SOURCECRAFT_TASK_DATA

Path to the directory housing auxiliary files of the task in progress

SOURCECRAFT_COMMIT_REF

Full name of a branch or tag the workflow started in

SOURCECRAFT_COMMIT_SHA

SHA hash of the commit after which the workflow started

SOURCECRAFT_COMMIT_SHORT_SHA

First 8 characters of SOURCECRAFT_COMMIT_SHA

SOURCECRAFT_BASE_SHA

SHA hash of the commit for which the list of changes is calculated. The values it takes depend on the event which started the workflow:

  • SHA hash of the previous branch commit if pushing changes to a remote repository branch (on.push).
  • SHA hash of the last target branch commit (merge-base) if creating a pull request (on.pull_request).
  • Empty value if starting the CI/CD process manually (manual).

SOURCECRAFT_BASE_REF

Full name of the target branch in a pull request. It is filled in only when starting and restarting checks in the pull request.

SOURCECRAFT_EVENT

Type of the trigger event which started the workflow:

  • push: Pushing changes to a remote repository branch.
  • pull_request: Creating a pull request.
  • restart: Restarting the CI/CD process.
  • manual: Starting the CI/CD process manually.

SOURCECRAFT_CHECKOUT_ENABLED

Indicates whether or not to clone the repository automatically. It equals the checkout:enabled value. The default value is true.

SOURCECRAFT_WORKFLOW

Name of the workflow in progress.

SOURCECRAFT_TASK

Name of the task in progress.

SOURCECRAFT_CUBE

Name of the cube in progress.

SOURCECRAFT_CUBE_IMAGE

Docker image used by the cube. It is only defined for cubes which use a container.

SOURCECRAFT_CUBE_ARTIFACTS

List of paths to cube artifacts relative to SOURCECRAFT_WORKSPACE, separated with ;. It is only defined for cubes with the specified artifacts.

SOURCECRAFT_COMMIT_AUTHOR

Commit author, in Name email format.

SOURCECRAFT_COMMITTER

Committer who added the commit to the target branch, in Name email format.

SOURCECRAFT_COMMIT_TIMESTAMP

Commit timestamp in ISO 8601 format, e.g., 2025-03-03T23:41:19Z. The UTC zone is used by default.

SOURCECRAFT_COMMIT_MESSAGE

Commit message

SOURCECRAFT_COMMIT_TITLE

Commit title, i.e., the first line of the message

SOURCECRAFT_COMMIT_DESCRIPTION

Commit description. If the title is less than 100 characters, the message is displayed without a title; otherwise, the entire message is displayed.

See also