mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-25 03:14:46 +01:00
parse and set the deployment-url
This commit is contained in:
parent
11fa60953d
commit
97c920b38e
3 changed files with 38 additions and 0 deletions
25
README.md
25
README.md
|
@ -243,6 +243,31 @@ 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.
|
> 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
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Deploy
|
||||||
|
id: deploy
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: pages deploy --project-name=example
|
||||||
|
|
||||||
|
- name: print deployment-url
|
||||||
|
env:
|
||||||
|
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
|
run: echo $DEPLOYMENT_URL
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting output will look something like this:
|
||||||
|
|
||||||
|
```text
|
||||||
|
https://<your_pages_site>.pages.dev
|
||||||
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### "I just started using Workers/Wrangler and I don't know what this is!"
|
### "I just started using Workers/Wrangler and I don't know what this is!"
|
||||||
|
|
|
@ -49,3 +49,5 @@ outputs:
|
||||||
description: "The output of the Wrangler command (comes from stdout)"
|
description: "The output of the Wrangler command (comes from stdout)"
|
||||||
command-stderr:
|
command-stderr:
|
||||||
description: "The error output of the Wrangler command (comes from stderr)"
|
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"
|
||||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -267,6 +267,17 @@ async function wranglerCommands() {
|
||||||
// Set the outputs for the command
|
// Set the outputs for the command
|
||||||
setOutput("command-output", stdOut);
|
setOutput("command-output", stdOut);
|
||||||
setOutput("command-stderr", stdErr);
|
setOutput("command-stderr", stdErr);
|
||||||
|
|
||||||
|
// Check if this command is a workers or pages deployment
|
||||||
|
if (command.startsWith("deploy") || command.startsWith("publish")) {
|
||||||
|
// If this is a workers or pages deployment, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
endGroup();
|
endGroup();
|
||||||
|
|
Loading…
Reference in a new issue