Repository navigation
Upload to R2 with the AWS CLI instead of a third-party action - #191
Merged
Merged
Conversation
R2 is S3-compatible and the AWS CLI ships in the runner image, so the upload needs no third-party action. This takes third-party code off the path that holds the Cloudflare R2 write credentials. Keeps the same key layout: aws s3 cp --recursive maps the source directory's contents under the destination prefix exactly as the action's source-dir/destination-dir pair did. Uses cp rather than sync so promote always rewrites a manifest whose size happens to be unchanged, and strips a trailing slash from the directory input so a caller passing "foo/" no longer yields a "foo//" prefix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
ryand56/r2-upload-actioninupload-to-r2.ymlandpromote-r2.ymlwith a plainaws s3 cp --recursivestep. R2 is S3-compatible and the AWS CLI ships in the runner image (AWS CLI 2.36.2on the Ubuntu 24.04 image,2.36.16on 26.04, both listed underCLI Toolsin actions/runner-images), so the upload needs no third-party action and no install step.The main motivation is credential exposure: the action is a JavaScript action that received
CLOUDFLARE_R2_SECRET_ACCESS_KEYin its environment and ran a bundledaws-sdk-jsplus whatever else it shipped. SHA-pinning froze that code but also froze its dependencies. Removing it takes third-party code off the path that holds R2 write credentials forfirmware.esphome.io.I considered factoring the shared step into a composite action in this repo, but a relative
uses: ./.github/actions/...inside a called reusable workflow resolves against the caller's workspace rather than this repo, and these workflows do no checkout. It would mean adding anactions/checkoutofesphome/workflowsat a hardcoded self-referential ref to every consumer run, which is not worth it for eight lines used twice.Behaviour is unchanged
destination-dir+ the path relative tosource-dir;aws s3 cp <dir> s3://bucket/prefix/ --recursivedoes the same, sofiles/<device>/<version>/manifest.jsonstill lands at<directory>/<device>/<version>/manifest.json..jsonresolves toapplication/json(the web installer fetches the manifests), and.bin/.elfend up as octet-stream either way.cprather thansync, deliberately: promote re-uploads a manifest whose size may be unchanged, andsyncwould skip it.${DIRECTORY%/}/strips a trailing slash, so a caller passingfoo/no longer produces afoo//prefix. The previous${{ inputs.directory }}/would have.Things worth knowing
AWS_REQUEST_CHECKSUM_CALCULATION: when_requiredguards against the CRC32 trailers AWS CLI 2.23 and newer send by default, which R2 has intermittently rejected. Cloudflare's current docs no longer mention the workaround, but it costs nothing to keep.The tradeoff is that the CLI version now floats with the runner image where the pinned action was frozen. That is the failure mode that bit R2 users in January 2025, when an image bump to CLI 2.23 started breaking uploads. Worth noting the pinned action was not immune to that class of bug either, since
aws-sdk-jsv3.729.0 had the same breakage. If we would rather have determinism, the alternative is installing a pinned CLI in the step at roughly 15s per job.CI has no R2 secrets, so nothing here exercises the upload path. It is unverified until a real release run.
yamllintpasses, andactionlintwith shellcheck reports nothing on the new steps.