Branches and CI
Move changes from feature branches to development, qa and main through pull requests, and validate every pull request against the public JSON Schemas before anything reaches an installation.
Git Sync gives you a deployment pipeline made of the tools you already use: branches decide what each installation can see, pull requests are the review, and CI checks catch broken files before a person previews them in Sommatic AI.
Branch flow
- Work on a
feature/*branch and open a pull request todevelopment. - Each installation reads one branch, set in its environment file and its connection: for example dev reads
developmentand prod readsmain. - Promote a change with a pull request from
developmenttoqa, and fromqatomain. - Deploy to an installation only after the pull request into its branch is merged, by previewing and applying the new head.
- Protect
development,qaandmain: no direct pushes, required reviews and required checks.
What to check on every pull request
| Check | Why |
|---|---|
Every sommatic.json validates against the package schema. | The manifest is what Sommatic AI reads first. |
| Every file listed in a manifest exists and validates against the resource header schema. | It also rejects runtime fields such as id or status. |
The header key of each file equals its manifest key. | Preview reports a mismatch as an error. |
| Keys are unique across the repository. | One key maps to one resource per installation. |
| Every environment file validates and declares an id for every key. | Apply fails for resources that are not declared. |
No @@secret.REPLACE_ME@@ remains. | Export leaves it when it could not name a secret. |
The schemas are public:
https://docs.sommatic.ai/schemas/git-sync/package.schema.jsonhttps://docs.sommatic.ai/schemas/git-sync/environment.schema.jsonhttps://docs.sommatic.ai/schemas/git-sync/resource-header.schema.json
They use JSON Schema draft 2020-12, so any validator that supports it works.
A generic validator
This script runs every check above with Node.js and Ajv 8. Save it in your repository, for
example as tools/validate-sommatic.mjs:
// Usage: node tools/validate-sommatic.mjs <repo-root> <schemas-dir>
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative, dirname } from 'node:path';
import Ajv2020 from 'ajv/dist/2020.js';
const root = process.argv[2] || '.';
const schemaDir = process.argv[3] || 'schemas';
const ajv = new Ajv2020({ allErrors: true, strict: false });
const load = (path) => JSON.parse(readFileSync(path, 'utf8'));
const validate = {
package: ajv.compile(load(join(schemaDir, 'package.schema.json'))),
environment: ajv.compile(load(join(schemaDir, 'environment.schema.json'))),
resource: ajv.compile(load(join(schemaDir, 'resource-header.schema.json'))),
};
const errors = [];
const check = (kind, file, data) => {
if (!validate[kind](data)) {
validate[kind].errors.forEach((error) => errors.push(`${file}: ${error.instancePath || '/'} ${error.message}`));
}
};
const walk = (folder) =>
readdirSync(folder).flatMap((name) => {
const path = join(folder, name);
if (['.git', 'node_modules'].includes(name)) return [];
return statSync(path).isDirectory() ? walk(path) : [path];
});
const files = walk(root).map((path) => relative(root, path));
const ignored = (path) => path.split('/').some((segment) => ['templates', '.github'].includes(segment));
const manifests = files.filter((path) => path.endsWith('sommatic.json') && !ignored(path));
const environments = files.filter((path) => /^environments\/[^/]+\.json$/.test(path));
const keys = new Set();
for (const manifestPath of manifests) {
const manifest = load(join(root, manifestPath));
check('package', manifestPath, manifest);
const packageDir = dirname(manifestPath);
for (const entry of [...(manifest.resources?.workflows || []), ...(manifest.resources?.knowledge || [])]) {
if (keys.has(entry.key)) errors.push(`${manifestPath}: duplicated key ${entry.key}`);
keys.add(entry.key);
const filePath = join(packageDir, entry.path);
if (!files.includes(filePath)) {
errors.push(`${manifestPath}: ${entry.key} points to a missing file ${filePath}`);
continue;
}
const text = readFileSync(join(root, filePath), 'utf8');
const resource = JSON.parse(text);
check('resource', filePath, resource);
if (resource.sommatic?.key !== entry.key) errors.push(`${filePath}: header key is not ${entry.key}`);
if (text.includes('@@secret.REPLACE_ME@@')) errors.push(`${filePath}: name the secret that replaced @@secret.REPLACE_ME@@`);
}
}
for (const environmentPath of environments) {
const environment = load(join(root, environmentPath));
check('environment', environmentPath, environment);
for (const key of keys) {
if (!environment.resources?.[key]) errors.push(`${environmentPath}: resources has no id for ${key}`);
}
}
if (errors.length) {
console.error(errors.join('\n'));
process.exit(1);
}
console.log(`OK: ${manifests.length} package(s), ${keys.size} resource(s), ${environments.length} environment(s)`);The script assumes packages and environments/ sit at the repository root. If your connection uses a root path, pass
that folder as <repo-root>.
Run it on pull requests
A GitHub Actions workflow that downloads the schemas and runs the validator on every pull request to a deployment branch:
name: Validate Sommatic packages
on:
pull_request:
branches: [development, qa, main]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install --no-save ajv@8
- name: Download the Git Sync schemas
run: |
mkdir -p .sommatic-schemas
for name in package environment resource-header; do
curl -fsSL "https://docs.sommatic.ai/schemas/git-sync/$name.schema.json" -o ".sommatic-schemas/$name.schema.json"
done
- run: node tools/validate-sommatic.mjs . .sommatic-schemasOptional: preview the pull request
Static checks cannot know whether each resource exists in the installation or what a change does to the live workflow. A preview can, and it writes nothing. A CI job with a token for the dev installation
can call preview with ref set to the pull request’s head commit and fail when any item has unresolved tokens or
exists: false:
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/preview" \
-H "Authorization: Bearer $SOMMATIC_TOKEN" \
-H 'Content-Type: application/json' \
-d '{ "repository_id": "<repository_id>", "path": "support", "ref": "<pull request head commit>", "include_content": false }'Store the token as a CI secret, never in the repository.