Скоро перестанет поддерживаться хранение конфигурации CI/CD, правил ревью кода и политик веток в едином файле .src.ci.yaml в корне репозитория. Используйте отдельные файлы .sourcecraft/ci.yaml, .sourcecraft/review.yaml и .sourcecraft/branches.yaml.
CI/CD-процессы запускаются событиями-триггерами. Такими событиями могут быть отправка изменений в ветку удаленного репозитория, или когда создается предложение изменений.
Для разных событий вы можете настроить разные рабочие процессы. Также срабатывание триггеров можно настроить для конкретных веток или путей в репозитории.
В зависимости от настроек, указанных в .sourcecraft/ci.yaml, выполните событие-триггер.
Проверьте выполнение CI/CD-процесса:
На странице репозитория в разделе Код перейдите в секцию Автоматизации.
Выберите запущенный рабочий процесс (workflow).
На открывшейся странице будут отображены все задания (tasks) рабочего процесса, шаги задания — кубики (cubes), а также статусы и результаты выполнения.
Примеры
Hello World
Docker
Python
Node.js
Java
# Это базовый рабочий процесс (workflow), который # поможет вам начать работу с SourceCraft CI/CD# Настройка события-триггера для запуска рабочего процессаon:# Запуск рабочего процесса по отправке изменений в ветку main# удаленного репозитория, или когда создается предложение изменений в ветку mainpull_request:-workflows: [sample-workflow]
filter:source_branches: ["**", "!test**"]
target_branches:"main"push:-workflows: [sample-workflow]
filter:branches: ["main"]
workflows:sample-workflow:tasks:-name:sample-taskcubes:# Запуск набора команд -name:sample-cube1image:docker.io/library/nodescript:-echoHello,world!-name:sample-cube2script:-echoAddothercubestobuild,-echotest,anddeployyourproject.
on:push:-workflows:build-workflowfilter:branches: ["main"]
workflows:build-workflow:tasks:-build-tasktasks:-name:build-taskenv:IMAGE_URI:dockerhub_account/hello-worldcubes:-name:docker-buildscript:-dockerbuild.--fileDockerfile--tag$IMAGE_URI:$(date+%s)# Опционально: отправка Docker-образа в реестр# Передайте в кубик данные для аутентификации в реестре,# например в Docker Hub или Yandex Container Registry# - name: push-dockerhub# env:# USER: username# PAT: personal_access_token# script:# - echo $PAT | docker login --username $USER --password-stdin# - docker push $IMAGE_URI
Чтобы протестировать CI\CD-процесс, отправьте в ветку main коммит с файлом Dockerfile:
Добавьте в файл .gitignore данные, специфичные для тестирования приложений на Python.
Пример .gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# PyPI configuration file
.pypirc
Чтобы протестировать CI\CD-процесс, отправьте в ветку main коммит с файлом main.py:
print('Hello SourceCraft')
print('Hello SourceCraft')
for i inrange(10):
print(i)
# input
hi = input()
print(hi)
# Этот рабочий процесс (workflow) соберет Java-проект с помощью Mavenon:push:-workflows:publish-package-workflowfilter:branches: ["main"]
workflows:publish-package-workflow:settings:max-cube-duration:10mretry:2tasks:-build-publish-tasktasks:-name:build-publish-taskcubes:-name:setup-jdk-mavenscript:-sudoaptinstallopenjdk-21-jdk-y-sudoaptinstallmaven-y-java--version-mvn--version-name:testscript:-echo'test'-name:packagescript:-mvnpackage# Опционально: выгрузка артефакта с именем# sourcecraft-sample-maven-1.0-SNAPSHOT.jar из целевой директории.# Артефакт можно скачать из кубика в разделе CI/CD#artifacts: # paths:# - target/sourcecraft-sample-maven-1.0-SNAPSHOT.jar
Добавьте в файл .gitignore данные, специфичные для тестирования приложений на Java.
Чтобы протестировать CI\CD-процесс, отправьте в ветку main коммит со следующими файлами:
pom.xml:
<?xml version="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.mycompany.app</groupId><artifactId>sourcecraft-sample-maven</artifactId><version>1.0-SNAPSHOT</version><name>bondarevsky-maven</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.release>17</maven.compiler.release></properties><dependencyManagement><dependencies><dependency><groupId>org.junit</groupId><artifactId>junit-bom</artifactId><version>5.11.0</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><scope>test</scope></dependency><!-- Optionally: parameterized tests support --><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-params</artifactId><scope>test</scope></dependency></dependencies><build><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --><plugin><artifactId>maven-clean-plugin</artifactId><version>3.4.0</version></plugin><!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.3.1</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.13.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>3.3.0</version></plugin><plugin><artifactId>maven-jar-plugin</artifactId><version>3.4.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>3.1.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>3.1.2</version></plugin><!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --><plugin><artifactId>maven-site-plugin</artifactId><version>3.12.1</version></plugin><plugin><artifactId>maven-project-info-reports-plugin</artifactId><version>3.6.1</version></plugin></plugins></pluginManagement></build></project>
src/test/java/com/mycompany/app/AppTest.java:
package com.mycompany.app;
importstatic org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* Unit test for simple App.
*/publicclassAppTest {
/**
* Rigorous Test :-)
*/@TestpublicvoidshouldAnswerWithTrue() {
assertTrue(true);
}
}