Coder Social home page Coder Social logo

Comments (14)

tillkruss avatar tillkruss commented on May 18, 2024 3

@signalnerve: Two Tills requesting this feature, must be a sign.

from wrangler-action.

kristianfreeman avatar kristianfreeman commented on May 18, 2024 1

@bradyjoslin this is awesome! I'm wondering if it makes more sense to have it not be wrangler subcommands, and just have a pre/post-publish inputs that you can use to execute commands inside of the wrangler-action context. @till would be curious on your thoughts around this too

from wrangler-action.

till avatar till commented on May 18, 2024 1

@bradyjoslin I think that sounds great! :)

from wrangler-action.

kristianfreeman avatar kristianfreeman commented on May 18, 2024

hm, good question! you may be able to put in some shell commands after the uses: wrangler-action step and just call wrangler directly, but i haven't tested it!

from wrangler-action.

tillkruss avatar tillkruss commented on May 18, 2024

I'm getting this error:

/home/runner/work/_temp/...673e2ea27105.sh: line 1: wrangler: command not found

Step:

- name: Clean KV cache
    run: wrangler kv:key delete --binding=app cache-foo

from wrangler-action.

till avatar till commented on May 18, 2024

The action doesn't do anything besides wrangler publish. So I have a similar request, I want to run wrangler build only (and then deploy with Terraform). Can you extend your action to support this?

from wrangler-action.

bradyjoslin avatar bradyjoslin commented on May 18, 2024

One option for addressing would be similar to how the action was extended for secrets.

Example action yaml of implementation idea:

jobs:
  deploy:
    steps:
      uses: cloudflare/[email protected]
      with:
        apiToken: ${{ secrets.CF_API_TOKEN }}
        wrangler-commands: |
            kv:namespace create "MY_KV"
            kv:key put --binding=MY_KV "key" "value"

entrypoint.sh could be updated as:

# If an environment is detected as input, for each secret specified get the value of
# the matching named environment variable then configure using wrangler secret put.
if [ -z "$INPUT_ENVIRONMENT" ]
then
  wrangler publish

  for SECRET in $INPUT_SECRETS; do
    VALUE=$(printenv "$SECRET") || secret_not_found "$SECRET"
    echo "$VALUE" | wrangler secret put "$SECRET"
  done

  # ** New feature for handling arbitrary wrangler commands **
  for COMMAND in $INPUT_WRANGLER_COMMANDS; do
    wrangler "$COMMAND"
  done
else
  wrangler publish -e "$INPUT_ENVIRONMENT"

  # ** New feature for handling arbitrary wrangler commands **
  for COMMAND in $INPUT_WRANGLER_COMMANDS; do
    wrangler "$COMMAND" --env "$INPUT_ENVIRONMENT"
  done
fi

from wrangler-action.

tillkruss avatar tillkruss commented on May 18, 2024

@bradyjoslin, nice! Can you submit a PR?

from wrangler-action.

bradyjoslin avatar bradyjoslin commented on May 18, 2024

That's sort of pseudocode above just to express an idea, if implemented as written a few things wouldn't work right. But, if I get some time I'll try and prototype something out.

from wrangler-action.

bradyjoslin avatar bradyjoslin commented on May 18, 2024

Have a POC working with these changes.

Update to action.yaml:

...
  wranglerCommands:
    description: "(Advanced) A new line deliminated string of wrangler commands.  Target environment must be explicitly specified."
    required: false

With this update to entrypoint.sh.

...
# ** New feature for handling arbitrary wrangler commands **
printf '%s' "$INPUT_WRANGLERCOMMANDS" | while IFS= read -r COMMAND; do
  OPTS=()

  for OPT in $COMMAND; do
    OPTS+=("$OPT")
  done

  wrangler "${OPTS[@]}"

  OPTS=()
done

Example deployment.yml that updates two kv entries using the action:

...
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          environment: "production"
          workingDirectory: "test"
          secrets: SECRET1
          wranglerCommands: |
            kv:key put --binding=STATIC_TEST_MY_KV key value
            kv:key put --binding=STATIC_TEST_MY_KV key2 value2
        env:
          SECRET1: ${{ secrets.SECRET1 }}

from wrangler-action.

till avatar till commented on May 18, 2024

@bradyjoslin please open a pull-request? Other people can take it on if it goes stale and you don't have the time.

from wrangler-action.

till avatar till commented on May 18, 2024

@signalnerve Well, sort of.

I need something basic like, a action: build, and I figured I can always "include" the action multiple times (if the penalty of running or restarting it isn't too high), but see #29 for what I mean. E.g. if I wanted to kv:key put, I would include it again in the next step.

So as long as I can e.g. not do publish (it can be the default though), then that works. Right now this adds pre/post commands, so it's not exactly what I need.

from wrangler-action.

bradyjoslin avatar bradyjoslin commented on May 18, 2024

An idea for supporting builds without publish...

A new optional action input publish that if set to false could skip the wrangler publish portion of the Action's script.

That way if someone wanted to just build, run kv commands, or anything else, they could specify those as preCommands or postCommands with publish set to false.

from wrangler-action.

bradyjoslin avatar bradyjoslin commented on May 18, 2024

@till - Awesome! PR #35 updated to include this additional option.

Set the optional publish input to false to skip publishing your Worker project and secrets. Useful in conjunction with pre and post commands. For example, if you only wanted to run wrangler build against your project:

jobs:
  deploy:
    steps:
      uses: cloudflare/[email protected]
      with:
        apiToken: ${{ secrets.CF_API_TOKEN }}
        publish: false
        preCommands: wrangler build

from wrangler-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.