Merge pull request #291 from Ambroos/add-pages-deployment-alias

Add deployment-alias-url for pages deployments with Wrangler 3.78.0+
This commit is contained in:
Maximo Guk 2024-10-01 19:11:49 -03:00 committed by GitHub
commit 7b9aec5185
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 1 deletions

View file

@ -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

View file

@ -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://<your_pages_site>.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.<your_pages_site>.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`/`bun.lock` file.

View file

@ -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"

View file

@ -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 {