Skip to content

Commit

Permalink
Improve release automation
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Frantz <[email protected]>
  • Loading branch information
cfrantz committed Jun 29, 2022
1 parent ce7249b commit 6f79306
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ release(
"@mxe_src//:mxe-binaries": "MXE mingw64 compiler",
"@qemu_src//:qemu-binaries": "QEMU system emulator",
},
env = {
"BASE_URL": "https://github.com/cfrantz/crt",
},
script = """(
cd "${BUILD_WORKSPACE_DIRECTORY}"
envsubst \
# Apparently envsubst can't handle bash arrays or dicts.
SHA256=${DIGEST[mxe-binaries.tar.xz]} envsubst \
<toolchains/gcc_mxe_mingw64/repository.bzl.template \
>toolchains/gcc_mxe_mingw64/repository.bzl
# Apparently envsubst can't handle bash arrays or dicts.
SHA256=${DIGEST[qemu-binaries.tar.xz]} envsubst \
<third_party/qemu/repos.bzl.template \
>third_party/qemu/repos.bzl
Expand Down
1 change: 1 addition & 0 deletions third_party/github/release.template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ARTIFACTS=(@@ARTIFACTS@@)
FILES=(@@FILES@@)
GH=@@GH@@
REMOTE="@@REMOTE@@"
@@ENV@@

BRANCH=$(cd "$BUILD_WORKSPACE_DIRECTORY" && git branch --show-current)
RELEASE_TAG=$(cd "$BUILD_WORKSPACE_DIRECTORY" && git describe --abbrev=0 --tags)
Expand Down
5 changes: 5 additions & 0 deletions third_party/github/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ def _release_impl(ctx):
runfiles.extend(files)
artifacts.append("'{}#{}'".format(files[0].short_path, v))

env = "\n".join(["export {}=\"{}\"".format(k, v) for k, v in ctx.attr.env.items()])
runner = ctx.actions.declare_file(ctx.label.name + ".bash")
ctx.actions.expand_template(
template = ctx.file._runner,
output = runner,
is_executable = True,
substitutions = {
"@@ARTIFACTS@@": " ".join(artifacts),
"@@ENV@@": env,
"@@FILES@@": " ".join([f.short_path for f in runfiles]),
"@@REMOTE@@": ctx.attr.remote,
"@@SCRIPT@@": ctx.attr.script,
Expand Down Expand Up @@ -42,6 +44,9 @@ release = rule(
"script": attr.string(
doc = "Script operation to perform before the github release operation",
),
"env": attr.string_dict(
doc = "Additional environment variables for the script",
),
"_gh": attr.label(
default = "@com_github_gh//:gh",
cfg = "exec",
Expand Down
4 changes: 1 addition & 3 deletions third_party/qemu/repos.bzl.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def qemu_src_repos():
def qemu_binary_repos():
http_archive(
name = "qemu",
urls = [
"https://github.com/cfrantz/crt/releases/download/${RELEASE_TAG}/qemu-binaries.tar.xz",
],
url = "${BASE_URL}/releases/download/${RELEASE_TAG}/qemu-binaries.tar.xz",
sha256 = "${SHA256}",
build_file = Label("//third_party/qemu:BUILD.qemu.bazel"),
strip_prefix = "qemu",
Expand Down
3 changes: 2 additions & 1 deletion toolchains/gcc_mxe_mingw64/repository.bzl.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@crt//config:repo.bzl", "compiler_repository")
def gcc_mxe_mingw64_repos():
compiler_repository(
name = "gcc_mxe_mingw64_files",
url = "https://github.com/cfrantz/crt/releases/download/${RELEASE_TAG}/mxe-binaries.tar.xz",
url = "${BASE_URL}/releases/download/${RELEASE_TAG}/mxe-binaries.tar.xz",
sha256 = "${SHA256}",
strip_prefix = "mxe",
)

0 comments on commit 6f79306

Please sign in to comment.