Skip to content

Use wrangler deploy artifacts for deployment URLs #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tsteckenborn opened this issue Oct 25, 2024 · 7 comments · Fixed by #351
Closed

Use wrangler deploy artifacts for deployment URLs #311

tsteckenborn opened this issue Oct 25, 2024 · 7 comments · Fixed by #351
Assignees
Labels

Comments

@tsteckenborn
Copy link

Hi all,
I was wondering why I see some of my environment variables as deployment urls. I would argue that the coding here is not robust enough as I now always get, for example, the posthog endpoint I set as a variable (because it may be us or eu) as my deployment url:

// 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);
}

Would be nice if this could be improved.

@nprogers
Copy link

This is a bug where wrangler-action is picking up the first url listed in environment variables. We need to create a PR to use deployment metadata instead. Updating this issue to reflect what work needs to be done.

@nprogers nprogers changed the title Incorrect deployment URL set Use wrangler deploy artifacts for deployment URLs Nov 12, 2024
Southpaw1496 added a commit to QuiltMC/quiltmc.org that referenced this issue Nov 29, 2024
…)"

This reverts commit fd8b3a5. The world wasn't ready (I think it's cloudflare/wrangler-action#311).

[skip ci]
@michael-land
Copy link

michael-land commented Dec 28, 2024

I still have this issue due to it extracts the first URL from stdout, which is https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md

verison:

    "wrangler": "3.99.0"
    "wrangler-action": "v3.13.0"
/usr/local/bin/npx wrangler deploy
  Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md
   ⛅️ wrangler 3.99.0

@michael-land
Copy link

In my case, the workaround is to add WRANGLER_SEND_METRICS: false to the environment.

CleanShot 2024-12-27 at 23 35 44@2x

@simontong
Copy link

I'm experiencing this issue as well. When I define a URL as a var binding, it's capturing that as the deployment-url:

Wrangler step:

Total Upload: 30.22 KiB / gzip: 11.11 KiB
  Your worker has access to the following bindings:
  - KV Namespaces:
    - XXX: xxxx
  - Vars:
    - MY_URL: "https://example.com/..."
  Uploaded xxx-dev (1.50 sec)
  Deployed xxx-dev triggers (0.15 sec)
    https://xxx-dev.xxx.workers.dev/
  Current Version ID: xxx-xxx-xxx-xxx-xxx
🏁 Wrangler Action completed

Then in the subsequent action step, where I output the deployment URL:

// echo ${{ steps.deploy.outputs.deployment-url }}
echo https://example.com/...

@iharuya
Copy link

iharuya commented Feb 9, 2025

I faced the same issue and this is my workaround to extract the url from stdout:

- name: Deploy to Cloudflare
  id: cloudflare_workers_deploy
  uses: cloudflare/wrangler-action@v3
  with:
    apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    workingDirectory: "apps/backend"

- name: Parse Wrangler Output
  id: parse-wrangler-output
  uses: actions/github-script@v6
  with:
    result-encoding: string
    script: |
      const output = `${{ steps.cloudflare_workers_deploy.outputs.command-output }}`;
      console.log("wrangler output:", output);
      const baseUrl = new URL("https://[worker name].[account name].workers.dev") // your prod url
      const versionIdMatch = output.match(/Current Version ID: ([0-9a-f-]+)/);
      if (!versionIdMatch) {
        core.setFailed("Failed to extract Version ID from wrangler output.");
        return;
      }
      const versionId = versionIdMatch[1].split('-')[0];
      console.log("versionId:", versionId);
      const workersUrl = `https://${versionId}-${baseUrl.hostname}`;
      return workersUrl; // this value can be referenced by `${{ steps.parse-wrangler-output.outputs.result }}`

@Maximo-Guk
Copy link
Member

Hi @michael-land , @simontong and @iharuya 👋 !

Could you see if the latest version of wrangler-action with the latest version of wrangler installed in your repo fixed this issue for you?

@Maximo-Guk Maximo-Guk reopened this Feb 10, 2025
@simontong
Copy link

That appears to have fixed it thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants