Simplify to single file uploads and config settings for runtime customisation
We currently support uploading single files with curl_upload_file
and multiple with curl_upload_manifest
. We also have a complex substitution mechanism to allow overriding the destination URL at both target definition time and a runtime. This allow use to support use cases where we might have a destination URL that makes sense for local development use but in CI we need to inject and additional folder (e.g. with the CI job id) to make it unique per CI run.
We could simplify this to supporting single files or directories in a single rule and by moving the URL customization to use config_setting
s.
For example,
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
string_flag(
name = "injection",
build_setting_default = "",
make_variable = "INJECT"
)
curl_upload(
name = "upload",
src = ":fixture.txt",
url = "https://test.case/directory/fixture.txt",
)
curl_upload(
name = "upload_custom",
src = ":fixture.txt",
url = "https://test.case/directory/$(INJECT)fixture",
toolchains = [":injection"]
)
For single files this gives you the flexibility to use the original filename for upload, if the url ends in /
or use a different destination name if not. Same as curl
.
For customization, if you run bazel run --injection="trevor/" upload_custom
it would use make variable replacement to upload to https://test.case/directory/trevor/fixture
.
Is src
is a dir, we could just not support that, curl
itself doesn't support directories (it can do multiple files but you have to give the file and url for each one). Or we could loop through the files and upload each one. In that case we'd have to ensure that the url ends in /
. Obviously this has the limitation that only the original filenames can be used. Maybe that's ok?