Skip to content

Commit

Permalink
chore: add Aspect Workflows (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Sep 7, 2024
1 parent 5df456b commit 48d1a45
Show file tree
Hide file tree
Showing 24 changed files with 843 additions and 110 deletions.
6 changes: 6 additions & 0 deletions .aspect/cli/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
configure:
languages:
javascript: true
go: false
kotlin: false
protobuf: false
13 changes: 13 additions & 0 deletions .aspect/workflows/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(["config.yaml"])

bzl_library(
name = "deps",
srcs = ["deps.bzl"],
visibility = ["//visibility:public"],
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)
18 changes: 18 additions & 0 deletions .aspect/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Aspect Workflows demonstration deployment

This deployment of [Aspect Workflows](https://www.aspect.build/workflows) is configured to run on GCP + CircleCI.

You can see this Aspect Workflows demonstration deployment live at https://app.circleci.com/pipelines/github/aspect-build/rules_terser.

The two components of the configuration in this repository are,

1. Aspect Workflows configuration yaml
1. CircleCI pipeline configuration

## Aspect Workflows configuration yaml

This is the [config.yaml](./config.yaml) file in this directory.

## CircleCI pipeline configuration

This is the [.circleci/config.yml](../../.circleci/config.yml) file.
10 changes: 10 additions & 0 deletions .aspect/workflows/bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# build without the bytes
common --remote_download_outputs=minimal
common --nobuild_runfile_links

common:rbe --extra_execution_platforms=@aspect_bazel_lib//platforms:x86_64_linux_remote
common:rbe --host_platform=@aspect_bazel_lib//platforms:x86_64_linux_remote
common:rbe --remote_executor=unix:///mnt/ephemeral/buildbarn/.cache/bb_clientd/grpc
common:rbe --genrule_strategy=remote,local
common:rbe --jobs=32
common:rbe --remote_timeout=3600
55 changes: 55 additions & 0 deletions .aspect/workflows/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
queue: oss-gcp-default
bazel:
flags:
- --config=rbe
workspaces:
.:
tasks:
- test:
targets:
- //...
- configure:
bazel:
flags: [] # TODO: Aspect CLI does not support --config for configure cmd
e2e/smoke:
icon: bazel
tasks:
- test:
queue: oss-gcp-small
- format:
without: true
- gazelle:
without: true
- configure:
without: true
- buildifier:
without: true
- delivery:
without: true
tasks:
- test:
- format:
queue: oss-gcp-small
- gazelle:
queue: oss-gcp-small
- configure:
queue: oss-gcp-small
- buildifier:
queue: oss-gcp-small
- delivery:
auto_deliver: true
rules:
- deliverable: 'attr("tags", "\bdeliverable\b", //...)'
condition:
branches:
- main
- deliverable:
- //docs:docs_delivery
condition:
only_on_change: false
branches:
- main
- warming:
queue: oss-gcp-warming
notifications:
github: {}
48 changes: 48 additions & 0 deletions .aspect/workflows/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Bazel dependencies for Aspect Workflows"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive", _http_file = "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

# TODO: move this to a rule set so repositories on Aspect Workflows can avoid this boilerplate
rosetta_version = "5.11.0-rc0"
rosetta_integrity = {
"darwin_aarch64": "sha256-poZcgwCiCQ+d4gGqT8uSLD+Lw+hHvgFco0HkRKWb/JE=",
"darwin_x86_64": "sha256-knu8ztUUCdn6wpCvEKntuuEVN0rI5jyC5h0VeR4WsbQ=",
"linux_aarch64": "sha256-M/cL1Tb38gUYYVMefSGNbyxtWdRuLQ9t+bKQnzp+kL4=",
"linux_x86_64": "sha256-LzMQGU5SzzGmnAaJjvSogjTl5PWXnTG8v9dHDRnEe8Q=",
}

# https://github.com/suzuki-shunsuke/circleci-config-merge/releases
# https://dev.to/suzukishunsuke/splitting-circleci-config-yml-10gk
circleci_config_merge_version = "1.1.6"
circleci_config_merge_integrity = {
"darwin_aarch64": "sha256-7cQeLrSVRZR+mQu/njn+x//EIb2bhTV2+J8fafRHpr4=",
"darwin_x86_64": "sha256-vHKDSdDaYK58MaudJ9yOPRKh+OT/LiTQV/9E07RL8qA=",
"linux_aarch64": "sha256-MaXVQmRK9q9LgsfM5ZzxCIIT8rUcOBbzJ8aVDgK6zWs=",
"linux_x86_64": "sha256-3eYJn7dShZD1oiS3cgXfqXwdDzclf/N97A2nh7ZfW+w=",
}

def http_archive(name, **kwargs):
maybe(_http_archive, name = name, **kwargs)

def http_file(name, **kwargs):
maybe(_http_file, name = name, **kwargs)

# buildifier: disable=function-docstring
def fetch_workflows_deps():
for platform_arch in rosetta_integrity.keys():
http_file(
name = "rosetta_{}".format(platform_arch),
downloaded_file_path = "rosetta",
executable = True,
# integrity = rosetta_integrity[platform_arch],
urls = ["https://static.aspect.build/aspect/{0}/rosetta_real_{1}".format(rosetta_version, platform_arch.replace("aarch64", "arm64"))],
)

for platform_arch in circleci_config_merge_integrity.keys():
http_archive(
name = "circleci_config_merge_{}".format(platform_arch),
build_file_content = "exports_files([\"circleci-config-merge\"])",
integrity = circleci_config_merge_integrity[platform_arch],
urls = ["https://github.com/suzuki-shunsuke/circleci-config-merge/releases/download/v{0}/circleci-config-merge_{0}_{1}.tar.gz".format(circleci_config_merge_version, platform_arch.replace("aarch64", "arm64").replace("x86_64", "amd64"))],
)
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.1.1
7.3.1
61 changes: 61 additions & 0 deletions .circleci/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")

CIRCLECI_ORG = "aspect-build"

CIRCLECI_USER_CONFIG_FILE = "//.circleci:user-config.yml"

not_windows = select({
# There isn't a published rosetta binary for windows as of Feb 2024
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
})

alias(
name = "rosetta",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": "@rosetta_darwin_aarch64//file:rosetta",
"@bazel_tools//src/conditions:darwin_x86_64": "@rosetta_darwin_x86_64//file:rosetta",
"@bazel_tools//src/conditions:linux_aarch64": "@rosetta_linux_aarch64//file:rosetta",
"@bazel_tools//src/conditions:linux_x86_64": "@rosetta_linux_x86_64//file:rosetta",
}),
target_compatible_with = not_windows,
)

alias(
name = "circleci-config-merge",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": "@circleci_config_merge_darwin_aarch64//:circleci-config-merge",
"@bazel_tools//src/conditions:darwin_x86_64": "@circleci_config_merge_darwin_x86_64//:circleci-config-merge",
"@bazel_tools//src/conditions:linux_aarch64": "@circleci_config_merge_linux_aarch64//:circleci-config-merge",
"@bazel_tools//src/conditions:linux_x86_64": "@circleci_config_merge_linux_x86_64//:circleci-config-merge",
}),
target_compatible_with = not_windows,
)

genrule(
name = "aspect_workflows_config",
srcs = ["//.aspect/workflows:config.yaml"],
outs = [":aspect-workflows-config.yml"],
cmd = "CI=1 CIRCLE_PROJECT_USERNAME={0} $(execpath :rosetta) steps --configuration .aspect/workflows/config.yaml --host circleci > $@".format(CIRCLECI_ORG),
target_compatible_with = not_windows,
tools = [":rosetta"],
)

genrule(
name = "merge_config",
srcs = [
":aspect-workflows-config.yml",
CIRCLECI_USER_CONFIG_FILE,
],
outs = [":_config.yml"],
cmd = "echo -e '# GENERATED FILE - DO NOT EDIT!\\n# Update with: bazel run //.circleci:write_merged_config' > $@ && $(execpath :circleci-config-merge) merge $(execpath :aspect-workflows-config.yml) $(execpath {0}) >> $@".format(CIRCLECI_USER_CONFIG_FILE),
target_compatible_with = not_windows,
tools = [":circleci-config-merge"],
)

write_source_file(
name = "write_merged_config",
in_file = ":_config.yml",
out_file = "config.yml",
target_compatible_with = not_windows,
)
Loading

0 comments on commit 48d1a45

Please sign in to comment.