cloudflare / wrangler-action

🧙‍♀️ easily deploy cloudflare workers applications using wrangler and github actions
Apache License 2.0
1.14k stars 146 forks source link

Wrangler is reinstalled even when it's already available #199

Open 1000hz opened 10 months ago

1000hz commented 10 months ago

Currently, wrangler-action always installs wrangler as specified by the wranglerVersion input or the DEFAULT_WRANGLER_VERSION constant contained in the source. This isn't always necessary as Wrangler may have already been installed in a previous step of the workflow (e.g. if it's declared in the project's dependencies in package.json). This also makes it harder to keep the version of Wrangler used by wrangler-action and the version used locally consistent, as the user needs to manually keep wranglerVersion and package.json in sync.

Instead, we should only install Wrangler if it's not already present in the $PATH (including the package manager bin directory) OR if wranglerVersion has been explicitly provided

peplin commented 7 months ago

+1 but also wanted to mention that not having the option to disabling this install is preventing my team from using this action because of the hugely increased runtime. The action runs yarn add wrangler and triggers linking for our entire (large) list of dependencies, and this action takes > 2 minutes. npx wrangler is ready in < 3 seconds, for comparison.

AdiRishi commented 6 months ago

I've recently moved all my projects to use wrangler-action in CI. Definitely hit this quite a few times now. I've made a PR with a fix 👍

TonyRL commented 2 months ago

@petebacondarwin Please reopen this issue due to #265.

wqcstrong commented 1 month ago

I've recently moved all my projects to use wrangler-action in CI. Definitely hit this quite a few times now. I've made a PR with a fix 👍

@AdiRishi Thanks for your contribution. However, I am currently facing some issues with my project setup. My project uses yarn workspaces. Even though I have executed yarn install which installs wrangler@3.61.0 at the workspace root in bash ./build.sh , it seems that the check here https://github.com/cloudflare/wrangler-action/blob/main/src/index.ts#L117-L124 did not pass.

// "package.json" in workspace root 
{
  "name": "sony-pages",
  "workspaces": [
    "apps/*"
  ],
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest"
  },
  "devDependencies": {
    "@cloudflare/kv-asset-handler": "^0.3.3",
    "@cloudflare/workers-types": "^4.20240620.0",
    "lerna": "^8.1.5",
    "typescript": "^5.0.4",
    "vitest": "1.3.0",
    "wrangler": "^3.61.0"
  },
  "dependencies": {}
}
// the workflow yml
name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          bash ./build.sh

      - name: Deploy to cloudflare
        uses: cloudflare/wrangler-action@v3.6.0
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Lark bot notify
        run: |
          curl -X POST \
              -H "Content-Type: application/json" \
              ...

Do you know what could be the reason for this? Below is a screenshot of the results from my workflow execution.

image

wqcstrong commented 1 month ago

I've recently moved all my projects to use wrangler-action in CI. Definitely hit this quite a few times now. I've made a PR with a fix 👍

@AdiRishi Thanks for your contribution. However, I am currently facing some issues with my project setup. My project uses yarn workspaces. Even though I have executed yarn install which installs wrangler@3.61.0 at the workspace root in bash ./build.sh , it seems that the check here https://github.com/cloudflare/wrangler-action/blob/main/src/index.ts#L117-L124 did not pass.

// "package.json" in workspace root 
{
  "name": "sony-pages",
  "workspaces": [
    "apps/*"
  ],
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest"
  },
  "devDependencies": {
    "@cloudflare/kv-asset-handler": "^0.3.3",
    "@cloudflare/workers-types": "^4.20240620.0",
    "lerna": "^8.1.5",
    "typescript": "^5.0.4",
    "vitest": "1.3.0",
    "wrangler": "^3.61.0"
  },
  "dependencies": {}
}
// the workflow yml
name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          bash ./build.sh

      - name: Deploy to cloudflare
        uses: cloudflare/wrangler-action@v3.6.0
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Lark bot notify
        run: |
          curl -X POST \
              -H "Content-Type: application/json" \
              ...

Do you know what could be the reason for this? Below is a screenshot of the results from my workflow execution.

image

Delete 'workspaces' field in package.json is one solution:

name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          bash ./build.sh

+      - name: Delete 'workspaces' field
+        run: |
+          jq 'del(.workspaces)' package.json > temp.json
+          mv temp.json package.json
+          cat package.json

      - name: Deploy to cloudflare
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Lark bot notify
        run: |
          curl -X POST \
              -H "Content-Type: application/json" \
              .......
tyteen4a03 commented 1 month ago

Also running into this issue.

acusti commented 1 month ago

@wqcstrong i think you are running into the issue i documented in #277. for now, i just pinned the version in my workflow file (wranglerVersion: 3.64.0), but hopefully the fix will be merged soon (cc: @tyteen4a03 in case you have the same issue)