Skip to content

Commit

Permalink
added workflow outpu
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Jul 29, 2024
1 parent 2e0b1c7 commit 2d6f98e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -58,7 +62,7 @@ function RenderContent({
run.status !== ToTitleCase('pending_plan') &&
run.status !== ToTitleCase('running_plan') && (
<pre className="bg-muted p-4 rounded-md overflow-auto flex-1 max-h-[600px] text-sm whitespace-pre-wrap">
{run.terraform_output || 'No plan output available'}
{tfOutput}
</pre>
)}
</div>
Expand All @@ -76,9 +80,29 @@ function RenderContent({
}
return (
<div className="flex flex-col flex-1">
<h3 className="text-lg font-semibold mb-2">Apply logs</h3>
<div className="flex items-center justify-start gap-2 mb-2">
<h3 className="text-lg font-semibold ">Apply logs</h3>

{applyWorkflowRunUrl && ['pending_apply', 'running_apply', 'succeeded', 'failed'].includes(ToSnakeCase(run.status)) && (
<TooltipProvider>
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Link
href={applyWorkflowRunUrl}
target="_blank"
>
<LinkIcon className="size-4 text-muted-foreground hover:text-foreground cursor-pointer" />
</Link>
</TooltipTrigger>
<TooltipContent side="top" className="flex items-center gap-4">
View workflow run
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</div>
<div className="dark font-mono bg-muted p-4 rounded-md overflow-auto flex-1 max-h-[600px] text-sm whitespace-pre-wrap text-white">
{tfOutput}
{applyTerraformOutput}
</div>
</div>
);
Expand All @@ -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');

Expand Down Expand Up @@ -265,7 +291,7 @@ export const ProjectRunDetails: React.FC<{
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
<RenderContent activeStage={activeStage} run={run} tfOutput={tfOutput} workflowRunUrl={workflowRunUrl} />
<RenderContent activeStage={activeStage} run={run} tfOutput={tfOutput} workflowRunUrl={workflowRunUrl} applyTerraformOutput={applyTerraformOutput} applyWorkflowRunUrl={applyWorkflowRunUrl} />
</motion.div>
</AnimatePresence>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -32,6 +32,8 @@ type ProjectRunDetailsProps = {
isUserOrgAdmin: boolean
tfOutput: string | null
workflowRunUrl: string | null
applyTerraformOutput: string | null
applyWorkflowRunUrl: string | null
fullRepoName: string | null
}

Expand All @@ -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";
Expand All @@ -81,7 +85,14 @@ export default async function RunDetailPage({
</T.P>
}
>
<DynamicProjectRunDetails run={run} loggedInUser={userProfile} isUserOrgAdmin={isOrganizationAdmin} tfOutput={terraform_output} workflowRunUrl={workflow_run_url} fullRepoName={repo_full_name} />
<DynamicProjectRunDetails run={run}
loggedInUser={userProfile}
isUserOrgAdmin={isOrganizationAdmin}
tfOutput={planTerraformOutput}
workflowRunUrl={planWorkflowRunUrl}
applyTerraformOutput={applyLogs}
applyWorkflowRunUrl={applyWorkflowRunUrl}
fullRepoName={repo_full_name} />
</Suspense>
}
</div>
Expand Down
34 changes: 34 additions & 0 deletions src/data/user/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -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,
};
}

0 comments on commit 2d6f98e

Please sign in to comment.