From 0abb391dda23e7be256412d1a255b2b515499f00 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 6 Feb 2024 03:30:45 -0800 Subject: [PATCH] chore: use rules_workflows for CircleCI config generation --- .aspect/workflows/deps.bzl | 48 --------------------------------- .circleci/BUILD.bazel | 54 +++++++------------------------------- .circleci/config.yml | 2 +- WORKSPACE | 15 +++++++++-- 4 files changed, 23 insertions(+), 96 deletions(-) delete mode 100644 .aspect/workflows/deps.bzl diff --git a/.aspect/workflows/deps.bzl b/.aspect/workflows/deps.bzl deleted file mode 100644 index 1da0bed83..000000000 --- a/.aspect/workflows/deps.bzl +++ /dev/null @@ -1,48 +0,0 @@ -"""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.9.2" -rosetta_integrity = { - "darwin_aarch64": "sha256-DT/DyJuykKDmgZ/hHqC1JF+iYnkK6PjCwi4cXH7JD4g=", - "darwin_x86_64": "sha256-j3LPtSVc56uBC3ZTTMtnECZmOTMlbz4MeGPu6mbTpEo=", - "linux_aarch64": "sha256-tlJF0qgR5RQ/9Q4F9O9y2K4nRLJg3V2D25xXxRJzAAY=", - "linux_x86_64": "sha256-RAQfYXWhisbdW2D5WzjirYmWjc0+Rpjqg2vtMKQy6rc=", -} - -# 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"))], - ) diff --git a/.circleci/BUILD.bazel b/.circleci/BUILD.bazel index ca7d1ed7c..fe50bd959 100644 --- a/.circleci/BUILD.bazel +++ b/.circleci/BUILD.bazel @@ -1,50 +1,14 @@ -load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file") +load("@aspect_rules_workflows//workflows:defs.bzl", "circleci_aspect_workflows_config", "circleci_merged_config") -CIRCLECI_ORG = "aspect-build" - -CIRCLECI_USER_CONFIG_FILE = "//.circleci:user-config.yml" - -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", - }), -) - -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", - }), +circleci_aspect_workflows_config( + name = "aspect-workflows-config", + circleci_org = "aspect-build", ) -genrule( - name = "aspect_workflows_config", - srcs = ["//.aspect/workflows:config.yaml"], - outs = [":aspect-workflows-config.yml"], - cmd = "CIRCLE_PROJECT_USERNAME={0} $(execpath :rosetta) steps --configuration .aspect/workflows/config.yaml --host circleci > $@".format(CIRCLECI_ORG), - tools = [":rosetta"], -) - -genrule( - name = "merge_config", - srcs = [ - ":aspect-workflows-config.yml", - CIRCLECI_USER_CONFIG_FILE, +circleci_merged_config( + name = "config", + circleci_config_files = [ + ":user-config.yml", + ":aspect-workflows-config", ], - 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), - tools = [":circleci-config-merge"], -) - -write_source_file( - name = "write_merged_config", - in_file = ":_config.yml", - out_file = "config.yml", ) diff --git a/.circleci/config.yml b/.circleci/config.yml index 952de8eae..cf9f74898 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,5 @@ # GENERATED FILE - DO NOT EDIT! -# Update with: bazel run //.circleci:write_merged_config +# Update with: bazel run //.circleci:config version: 2.1 workflows: aspect-workflows: diff --git a/WORKSPACE b/WORKSPACE index c6d1b02c8..55a502139 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -23,6 +23,13 @@ http_archive( url = "https://github.com/aspect-build/rules_lint/releases/download/v0.7.0/rules_lint-v0.7.0.tar.gz", ) +http_archive( + name = "aspect_rules_workflows", + sha256 = "43aa7ce5eb8fa8d8bae023bf8cda45353d5bfe5e4df9e4c331abacbca7b298eb", + strip_prefix = "rules_workflows-0.1.0", + url = "https://github.com/aspect-build/rules_workflows/releases/download/v0.1.0/rules_workflows-v0.1.0.tar.gz", +) + http_archive( name = "bazel_skylib", sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", @@ -253,6 +260,10 @@ fetch_shfmt() fetch_terraform() -load("//.aspect/workflows:deps.bzl", "fetch_workflows_deps") +load("@aspect_rules_workflows//workflows:dependencies.bzl", "rules_workflows_dependencies") + +rules_workflows_dependencies() + +load("@aspect_rules_workflows//workflows:repositories.bzl", "fetch_workflows_tools") -fetch_workflows_deps() +fetch_workflows_tools(workflows_version = "5.9.2")