-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves wrangler output to tmpdir rather than /opt/ since /opt/ is owne…
…d by root. - Github self hosted runners may not have permissions to write to /opt/ - Also fallsback to trying to extract the deployment-url and deployment-alias-url from stdout when WRANGLER_OUTPUT_DIR is not specified
- Loading branch information
1 parent
44d79ed
commit b4191bf
Showing
3 changed files
with
50 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler-action": minor | ||
--- | ||
|
||
This reapplies [303](https://github.com/cloudflare/wrangler-action/pull/303) add parity with pages-action for pages deploy outputs |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import { exec, execShell } from "./exec"; | |
import { getPackageManager } from "./packageManagers"; | ||
import { checkWorkingDirectory, semverCompare } from "./utils"; | ||
import { getDetailedPagesDeployOutput } from "./wranglerArtifactManager"; | ||
import { join } from "path"; | ||
import { tmpdir } from "os"; | ||
|
||
const DEFAULT_WRANGLER_VERSION = "3.81.0"; | ||
|
||
|
@@ -34,6 +36,7 @@ const config = { | |
COMMANDS: getMultilineInput("command"), | ||
QUIET_MODE: getBooleanInput("quiet"), | ||
PACKAGE_MANAGER: getInput("packageManager"), | ||
WRANGLER_OUTPUT_DIR: `${join(tmpdir(), "wranglerArtifacts")}`, | ||
} as const; | ||
|
||
const packageManager = getPackageManager(config.PACKAGE_MANAGER, { | ||
|
@@ -277,6 +280,28 @@ async function uploadSecrets() { | |
} | ||
} | ||
|
||
function extractDeploymentUrlsFromStdout(stdOut: string): { | ||
deploymentUrl?: string; | ||
aliasUrl?: string; | ||
} { | ||
let deploymentUrl = ""; | ||
let aliasUrl = ""; | ||
|
||
// Try to extract the deployment URL | ||
const deploymentUrlMatch = stdOut.match(/https?:\/\/[a-zA-Z0-9-./]+/); | ||
if (deploymentUrlMatch && deploymentUrlMatch[0]) { | ||
deploymentUrl = deploymentUrlMatch[0].trim(); | ||
} | ||
|
||
// And also try to extract the alias URL (since [email protected]) | ||
const aliasUrlMatch = stdOut.match(/alias URL: (https?:\/\/[a-zA-Z0-9-./]+)/); | ||
if (aliasUrlMatch && aliasUrlMatch[1]) { | ||
aliasUrl = aliasUrlMatch[1].trim(); | ||
} | ||
|
||
return { deploymentUrl, aliasUrl }; | ||
} | ||
|
||
async function wranglerCommands() { | ||
startGroup("🚀 Running Wrangler Commands"); | ||
try { | ||
|
@@ -313,9 +338,8 @@ async function wranglerCommands() { | |
let stdOut = ""; | ||
let stdErr = ""; | ||
|
||
// Construct the options for the exec command | ||
const wranglerOutputDir = "/opt/wranglerArtifacts"; | ||
process.env.WRANGLER_OUTPUT_FILE_DIRECTORY = wranglerOutputDir; | ||
// set WRANGLER_OUTPUT_FILE_DIRECTORY env for exec | ||
process.env.WRANGLER_OUTPUT_FILE_DIRECTORY = config.WRANGLER_OUTPUT_DIR; | ||
|
||
const options = { | ||
cwd: config["workingDirectory"], | ||
|
@@ -339,41 +363,35 @@ async function wranglerCommands() { | |
|
||
// Check if this command is a workers deployment | ||
if (command.startsWith("deploy") || command.startsWith("publish")) { | ||
// Try to extract the deployment URL | ||
let deploymentUrl = ""; | ||
const deploymentUrlMatch = stdOut.match(/https?:\/\/[a-zA-Z0-9-./]+/); | ||
if (deploymentUrlMatch && deploymentUrlMatch[0]) { | ||
deploymentUrl = deploymentUrlMatch[0].trim(); | ||
setOutput("deployment-url", deploymentUrl); | ||
} | ||
|
||
// And also try to extract the alias URL (since [email protected]) | ||
const aliasUrlMatch = stdOut.match( | ||
/alias URL: (https?:\/\/[a-zA-Z0-9-./]+)/, | ||
); | ||
if (aliasUrlMatch && aliasUrlMatch.length == 2 && aliasUrlMatch[1]) { | ||
const aliasUrl = aliasUrlMatch[1].trim(); | ||
setOutput("deployment-alias-url", aliasUrl); | ||
} | ||
const { deploymentUrl, aliasUrl } = | ||
extractDeploymentUrlsFromStdout(stdOut); | ||
setOutput("deployment-url", deploymentUrl); | ||
setOutput("deployment-alias-url", aliasUrl); | ||
} | ||
// Check if this command is a pages deployment | ||
if ( | ||
command.startsWith("pages publish") || | ||
command.startsWith("pages deploy") | ||
) { | ||
const pagesArtifactFields = | ||
await getDetailedPagesDeployOutput(wranglerOutputDir); | ||
const pagesArtifactFields = await getDetailedPagesDeployOutput( | ||
config.WRANGLER_OUTPUT_DIR, | ||
); | ||
|
||
if (pagesArtifactFields) { | ||
setOutput("id", pagesArtifactFields.deployment_id); | ||
setOutput("url", pagesArtifactFields.url); | ||
// To ensure parity with pages-action, display url for alias if there is no alias | ||
setOutput("alias", pagesArtifactFields.alias); | ||
setOutput("deployment-url", pagesArtifactFields.url); | ||
setOutput("deployment-alias-url", pagesArtifactFields.alias); | ||
setOutput("environment", pagesArtifactFields.environment); | ||
} else { | ||
info( | ||
"No fields available for output. Have you updated wrangler to version >=3.81.0?", | ||
"Unable to find a WRANGLER_OUTPUT_DIR, environment and id fields will be unavailable for output. Have you updated wrangler to version >=3.81.0?", | ||
); | ||
// fallback to trying to extract the deployment-url and deployment-alias-url from stdout | ||
const { deploymentUrl, aliasUrl } = | ||
extractDeploymentUrlsFromStdout(stdOut); | ||
|
||
setOutput("deployment-url", deploymentUrl); | ||
setOutput("deployment-alias-url", aliasUrl); | ||
} | ||
} | ||
} | ||
|