From 2d6f98e456d77c4e6042601fe9c472d1adcb1238 Mon Sep 17 00:00:00 2001
From: psiddharthdesign <107192927+psiddharthdesign@users.noreply.github.com>
Date: Mon, 29 Jul 2024 23:58:29 +0530
Subject: [PATCH] added workflow outpu
---
.../runs/[runId]/ProjectRunDetails.tsx | 38 ++++++++++++++++---
.../[projectSlug]/runs/[runId]/page.tsx | 21 +++++++---
src/data/user/runs.ts | 34 +++++++++++++++++
3 files changed, 82 insertions(+), 11 deletions(-)
diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx
index b0659000..5f632d06 100644
--- a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx
+++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx
@@ -23,12 +23,16 @@ function RenderContent({
activeStage,
run,
tfOutput,
- workflowRunUrl
+ workflowRunUrl,
+ applyTerraformOutput,
+ applyWorkflowRunUrl
}: {
activeStage: string;
run: Table<'digger_runs'>;
tfOutput: string | null;
workflowRunUrl: string | null;
+ applyTerraformOutput: string | null;
+ applyWorkflowRunUrl: string | null;
}) {
if (activeStage === 'plan') {
return (
@@ -58,7 +62,7 @@ function RenderContent({
run.status !== ToTitleCase('pending_plan') &&
run.status !== ToTitleCase('running_plan') && (
- {run.terraform_output || 'No plan output available'}
+ {tfOutput}
)}
@@ -76,9 +80,29 @@ function RenderContent({
}
return (
-
Apply logs
+
+
Apply logs
+
+ {applyWorkflowRunUrl && ['pending_apply', 'running_apply', 'succeeded', 'failed'].includes(ToSnakeCase(run.status)) && (
+
+
+
+
+
+
+
+
+ View workflow run
+
+
+
+ )}
+
- {tfOutput}
+ {applyTerraformOutput}
);
@@ -92,8 +116,10 @@ export const ProjectRunDetails: React.FC<{
isUserOrgAdmin: boolean
tfOutput: string | null
workflowRunUrl: string | null
+ applyTerraformOutput: string | null
+ applyWorkflowRunUrl: string | null
fullRepoName: string | null
-}> = ({ run, loggedInUser, isUserOrgAdmin, tfOutput, workflowRunUrl, fullRepoName }) => {
+}> = ({ run, loggedInUser, isUserOrgAdmin, tfOutput, workflowRunUrl, applyTerraformOutput, applyWorkflowRunUrl, fullRepoName }) => {
const router = useRouter();
const [activeStage, setActiveStage] = useState<'plan' | 'apply'>('plan');
@@ -265,7 +291,7 @@ export const ProjectRunDetails: React.FC<{
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
-
+
diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx
index 09c9e9c1..d8faf5b8 100644
--- a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx
+++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx
@@ -4,7 +4,7 @@ import { T } from "@/components/ui/Typography";
import { getLoggedInUserOrganizationRole } from "@/data/user/organizations";
import { getSlimProjectById } from "@/data/user/projects";
import { getRepoDetails } from "@/data/user/repos";
-import { getBatchIdFromPlanStageId, getRunById, getTFOutputAndWorkflowURLFromBatchId } from "@/data/user/runs";
+import { getBatchIdFromApplyStageId, getBatchIdFromPlanStageId, getOutputLogsAndWorkflowURLFromBatchId, getRunById, getTFOutputAndWorkflowURLFromBatchId } from "@/data/user/runs";
import { getUserProfile } from "@/data/user/user";
import { Table } from "@/types";
import { serverGetLoggedInUser } from "@/utils/server/serverGetLoggedInUser";
@@ -32,6 +32,8 @@ type ProjectRunDetailsProps = {
isUserOrgAdmin: boolean
tfOutput: string | null
workflowRunUrl: string | null
+ applyTerraformOutput: string | null
+ applyWorkflowRunUrl: string | null
fullRepoName: string | null
}
@@ -57,11 +59,13 @@ export default async function RunDetailPage({
const { repo_full_name } = await getRepoDetails(project.repo_id);
const userProfile = await getUserProfile(user.id);
- const [organizationRole, batchId] = await Promise.all([
+ const [organizationRole, planBatchId, applyBatchId] = await Promise.all([
getLoggedInUserOrganizationRole(project.organization_id),
- getBatchIdFromPlanStageId(run.plan_stage_id)
+ getBatchIdFromPlanStageId(run.plan_stage_id),
+ getBatchIdFromApplyStageId(run.apply_stage_id)
]);
- const { terraform_output, workflow_run_url } = await getTFOutputAndWorkflowURLFromBatchId(batchId);
+ const { terraform_output: planTerraformOutput, workflow_run_url: planWorkflowRunUrl } = await getTFOutputAndWorkflowURLFromBatchId(planBatchId);
+ const { terraform_output: applyLogs, workflow_run_url: applyWorkflowRunUrl } = await getOutputLogsAndWorkflowURLFromBatchId(applyBatchId);
const isOrganizationAdmin =
organizationRole === "admin" || organizationRole === "owner";
@@ -81,7 +85,14 @@ export default async function RunDetailPage({
}
>
-
+
}
diff --git a/src/data/user/runs.ts b/src/data/user/runs.ts
index 8aa26ce3..cc8f22bb 100644
--- a/src/data/user/runs.ts
+++ b/src/data/user/runs.ts
@@ -211,6 +211,20 @@ export async function getBatchIdFromPlanStageId(planStageId: string | null) {
return data.batch_id;
}
+export async function getBatchIdFromApplyStageId(applyStageId: string | null) {
+ if (!applyStageId) return null;
+ const supabase = createSupabaseUserServerComponentClient();
+ const { error, data } = await supabase
+ .from('digger_run_stages')
+ .select('batch_id')
+ .eq('id', applyStageId)
+ .single();
+
+ if (error) throw error;
+
+ return data.batch_id;
+}
+
export async function getTFOutputAndWorkflowURLFromBatchId(
batchId: string | null,
) {
@@ -231,3 +245,23 @@ export async function getTFOutputAndWorkflowURLFromBatchId(
workflow_run_url: data?.workflow_run_url ?? null,
};
}
+export async function getOutputLogsAndWorkflowURLFromBatchId(
+ batchId: string | null,
+) {
+ if (!batchId) return { terraform_output: null, workflow_run_url: null };
+
+ const supabase = createSupabaseUserServerComponentClient();
+ const { error, data } = await supabase
+ .from('digger_jobs')
+ .select('terraform_output, workflow_run_url')
+ .eq('batch_id', batchId)
+ .limit(1)
+ .maybeSingle();
+
+ if (error) throw error;
+
+ return {
+ terraform_output: data?.terraform_output ?? null,
+ workflow_run_url: data?.workflow_run_url ?? null,
+ };
+}