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 |
|
Indicates the task is running in a CI environment, which is always |
|
Indicates the task is running in the SourceCraft CI/CD, which is always |
|
Path to the directory housing files associated with the task in progress |
|
Path to the directory to clone the repository to. This directory is also the default directory ( |
|
Path to the directory housing auxiliary files of the task in progress |
|
Full name of a branch or tag the workflow started in |
|
SHA hash of the commit after which the workflow started |
|
First 8 characters of |
|
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:
|
|
Full name of the target branch in a pull request. It is filled in only when starting and restarting checks in the pull request. |
|
Type of the trigger event which started the workflow:
|
|
Indicates whether or not to clone the repository automatically. It equals the |
|
Name of the workflow in progress. |
|
Name of the task in progress. |
|
Name of the cube in progress. |
|
Docker image used by the cube. It is only defined for cubes which use a container. |
|
List of paths to cube artifacts relative to |
|
Commit author, in |
|
Committer who added the commit to the target branch, in |
|
Commit timestamp in ISO 8601 format, e.g., |
|
Commit message |
|
Commit title, i.e., the first line of the message |
|
Commit description. If the title is less than 100 characters, the message is displayed without a title; otherwise, the entire message is displayed. |