superfly / flyctl-actions

:octocat: GitHub Action that wraps the flyctl
Apache License 2.0
268 stars 34 forks source link

Add setup-flyctl action #20

Closed jacobwgillespie closed 2 years ago

jacobwgillespie commented 2 years ago

This PR adds a new superfly/flyctl-actions/setup-flyctl action in the style mentioned in #12 - the action downloads and installs flyctl using the GitHub Actions toolkit tool cache:

# Install `latest`
- uses: superfly/flyctl-actions/setup-flyctl@1.3
- run: flyctl ...

It's possible to specify a specific version of the CLI to install as well (#10):

# Install a specific version
- uses: superfly/flyctl-actions/setup-flyctl@1.3
  with:
    version: 0.0.306

The advantage of this approach compared to the current Dockerfile action is

  1. Speed - downloading the .tar.gz is significantly faster than building the Dockerfile, and by using @actions/tool-cache, GitHub can cache flyctl between runs.
  2. Native integration - running commands that affect the host environment (such as flyctl auth docker) just work as expected.

For now, this PR adds the action in a subdirectory. You could choose to replace the current action at the root of the repo and publish a new major version, or you could choose to offer both, this PR doesn't make any assumptions either way.


Closes #12 (and possibly #10)

jsierles commented 2 years ago

Hey, thanks for the PR. We haven't had time to look at it yet. If we merge this, will people still be able to use older versions of the action?

EDIT: I didn't see your last comment. So I'll merge this for now and give it a try.

jsierles commented 2 years ago

While running this without arguments, I'm seeing:

   steps:
        - uses: actions/checkout@v2
        - uses: superfly/flyctl-actions/setup-flyctl@master
        - run: "flyctl deploy --remote-only"
Run superfly/flyctl-actions/setup-flyctl@master
  with:
    version: latest
  env:
    FLY_API_TOKEN: ***
    DOCKER_BUILDKIT: 1
Invalid URL
Waiting 16 seconds before trying again
Invalid URL
Waiting 16 seconds before trying again
Error: Invalid URL
jacobwgillespie commented 2 years ago

@jsierles I think that's a transient failure from the Fly API, we've had a few builds receive the following response from the releases API using the install.sh script:

Error: Unable to find a flyctl release for Linux/x86_64/latest - see github.com/superfly/flyctl/releases for all versions

I've opened PR #21 to add better error handling, now a response like ☝️ would be displayed in the Actions log.

jsierles commented 2 years ago

I'm still seeing this error displayed as Invalid URL. Maybe it's coming from elsewhere?

jacobwgillespie commented 2 years ago

You have a FLY_API_TOKEN env var set that I don't (as I haven't provided it yet in my workflow) - does the releases API change behavior if an API key is provided?

jacobwgillespie commented 2 years ago

Actually that's likely not related give that the action doesn't read that variable...

jacobwgillespie commented 2 years ago

It looks like Waiting x seconds before trying again comes from https://github.com/actions/checkout/blob/2d1c1198e79c30cca5c3957b1e3b65ce95b5356e/src/retry-helper.ts#L37

jacobwgillespie commented 2 years ago

Looks like that helper is used when the Actions SDK attempts to download flyctl for the tool cache - I've opened #22 to add a log message to print what URL it's attempting to download, so we can see what it's trying to do in your repo. I'm currently not able to reproduce with a simple example: https://github.com/jacobwgillespie/fly-actions-test/actions/runs/2034036051