import assert from "node:assert/strict"; import fs from "node:fs"; import test from "node:test"; const stageWorkflow = fs.readFileSync( new URL("../.gitea/workflows/deploy.yml", import.meta.url), "utf8" ); const promoteWorkflow = fs.readFileSync( new URL("../.gitea/workflows/promote.yml", import.meta.url), "utf8" ); const helper = fs.readFileSync( new URL("./coolify-deploy.mjs", import.meta.url), "utf8" ); test("main builds once and deploys the exact digest to staging", () => { assert.match(stageWorkflow, /name: Deploy staging/); assert.match(stageWorkflow, /IMAGE_DIGEST=.*Manifest\.Digest/); assert.equal( (stageWorkflow.match(/coolify-deploy\.mjs set-release/g) || []).length, 1 ); assert.equal( (stageWorkflow.match(/coolify-deploy\.mjs assert-release/g) || []).length, 1 ); assert.match( stageWorkflow, /imagetools create --prefer-index=false --tag "\$IMAGE:staging"/ ); assert.doesNotMatch(stageWorkflow, /Promote staging image to production/); }); test("production promotion is input-free and resolves the live staging release", () => { assert.match(promoteWorkflow, /name: Promote to production/); assert.match(promoteWorkflow, /workflow_dispatch:\s*\n/); assert.doesNotMatch(promoteWorkflow, /inputs:/); assert.match(promoteWorkflow, /\/healthz\?__promotecheck=/); assert.match(promoteWorkflow, /git rev-list origin\/main/); assert.match(promoteWorkflow, /"\$IMAGE:\$STAGED_SHA"/); assert.match(promoteWorkflow, /"\$IMAGE:staging"/); assert.match(promoteWorkflow, /"\$IMAGE_DIGEST" != "\$STAGING_DIGEST"/); assert.match(promoteWorkflow, /coolify-deploy\.mjs current-release/); assert.match(promoteWorkflow, /PREVIOUS_PRODUCTION_DIGEST/); }); test("promotion deploys the staged digest and purges Cloudflare", () => { assert.equal( (promoteWorkflow.match(/coolify-deploy\.mjs set-release/g) || []).length, 1 ); assert.equal( (promoteWorkflow.match(/coolify-deploy\.mjs assert-release/g) || []).length, 2 ); assert.match( promoteWorkflow, /imagetools create --prefer-index=false --tag "\$IMAGE:main"/ ); assert.match(promoteWorkflow, /\/purge_cache/); assert.match(promoteWorkflow, /payload\.success !== true/); }); test("Coolify deploys use force deploy and immutable digest pins", () => { assert.match( helper, /\/deploy\?uuid=\$\{encodeURIComponent\(resourceUuid\)\}&force=true/ ); assert.doesNotMatch( helper, /\/applications\/\$\{encodeURIComponent\(resourceUuid\)\}\/start/ ); assert.match(helper, /AbortSignal\.timeout\(apiTimeoutMs\)/); assert.match(helper, /const OCI_DIGEST_PATTERN = \/\^sha256:/); assert.match(helper, /docker_registry_image_tag: expectedTag/); assert.match(helper, /async function currentRelease/); assert.match(helper, /not pinned to an immutable rollback digest/); });