Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix-visibility release artifacts #67

Merged
merged 4 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ jobs:
run: git status --porcelain
- name: bazel test //...
env:
# Bazelisk will download bazel to here
# Bazelisk will download bazel to here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we don't actually have to download bazelisk!
bazel-contrib/rules_bazel_integration_test#1 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will defer this to another PR.

XDG_CACHE_HOME: ~/.cache/bazel-repo
run:
run: |
# Test the repository.
bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test
--config=release //...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we don't want to test with --config=release since that causes some cache misses due to stamping non-determinism?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could argue that we don't need a test at all since we will only tag commits on main that were already tested.

# Copy the release artifacts to /tmp/aspect/release.
rm -rf /tmp/aspect/release
bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc run
--config=release //release -- /tmp/aspect/release
- name: Release
uses: softprops/action-gh-release@v1
with:
prerelease: true
files: |
bazel-out/*-opt-*/bin/cmd/aspect/aspect-linux_amd64
bazel-out/*-opt-*/bin/cmd/aspect/aspect-linux_arm64
bazel-out/*-opt-*/bin/cmd/aspect/aspect-darwin_amd64
bazel-out/*-opt-*/bin/cmd/aspect/aspect-darwin_arm64
bazel-out/*-opt-*/bin/cmd/aspect/aspect-windows_amd64.exe
files: /tmp/aspect/release/*
85 changes: 4 additions & 81 deletions cmd/aspect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ go_library(
name = "aspect_lib",
srcs = ["main.go"],
importpath = "aspect.build/cli/cmd/aspect",
visibility = ["//cmd:__subpackages__"],
visibility = [
"//cmd:__subpackages__",
"//release:__pkg__",
],
deps = [
"//cmd/aspect/root",
"//pkg/aspecterrors",
Expand All @@ -16,83 +19,3 @@ go_binary(
embed = [":aspect_lib"],
visibility = ["//visibility:public"],
)

go_binary(
name = "aspect-darwin-amd64",
out = "aspect-darwin_amd64",
embed = [":aspect_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "amd64",
goos = "darwin",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "aspect-darwin-arm64",
out = "aspect-darwin_arm64",
embed = [":aspect_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "arm64",
goos = "darwin",
pure = "on",
visibility = ["//visibility:public"],
)

# genrule(
# name = "aspect-darwin-universal",
# srcs = [
# ":aspect-darwin_amd64",
# ":aspect-darwin_arm64",
# ],
# outs = ["aspect-darwin_universal"],
# cmd = "lipo -create -output \"$@\" $(SRCS)",
# output_to_bindir = 1,
# target_compatible_with = [
# "@platforms//os:macos",
# ],
# )

go_binary(
name = "aspect-linux-amd64",
out = "aspect-linux_amd64",
embed = [":aspect_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "amd64",
goos = "linux",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "aspect-linux-arm64",
out = "aspect-linux_arm64",
embed = [":aspect_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "arm64",
goos = "linux",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "aspect-windows-amd64",
out = "aspect-windows_amd64.exe",
embed = [":aspect_lib"],
goarch = "amd64",
goos = "windows",
pure = "on",
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion plugins/fix-visibility/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go_library(
name = "fix-visibility_lib",
srcs = ["plugin.go"],
importpath = "aspect.build/cli/plugins/fix-visibility",
visibility = ["//visibility:private"],
visibility = ["//release:__pkg__"],
deps = [
"//pkg/ioutils",
"//pkg/plugin/sdk/v1alpha1/config",
Expand Down
20 changes: 20 additions & 0 deletions release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load(":release.bzl", "multi_platform_binaries", "release")

multi_platform_binaries(
name = "aspect",
embed = ["//cmd/aspect:aspect_lib"],
)

multi_platform_binaries(
name = "fix-visibility",
embed = ["//plugins/fix-visibility:fix-visibility_lib"],
prefix = "plugin-",
)

release(
name = "release",
targets = [
":aspect",
":fix-visibility",
],
)
15 changes: 15 additions & 0 deletions release/create_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -o errexit -o nounset -o pipefail

echo '#!/bin/bash'
echo 'set -o errexit -o nounset -o pipefail'
# shellcheck disable=SC2016
echo 'dst=$1'
# shellcheck disable=SC2016
echo 'mkdir -p "${dst}"'

for artifact in "$@"; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, don't need $BUILD_WORKSPACE_DIRECTORY to hop back to source tree? I guess this binary has no runfiles so a different working dir

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the files are passed from $(locations ...) MAKEVARS from Bazel.

echo "echo \"Copying ${artifact} to \${dst}\""
echo "cp \"${artifact}\" \"\${dst}\""
done
63 changes: 63 additions & 0 deletions release/release.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""This module provides the macros for performing a release.
"""

load("@io_bazel_rules_go//go:def.bzl", "go_binary")

PLATFORMS = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rad

struct(os = "darwin", arch = "amd64", ext = "", gc_linkopts = ["-s", "-w"]),
struct(os = "darwin", arch = "arm64", ext = "", gc_linkopts = ["-s", "-w"]),
struct(os = "linux", arch = "amd64", ext = "", gc_linkopts = ["-s", "-w"]),
struct(os = "linux", arch = "arm64", ext = "", gc_linkopts = ["-s", "-w"]),
struct(os = "windows", arch = "amd64", ext = ".exe", gc_linkopts = []),
]

def multi_platform_binaries(name, embed, prefix = ""):
"""The multi_platform_binaries macro creates a go_binary for each platform.

Args:
name: the name of the filegroup containing all go_binary targets produced
by this macro.
embed: the list of targets passed to each go_binary target in this
macro.
prefix: an optional prefix added to the output Go binary file name.
"""
targets = []
for platform in PLATFORMS:
target_name = "{}-{}-{}".format(name, platform.os, platform.arch)
go_binary(
name = target_name,
out = "{}{}-{}_{}{}".format(prefix, name, platform.os, platform.arch, platform.ext),
embed = embed,
gc_linkopts = platform.gc_linkopts,
goarch = platform.arch,
goos = platform.os,
pure = "on",
visibility = ["//visibility:public"],
)
targets.append(Label("//{}:{}".format(native.package_name(), target_name)))

native.filegroup(
name = name,
srcs = targets,
)

def release(name, targets):
"""The release macro creates the artifact copier script.

It's an executable script that copies all artifacts produced by the given
targets into the provided destination. See .github/workflows/release.yml.

Args:
name: the name of the genrule.
targets: a list of filegroups passed to the artifact copier.
"""
native.genrule(
name = name,
srcs = targets,
outs = ["release.sh"],
executable = True,
cmd = "./$(location //release:create_release.sh) {locations} > \"$@\"".format(
locations = " ".join(["$(locations {})".format(target) for target in targets]),
),
tools = ["//release:create_release.sh"],
)