Compare commits

..

13 Commits

Author SHA1 Message Date
github-actions[bot] da0e0dfe58 Automatic compilation 2025-03-15 02:01:33 +00:00
Maximo Guk 707f637509 Merge pull request #359 from cloudflare/changeset-release/main
Version Packages
2025-03-14 21:01:10 -05:00
github-actions[bot] e764ef3355 Version Packages 2025-03-15 01:57:01 +00:00
Maximo Guk 8d761e6bdc Merge pull request #358 from cloudflare/penalosa-patch-2
Support Wrangler v4 bulk secrets
2025-03-14 20:56:46 -05:00
Maximo Guk cd6314a97b Use wranglers secret:bulk on versions of wrangler prior to 3.60.0 2025-03-14 20:27:34 -05:00
Somhairle MacLeòid ef1f9fb2b0 Update wranglerAction.ts 2025-03-15 00:25:40 +00:00
Maximo Guk 08959b2671 Merge pull request #353 from cloudflare/changeset-release/main
Version Packages
2025-02-10 13:02:55 -06:00
github-actions[bot] abb67eda8d Version Packages 2025-02-10 18:57:44 +00:00
Maximo Guk 883eaf2de0 Merge pull request #351 from cloudflare/maximo/use-wrangler-outputs-for-version-upload-and-wrangler-deploy
Use wrangler outputs for wrangler deploy and versions upload
2025-02-10 12:56:18 -06:00
Maximo Guk 4ff07f4310 Use wrangler outputs for version upload and wrangler deploy 2025-02-09 17:10:09 -06:00
Maximo Guk 4fb15f8b7a Bump @changesets/cli to 2.27.12 and vitest to 2.1.9 2025-02-09 16:51:41 -06:00
Maximo Guk e8cd5f0968 Merge pull request #350 from cloudflare/maximo/handle-failures-in-create-github-deployment-and-job-summary
Handle failures in createGitHubDeployment and createGitHubJobSummary
2025-02-09 16:51:09 -06:00
Maximo Guk e209094e62 Handle failures in createGitHubDeployment and createGitHubJobSummary 2025-02-09 16:49:07 -06:00
+182 -64
View File
@@ -7703,6 +7703,16 @@ const gt = (a, b, loose) => compare(a, b, loose) > 0
module.exports = gt
/***/ }),
/***/ 3872:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
const compare = __nccwpck_require__(8469)
const lt = (a, b, loose) => compare(a, b, loose) < 0
module.exports = lt
/***/ }),
/***/ 5101:
@@ -32449,6 +32459,11 @@ function info(config, message, bypass) {
(0,core.info)(message);
}
}
function warn(config, message, bypass) {
if (!config.QUIET_MODE || bypass) {
(0,core.warning)(message);
}
}
function error(config, message, bypass) {
if (!config.QUIET_MODE || bypass) {
(0,core.error)(message);
@@ -36766,6 +36781,22 @@ const OutputEntryPagesDeployment = OutputEntryBase.merge(z.object({
})
.optional(),
}));
const OutputEntryDeployment = OutputEntryBase.merge(z.object({
type: z.literal("deploy"),
/** A list of URLs that represent the HTTP triggers associated with this deployment */
/** basically, for wrangler-action purposes this is the deployment urls */
targets: z.array(z.string()).optional(),
}));
const OutputEntryVersionUpload = OutputEntryBase.merge(z.object({
type: z.literal("version-upload"),
/** The preview URL associated with this version upload */
preview_url: z.string().optional(),
}));
const SupportedOutputEntry = z.discriminatedUnion("type", [
OutputEntryPagesDeployment,
OutputEntryDeployment,
OutputEntryVersionUpload,
]);
/**
* Parses file names in a directory to find wrangler artifact files
*
@@ -36792,30 +36823,31 @@ async function getWranglerArtifacts(artifactDirectory) {
return artifactFilePaths;
}
/**
* Searches for detailed wrangler output from a pages deploy
* Searches for a supported wrangler OutputEntry
*
* @param artifactDirectory
* @returns The first pages-output-detailed found within a wrangler artifact directory
* @returns The first SupportedOutputEntry found within a wrangler artifact directory
*/
async function getDetailedPagesDeployOutput(artifactDirectory) {
async function getOutputEntry(artifactDirectory) {
const artifactFilePaths = await getWranglerArtifacts(artifactDirectory);
for (let i = 0; i < artifactFilePaths.length; i++) {
const file = await (0,promises_namespaceObject.open)(artifactFilePaths[i], "r");
for await (const line of file.readLines()) {
try {
const output = JSON.parse(line);
const parsedOutput = OutputEntryPagesDeployment.parse(output);
if (parsedOutput.type === "pages-deploy-detailed") {
// Assume, in the context of the action, the first detailed deploy instance seen will suffice
return parsedOutput;
for (const filePath of artifactFilePaths) {
const file = await (0,promises_namespaceObject.open)(filePath, "r");
try {
for await (const line of file.readLines()) {
try {
// Attempt to parse and validate the JSON line against the union schema.
// Assume, in the context of the action, the first OutputEntry seen will suffice
return SupportedOutputEntry.parse(JSON.parse(line));
}
catch {
// Skip lines that are invalid JSON or don't match any schema.
continue;
}
}
catch (err) {
// If the line can't be parsed, skip it
continue;
}
}
await file.close();
finally {
await file.close();
}
}
return null;
}
@@ -36882,7 +36914,7 @@ async function createGitHubDeploymentAndJobSummary(config, pagesArtifactFields)
pagesArtifactFields.pages_project &&
pagesArtifactFields.deployment_trigger) {
const octokit = (0,github.getOctokit)(config.GITHUB_TOKEN);
await Promise.all([
const [createGitHubDeploymentRes, createJobSummaryRes] = await Promise.allSettled([
createGitHubDeployment({
config,
octokit,
@@ -36898,9 +36930,134 @@ async function createGitHubDeploymentAndJobSummary(config, pagesArtifactFields)
aliasUrl: pagesArtifactFields.alias,
}),
]);
if (createGitHubDeploymentRes.status === "rejected") {
warn(config, "Creating Github Deployment failed");
}
if (createJobSummaryRes.status === "rejected") {
warn(config, "Creating Github Job summary failed");
}
}
}
;// CONCATENATED MODULE: ./src/commandOutputParsing.ts
// fallback to trying to extract the deployment-url and pages-deployment-alias-url from stdout for wranglerVersion < 3.81.0
function extractDeploymentUrlsFromStdout(stdOut) {
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 wrangler@3.78.0)
const aliasUrlMatch = stdOut.match(/alias URL: (https?:\/\/[a-zA-Z0-9-./]+)/);
if (aliasUrlMatch && aliasUrlMatch[1]) {
aliasUrl = aliasUrlMatch[1].trim();
}
return { deploymentUrl, aliasUrl };
}
async function handlePagesDeployOutputEntry(config, pagesDeployOutputEntry) {
(0,core.setOutput)("deployment-url", pagesDeployOutputEntry.url);
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
(0,core.setOutput)("deployment-alias-url", pagesDeployOutputEntry.alias);
(0,core.setOutput)("pages-deployment-alias-url", pagesDeployOutputEntry.alias);
(0,core.setOutput)("pages-deployment-id", pagesDeployOutputEntry.deployment_id);
(0,core.setOutput)("pages-environment", pagesDeployOutputEntry.environment);
// Create github deployment, if GITHUB_TOKEN is present in config
await createGitHubDeploymentAndJobSummary(config, pagesDeployOutputEntry);
}
/**
* If no wrangler output file found, fallback to extracting deployment-url from stdout.
* @deprecated Use {@link handlePagesDeployOutputEntry} instead.
*/
function handlePagesDeployCommand(config, stdOut) {
info(config, "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?");
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
const { deploymentUrl, aliasUrl } = extractDeploymentUrlsFromStdout(stdOut);
(0,core.setOutput)("deployment-url", deploymentUrl);
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
(0,core.setOutput)("deployment-alias-url", aliasUrl);
(0,core.setOutput)("pages-deployment-alias-url", aliasUrl);
}
function handleWranglerDeployOutputEntry(config, wranglerDeployOutputEntry) {
// If no deployment urls found in wrangler output file, log that we couldn't find any urls and return.
if (!wranglerDeployOutputEntry.targets ||
wranglerDeployOutputEntry.targets.length === 0) {
info(config, "No deployment-url found in wrangler deploy output file");
return;
}
// If more than 1 deployment url found, log that we're going to set deployment-url to the first match.
// In a future wrangler-action version we should consider how we're going to output multiple deployment-urls
if (wranglerDeployOutputEntry.targets.length > 1) {
info(config, "Multiple deployment urls found in wrangler deploy output file, deployment-url will be set to the first url");
}
(0,core.setOutput)("deployment-url", wranglerDeployOutputEntry.targets[0]);
}
/**
* If no wrangler output file found, fallback to extracting deployment-url from stdout.
* @deprecated Use {@link handleWranglerDeployOutputEntry} instead.
*/
function handleWranglerDeployCommand(config, stdOut) {
info(config, "Unable to find a WRANGLER_OUTPUT_DIR, deployment-url may have an unreliable output. Have you updated wrangler to version >=3.88.0?");
const { deploymentUrl } = extractDeploymentUrlsFromStdout(stdOut);
(0,core.setOutput)("deployment-url", deploymentUrl);
}
function handleVersionsUploadOutputEntry(versionsOutputEntry) {
(0,core.setOutput)("deployment-url", versionsOutputEntry.preview_url);
}
/**
* If no wrangler output file found, log a message stating deployment-url will be unavailable for output.
* @deprecated Use {@link handleVersionsOutputEntry} instead.
*/
function handleVersionsOutputCommand(config) {
info(config, "Unable to find a WRANGLER_OUTPUT_DIR, deployment-url will be unavailable for output. Have you updated wrangler to version >=3.88.0?");
}
function handleDeprectatedStdoutParsing(config, command, stdOut) {
// Check if this command is a pages deployment
if (command.startsWith("pages deploy") ||
command.startsWith("pages publish")) {
handlePagesDeployCommand(config, stdOut);
return;
}
// Check if this command is a workers deployment
if (command.startsWith("deploy") || command.startsWith("publish")) {
handleWranglerDeployCommand(config, stdOut);
return;
}
// Check if this command is a versions deployment
if (command.startsWith("versions upload")) {
handleVersionsOutputCommand(config);
return;
}
}
async function handleCommandOutputParsing(config, command, stdOut) {
// get first OutputEntry found within wrangler artifact output directory
const outputEntry = await getOutputEntry(config.WRANGLER_OUTPUT_DIR);
if (outputEntry === null) {
// if no outputEntry found, fallback to deprecated stdOut parsing
handleDeprectatedStdoutParsing(config, command, stdOut);
return;
}
switch (outputEntry.type) {
case "pages-deploy-detailed":
await handlePagesDeployOutputEntry(config, outputEntry);
break;
case "deploy":
handleWranglerDeployOutputEntry(config, outputEntry);
break;
case "version-upload":
handleVersionsUploadOutputEntry(outputEntry);
break;
}
}
// EXTERNAL MODULE: ./node_modules/semver/functions/lt.js
var lt = __nccwpck_require__(3872);
var lt_default = /*#__PURE__*/__nccwpck_require__.n(lt);
;// CONCATENATED MODULE: ./src/wranglerAction.ts
@@ -37078,7 +37235,11 @@ async function uploadSecrets(config, packageManager) {
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0")) {
return legacyUploadSecrets(config, packageManager, secrets, environment, workingDirectory);
}
const args = ["wrangler", "secret:bulk"];
let args = ["wrangler", "secret", "bulk"];
// if we're on a WRANGLER_VERSION prior to 3.60.0 use wrangler secret:bulk
if (lt_default()(config["WRANGLER_VERSION"], "3.60.0")) {
args = ["wrangler", "secret:bulk"];
}
if (environment) {
args.push("--env", environment);
}
@@ -37099,22 +37260,6 @@ async function uploadSecrets(config, packageManager) {
endGroup(config);
}
}
// fallback to trying to extract the deployment-url and pages-deployment-alias-url from stdout for wranglerVersion < 3.81.0
function extractDeploymentUrlsFromStdout(stdOut) {
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 wrangler@3.78.0)
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(config, packageManager) {
startGroup(config, "🚀 Running Wrangler Commands");
try {
@@ -37162,35 +37307,8 @@ async function wranglerCommands(config, packageManager) {
// Set the outputs for the command
(0,core.setOutput)("command-output", stdOut);
(0,core.setOutput)("command-stderr", stdErr);
// Check if this command is a workers deployment
if (command.startsWith("deploy") || command.startsWith("publish")) {
const { deploymentUrl } = extractDeploymentUrlsFromStdout(stdOut);
(0,core.setOutput)("deployment-url", deploymentUrl);
}
// Check if this command is a pages deployment
if (command.startsWith("pages publish") ||
command.startsWith("pages deploy")) {
const pagesArtifactFields = await getDetailedPagesDeployOutput(config.WRANGLER_OUTPUT_DIR);
if (pagesArtifactFields) {
(0,core.setOutput)("deployment-url", pagesArtifactFields.url);
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
(0,core.setOutput)("deployment-alias-url", pagesArtifactFields.alias);
(0,core.setOutput)("pages-deployment-alias-url", pagesArtifactFields.alias);
(0,core.setOutput)("pages-deployment-id", pagesArtifactFields.deployment_id);
(0,core.setOutput)("pages-environment", pagesArtifactFields.environment);
// Create github deployment, if GITHUB_TOKEN is present in config
await createGitHubDeploymentAndJobSummary(config, pagesArtifactFields);
}
else {
info(config, "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?");
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
const { deploymentUrl, aliasUrl } = extractDeploymentUrlsFromStdout(stdOut);
(0,core.setOutput)("deployment-url", deploymentUrl);
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
(0,core.setOutput)("deployment-alias-url", aliasUrl);
(0,core.setOutput)("pages-deployment-alias-url", aliasUrl);
}
}
// Handles setting github action outputs and creating github deployment and job summary
await handleCommandOutputParsing(config, command, stdOut);
}
}
finally {