Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/rules_curl
1 result
Show changes
Commits on Source (4)
# [1.0.0-alpha.3](https://git.gitlab.arm.com/bazel/rules_curl/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2024-01-29)
### Features
- replace `curl_upload` with `curl_upload_file` ([088c891](https://git.gitlab.arm.com/bazel/rules_curl/commit/088c891619375d4d26cc1dddc618308fcdccb570))
### BREAKING CHANGES
- `curl_upload` is removed, long live `curl_upload_file`.
We hope to add `curl_upload` back in to allow uploads of multiple files.
There are complexities due to the correct mapping of filepaths.
It may be that packaging multiple files into a archive with `rules_pkg`
and then uploading that archive is a better way forward anyway.
# [1.0.0-alpha.2](https://git.gitlab.arm.com/bazel/rules_curl/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2024-01-12)
### Bug Fixes
......
module(
name = "rules_curl",
version = "1.0.0-alpha.2",
version = "1.0.0-alpha.3",
bazel_compatibility = [
">=7.0.0",
],
......
load(":rule.bzl", _upload = "upload")
visibility("public")
curl_upload = _upload
......@@ -10,7 +10,7 @@ alias(
"@rules_toolchain//toolchain/constraint/os:windows": ":nt.tmpl.bat",
"//conditions:default": ":posix.tmpl.sh",
},
no_match_error = "No script template available for `curl_upload`",
no_match_error = "No script template available for `curl_upload_file`",
),
visibility = ["//visibility:public"],
)
load(":rule.bzl", _file = "file")
visibility("public")
curl_upload_file = _file
File moved
......@@ -5,11 +5,12 @@ set -o errexit -o nounset
# Bazel substitutions
CURL="{{curl}}"
SRCS="{{srcs}}"
SRC="{{src}}"
DST="{{dst}}"
URL="{{url}}"
RETRY="{{retry}}"
RETRY_DELAY="{{retry_delay}}"
readonly CURL SRCS URL RETRY RETRY_DELAY
readonly CURL SRC DST URL RETRY RETRY_DELAY
# Runfiles
RUNFILES_DIR="${RUNFILES_DIR-${0}.runfiles}"
......@@ -48,17 +49,14 @@ while test 0 -ne "${#}"; do
done
readonly ENDPOINT
printf "%s\n" "${SRCS}" |
while IFS= read -r SRC; do
printf >&2 "Uploading: %s\n" "${SRC}"
printf >&2 "Uploading: %s to %s\n" "${SRC}" "${ENDPOINT}/${DST}"
# Do the upload
"${RUNFILES}/${CURL}" \
--netrc \
--location \
--progress-bar \
--retry "${RETRY}" \
--retry-delay "${RETRY_DELAY}" \
--upload-file "${RUNFILES}/${SRC}" \
"${ENDPOINT}/${SRC}"
done
# Do the upload
"${RUNFILES}/${CURL}" \
--netrc \
--location \
--progress-bar \
--retry "${RETRY}" \
--retry-delay "${RETRY_DELAY}" \
--upload-file "${RUNFILES}/${SRC}" \
"${ENDPOINT}/${DST}"
visibility("//curl/...")
DOC = """Uploads files to a URL endpoint with cURL.
DOC = """Upload a file to a URL endpoint with cURL.
```py
upload(
name = "upload",
srcs = [
":data"
],
file(
name = "upload_file",
src = ":data",
dst = "data"
url = "https://host.name.to.upload",
)
```
"""
ATTRS = {
"srcs": attr.label_list(
doc = "Files to be uploaded.",
"src": attr.label(
doc = "File to be uploaded.",
mandatory = True,
allow_single_file = True,
),
"dst": attr.string(
doc = "The filename to upload as.",
mandatory = True,
allow_files = True,
),
"url": attr.string(
doc = "URL endpoint for file uploads.",
doc = "URL endpoint for file upload.",
mandatory = True,
),
"retry": attr.int(
......@@ -38,9 +41,6 @@ ATTRS = {
),
}
def _map(x):
return x.short_path
def implementation(ctx):
curl = ctx.toolchains["//curl/toolchain/cli:type"]
......@@ -51,7 +51,8 @@ def implementation(ctx):
substitutions.add("{{url}}", ctx.attr.url.rstrip("/"))
substitutions.add("{{retry}}", str(ctx.attr.retry))
substitutions.add("{{retry_delay}}", str(ctx.attr.retry_delay))
substitutions.add_joined("{{srcs}}", depset(ctx.files.srcs), join_with = "\n", map_each = _map)
substitutions.add("{{src}}", str(ctx.file.src.short_path))
substitutions.add("{{dst}}", str(ctx.attr.dst))
ctx.actions.expand_template(
template = ctx.file.template,
......@@ -61,7 +62,7 @@ def implementation(ctx):
)
files = depset([executable])
runfiles = ctx.runfiles([curl.executable] + ctx.files.srcs)
runfiles = ctx.runfiles([curl.executable] + ctx.files.src)
return DefaultInfo(
executable = executable,
......@@ -69,7 +70,7 @@ def implementation(ctx):
runfiles = runfiles,
)
upload = rule(
file = rule(
doc = DOC,
attrs = ATTRS,
implementation = implementation,
......
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@rules_curl//curl/upload:defs.bzl", "curl_upload")
load("@rules_curl//curl/upload/file:defs.bzl", "curl_upload_file")
curl_upload(
curl_upload_file(
name = "upload",
testonly = True,
srcs = [
":fixture.txt",
],
src = ":fixture.txt",
dst = "directory/fixture.txt",
url = "https://test.case",
)
......
......@@ -7,4 +7,4 @@
1
--upload-file
fixture.txt
https://test.case/upload/fixture.txt
https://test.case/directory/fixture.txt
{
"name": "rules_download",
"name": "rules_curl",
"lockfileVersion": 3,
"requires": true,
"packages": {
......