Skip to content
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

Unable to forward command output #206

Closed
LeoColomb opened this issue Oct 31, 2023 · 2 comments
Closed

Unable to forward command output #206

LeoColomb opened this issue Oct 31, 2023 · 2 comments

Comments

@LeoColomb
Copy link

LeoColomb commented Oct 31, 2023

Here is my use case:

      - name: Retrieve Terraform State
        uses: cloudflare/[email protected]
        with:
          command: kv:namespace list | jq -r '.[] | select( .title == "dispoflare-terraform-state" ) | .id' .kv_namespace_list.json | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

This use case is mostly coming from Cloudflare Wildbeest deploy workflow:
https://github.com/cloudflare/wildebeest/blob/20efb7f0eb504462be869b91102307991d991c2f/.github/workflows/deploy.yml#L127-L137

The command is executed as followed, with the following wrangler error:

🚀 Running Wrangler Commands
  /usr/local/bin/npx wrangler kv:namespace list | jq -r '.[] | select( .title == dispoflare-terraform-state ) | .id' .kv_namespace_list.json | awk '{print tfstate_kv=$1}' >> $GITHUB_ENV
  
  ✘ [ERROR] Unknown arguments: r, |, jq, |, select(, .title, ==, dispoflare-terraform-state, ), |, .id', .kv_namespace_list.json, |, awk, '{print, tfstate_kv=$1}', >>, $GITHUB_ENV

Indeed, since #171, all arguments of command parameter are passed directly to the package manager.
It is therefore impossible to forward output to something else than the default stdout.

Using pre/post-commands as a workaround is mostly impossible due to #178.

@1000hz
Copy link
Contributor

1000hz commented Oct 31, 2023

Hey @LeoColomb, thanks for filing an issue.

Yeah, command doesn't execute within a shell, which is by design since we decorate the command you provide with extra stuff (your package manager's exec command, wrangler, extra flags, etc.) to produce the actually executed command. Supporting a shell would make that significantly more error-prone and complex.

Using pre/post-commands is mostly impossible due to #178.

What about #178 is preventing you from using pre/post-commands here? The two issues described there boil down to needing to invoke wrangler via your package manager and having to provide your own flags. It's maybe not quite as convenient, but definitely still possible.

This should work for you (assuming you're using npm):

      - name: Retrieve Terraform State
        uses: cloudflare/[email protected]
        with:
-         command: kv:namespace list | jq -r '.[] | select( .title == "dispoflare-terraform-state" ) | .id' .kv_namespace_list.json | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV
+         preCommands: npx wrangler kv:namespace list | jq -r '.[] | select( .title == "dispoflare-terraform-state" ) | .id' .kv_namespace_list.json | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

It's also worth mentioning, wrangler-action is primarily geared toward the use case of easily deploying your Workers via CI. The Wildebeest workflows probably would have been better off installing wrangler into the runner environment and just running shell commands via run: for most of its steps rather than using wrangler-action a whole bunch of times.

@LeoColomb
Copy link
Author

Thanks for your reply, @1000hz.
Indeed, I read #178 a bit too quick, I guess 😊
This is working, but comes with a few drawbacks: as you mentioned, the need to invoke the package manager, but also the need to pass a dummy command to avoid unexpected deployments.

Noted for the mention, I'll give a try to do in this other way instead.

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

No branches or pull requests

2 participants