Skip to content

Commit

Permalink
Add deployment-alias-url for pages deployments with Wrangler 3.78.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambroos committed Sep 19, 2024
1 parent 3ea6e3f commit a1467a0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/little-cougars-shout.md
Original file line number Diff line number Diff line change
@@ -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

19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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` file.
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ async function wranglerCommands() {
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);
}
}
}
} finally {
Expand Down

0 comments on commit a1467a0

Please sign in to comment.