Skip to content

Commit

Permalink
Merge pull request #350 from cloudflare/maximo/handle-failures-in-cre…
Browse files Browse the repository at this point in the history
…ate-github-deployment-and-job-summary

Handle failures in createGitHubDeployment and createGitHubJobSummary
  • Loading branch information
Maximo-Guk authored Feb 9, 2025
2 parents 181b9fb + e209094 commit e8cd5f0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-bags-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler-action": patch
---

Handle failures in createGitHubDeployment and createGitHubJobSummary
51 changes: 30 additions & 21 deletions src/service/github.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { summary } from "@actions/core";
import { context, getOctokit } from "@actions/github";
import { env } from "process";
import { info } from "../utils";
import { info, warn } from "../utils";
import { OutputEntryPagesDeployment } from "../wranglerArtifactManager";
import { WranglerActionConfig } from "../wranglerAction";

Expand Down Expand Up @@ -95,25 +95,34 @@ export async function createGitHubDeploymentAndJobSummary(
pagesArtifactFields.deployment_trigger
) {
const octokit = getOctokit(config.GITHUB_TOKEN);
await Promise.all([
createGitHubDeployment({
config,
octokit,
deploymentUrl: pagesArtifactFields.url,
productionBranch: pagesArtifactFields.production_branch,
environment: pagesArtifactFields.environment,
deploymentId: pagesArtifactFields.deployment_id,
projectName: pagesArtifactFields.pages_project,
}),
createJobSummary({
commitHash:
pagesArtifactFields.deployment_trigger.metadata.commit_hash.substring(
0,
8,
),
deploymentUrl: pagesArtifactFields.url,
aliasUrl: pagesArtifactFields.alias,
}),
]);
const [createGitHubDeploymentRes, createJobSummaryRes] =
await Promise.allSettled([
createGitHubDeployment({
config,
octokit,
deploymentUrl: pagesArtifactFields.url,
productionBranch: pagesArtifactFields.production_branch,
environment: pagesArtifactFields.environment,
deploymentId: pagesArtifactFields.deployment_id,
projectName: pagesArtifactFields.pages_project,
}),
createJobSummary({
commitHash:
pagesArtifactFields.deployment_trigger.metadata.commit_hash.substring(
0,
8,
),
deploymentUrl: pagesArtifactFields.url,
aliasUrl: pagesArtifactFields.alias,
}),
]);

if (createGitHubDeploymentRes.status === "rejected") {
warn(config, "Creating Github Deployment failed");
}

if (createJobSummaryRes.status === "rejected") {
warn(config, "Creating Github Job summary failed");
}
}
}
16 changes: 15 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { existsSync } from "node:fs";
import * as path from "node:path";
import semverGt from "semver/functions/gt";
import { info as originalInfo, error as originalError } from "@actions/core";
import {
info as originalInfo,
error as originalError,
warning as originalWarn,
} from "@actions/core";
import { WranglerActionConfig } from "./wranglerAction";

/**
Expand Down Expand Up @@ -32,6 +36,16 @@ export function info(
}
}

export function warn(
config: WranglerActionConfig,
message: string,
bypass?: boolean,
): void {
if (!config.QUIET_MODE || bypass) {
originalWarn(message);
}
}

export function error(
config: WranglerActionConfig,
message: string,
Expand Down

0 comments on commit e8cd5f0

Please sign in to comment.