From 1166b71985713fae971206a6b53fbb9c31e05a0d Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Tue, 19 Mar 2024 20:21:25 +0100 Subject: [PATCH] wip --- actions/ftrack-sync/package.json | 1 + actions/ftrack-sync/pre_deploy.ts | 56 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 actions/ftrack-sync/pre_deploy.ts diff --git a/actions/ftrack-sync/package.json b/actions/ftrack-sync/package.json index 89677ab..757f67b 100644 --- a/actions/ftrack-sync/package.json +++ b/actions/ftrack-sync/package.json @@ -11,6 +11,7 @@ "check-pr": "bun run sync-pr-status && bun run check-tasks", "release-notes": "bun sync_release.ts", "sync-deployment-approval": "bun sync_deployment_approval.ts", + "pre-deploy": "bun pre_deploy.ts", "test": "yarn lint && vitest --run", "lint": "eslint . && prettier -c ." }, diff --git a/actions/ftrack-sync/pre_deploy.ts b/actions/ftrack-sync/pre_deploy.ts new file mode 100644 index 0000000..7f2b50f --- /dev/null +++ b/actions/ftrack-sync/pre_deploy.ts @@ -0,0 +1,56 @@ +import { ensureReleaseTagExists, getSession } from "./ftrack.js"; +import { checkEnvironment } from "./utils.js"; +import type GithubPayload from "./fixtures/github_payload_on_push_tag.json"; + +export type Release = { + status_id: string; +}; + +export const APPROVAL_STATUS = { + RELEASED: "ba008734-2d87-11ec-a4f5-ca3b22452d4a", + APPROVED: "44de097a-4164-11df-9218-0019bb4983d8", + PENDING_APPROVAL: "44dded64-4164-11df-9218-0019bb4983d8", + IN_ROLLOUT: "3961f582-99f1-11ec-8f87-224ef9a30185", + REJECTED: "5c74bae6-5659-11e1-b145-f23c91df25eb", +} as const; + +type Context = { + status: keyof typeof APPROVAL_STATUS; +}; + +export async function updateReleaseApprovalStatus( + githubPayload: typeof GithubPayload, + context: Context, +) { + const approvalStatus = APPROVAL_STATUS[context.status]; + if (!approvalStatus) { + throw new Error( + `Invalid status passed to context: ${context.status}, should be one of: ${Object.keys(APPROVAL_STATUS).join(", ")}`, + ); + } + + const tagName = githubPayload.ref_name; + const repo = githubPayload.event.repository.name; + const releaseTag = await ensureReleaseTagExists(repo, tagName); + const response = await getSession().update( + "Release", + [releaseTag.id], + { + status_id: APPROVAL_STATUS[context.status], + }, + ); + return response; +} + +async function main() { + console.log("Github payload:\n", process.env.GITHUB_PAYLOAD); + const githubPayload = JSON.parse(process.env.GITHUB_PAYLOAD!); + const context = JSON.parse(process.env.CONTEXT!) as Context; + + return updateReleaseApprovalStatus(githubPayload, context); +} + +if (import.meta.url === `file://${process.argv[1]}`) { + checkEnvironment(); + main(); +}