diff --git a/.changeset/little-cougars-shout.md b/.changeset/little-cougars-shout.md new file mode 100644 index 0000000..01056ae --- /dev/null +++ b/.changeset/little-cougars-shout.md @@ -0,0 +1,6 @@ +--- +"wrangler-action": minor +--- + +Adds `deployment-alias-url` output for Pages deployment aliases (since Wrangler v3.78.0): https://github.com/cloudflare/workers-sdk/pull/6643 + diff --git a/README.md b/README.md index 3ddfda2..5a0f6d0 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ Now when you run your workflow, you will see the full output of the Wrangler com > Note: the `command-stderr` output variable is also available if you need to parse the standard error output of the Wrangler command. -### Using the `deployment-url` Output Variable +### Using the `deployment-url` and `deployment-alias-url` Output Variables If you are executing a Wrangler command that results in either a Workers or Pages deployment, you can utilize the `deployment-url` output variable to get the URL of the deployment. For example, if you want to print the deployment URL after deploying your application, you can do the following: @@ -287,6 +287,23 @@ The resulting output will look something like this: https://.pages.dev ``` +Pages deployments will also provide their alias URL (since Wrangler v3.78.0). You can use the `deployment-alias-url` output variable to get the URL of the deployment alias. This is useful for, for example, branch aliases for preview deployments. + +If the sample action above was used to deploy a branch other than main, you could use the following to get the branch URL: + +```yaml +- name: print deployment-alias-url + env: + DEPLOYMENT_ALIAS_URL: ${{ steps.deploy.outputs.deployment-alias-url }} + run: echo $DEPLOYMENT_ALIAS_URL +``` + +Resulting in: + +```text +https://new-feature..pages.dev +``` + ### Using a different package manager By default, this action will detect which package manager to use, based on the presence of a `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb` file. diff --git a/action.yml b/action.yml index e780f21..6094973 100644 --- a/action.yml +++ b/action.yml @@ -51,3 +51,5 @@ outputs: description: "The error output of the Wrangler command (comes from stderr)" deployment-url: description: "If the command was a Workers or Pages deployment, this will be the URL of the deployment" + deployment-alias-url: + description: "If the command was a Workers or Pages deployment, this can be the URL of the deployment alias (if it exists) - needs wrangler >= 3.78.0" diff --git a/src/index.ts b/src/index.ts index 3e2df44..4dad368 100755 --- a/src/index.ts +++ b/src/index.ts @@ -347,6 +347,15 @@ async function wranglerCommands() { deploymentUrl = deploymentUrlMatch[0].trim(); setOutput("deployment-url", deploymentUrl); } + + // 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.length == 2 && aliasUrlMatch[1]) { + const aliasUrl = aliasUrlMatch[1].trim(); + setOutput("deployment-alias-url", aliasUrl); + } } } } finally {