56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { expect, it } from "vitest";
|
|
|
|
const workflow = readFileSync(".gitea/workflows/ci.yaml", "utf8");
|
|
const deploy = readFileSync("scripts/ci-deploy.sh", "utf8");
|
|
it("uses two test workers and runs smoke checks in the deployment transaction", () => {
|
|
expect(workflow).toContain("pnpm test:coverage --maxWorkers=4");
|
|
expect(workflow).not.toContain("\n e2e:");
|
|
expect(workflow).toContain("bash scripts/ci-deploy.sh");
|
|
expect(deploy).toContain(
|
|
"node scripts/verify-deployed-release.mjs http://127.0.0.1:3002/api/health",
|
|
);
|
|
});
|
|
it("locks CI and scheduled deployments using the same production lock", () => {
|
|
expect(deploy).toContain('exec 9>"$deploy_dir/.deploy.lock"');
|
|
expect(deploy).toContain("flock -w 1800 9");
|
|
const scheduled = readFileSync("scripts/docker-update.sh", "utf8");
|
|
expect(scheduled).toContain('exec 9>"$DIR/.deploy.lock"');
|
|
expect(scheduled.indexOf("flock -w 1800 9")).toBeLessThan(
|
|
scheduled.indexOf("git pull --ff-only"),
|
|
);
|
|
});
|
|
it("preserves production runtime configuration and recent cache", () => {
|
|
expect(deploy).toContain("--net=host");
|
|
expect(deploy).toContain("--restart always");
|
|
expect(deploy).toContain("/var/www/Gamedata:/var/www/Gamedata");
|
|
expect(deploy).toContain("/app/storage");
|
|
expect(deploy).not.toContain("--env-file");
|
|
expect(deploy).toContain(
|
|
'docker builder prune -af --filter "until=72h" --max-used-space=4g',
|
|
);
|
|
expect(deploy).not.toContain("docker volume prune");
|
|
});
|
|
it("builds the checked out source without fetching a moving remote branch", () => {
|
|
const dockerfile = readFileSync("Dockerfile", "utf8");
|
|
expect(dockerfile).toContain("COPY . .");
|
|
expect(dockerfile).not.toMatch(
|
|
/^ADD\s+https?:\/\/.*(?:repository|branches)/m,
|
|
);
|
|
expect(dockerfile).not.toMatch(/^RUN\s+git\s+(?:pull|fetch|clone)\b/m);
|
|
});
|
|
|
|
it("publishes commit images after successful main deployment and preserves manual retries", () => {
|
|
const publish = workflow.slice(workflow.indexOf("\n publish-container:"));
|
|
expect(publish).toContain("needs: deploy");
|
|
expect(publish).toContain("gitea.event_name == 'push'");
|
|
expect(publish).toContain("gitea.ref_name == 'main'");
|
|
expect(publish).toContain("gitea.ref_name == 'master'");
|
|
expect(publish).toContain("bash scripts/publish-container.sh");
|
|
expect(publish).toContain("secrets.CONTAINER_REGISTRY_USER");
|
|
expect(publish).toContain("secrets.CONTAINER_REGISTRY_TOKEN");
|
|
const manual = readFileSync(".gitea/workflows/container.yaml", "utf8");
|
|
expect(manual).toContain("workflow_dispatch:");
|
|
expect(manual).not.toMatch(/^ {2}push:/m);
|
|
});
|