Skip to content

Commit 41a6aaf

Browse files
committed
chore: add Aspect Workflows CircleCI configuration
1 parent 6749298 commit 41a6aaf

File tree

6 files changed

+353
-1
lines changed

6 files changed

+353
-1
lines changed

.aspect/workflows/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports_files(["config.yaml"])

.aspect/workflows/deps.bzl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Bazel dependencies for Aspect Workflows"""
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive", _http_file = "http_file")
4+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5+
6+
# TODO: move this to a rule set so repositories on Aspect Workflows can avoid this boilerplate
7+
rosetta_version = "5.11.0"
8+
rosetta_integrity = {
9+
"darwin_aarch64": "sha256-zmWdxspunpc9Sz5iZOow0FotE66EGe6WFeHk5+vwMJ8=",
10+
"darwin_x86_64": "sha256-5V6SxvL3QYWbBE/GuwP1ReJwpe0zkznb+j8n4V36O+E=",
11+
"linux_aarch64": "sha256-qwscEgk9kdMnNZ9df+Cw8aPo1ZokIHViS6+6nCSsfSU=",
12+
"linux_x86_64": "sha256-WgDaxOssma7zDHGh+iZ4p3MyBvIBk6m138ZWzR44g2Q=",
13+
}
14+
15+
# https://github.com/suzuki-shunsuke/circleci-config-merge/releases
16+
# https://dev.to/suzukishunsuke/splitting-circleci-config-yml-10gk
17+
circleci_config_merge_version = "1.1.6"
18+
circleci_config_merge_integrity = {
19+
"darwin_aarch64": "sha256-7cQeLrSVRZR+mQu/njn+x//EIb2bhTV2+J8fafRHpr4=",
20+
"darwin_x86_64": "sha256-vHKDSdDaYK58MaudJ9yOPRKh+OT/LiTQV/9E07RL8qA=",
21+
"linux_aarch64": "sha256-MaXVQmRK9q9LgsfM5ZzxCIIT8rUcOBbzJ8aVDgK6zWs=",
22+
"linux_x86_64": "sha256-3eYJn7dShZD1oiS3cgXfqXwdDzclf/N97A2nh7ZfW+w=",
23+
}
24+
25+
def http_archive(name, **kwargs):
26+
maybe(_http_archive, name = name, **kwargs)
27+
28+
def http_file(name, **kwargs):
29+
maybe(_http_file, name = name, **kwargs)
30+
31+
# buildifier: disable=function-docstring
32+
def fetch_workflows_deps():
33+
for platform_arch in rosetta_integrity.keys():
34+
http_file(
35+
name = "rosetta_{}".format(platform_arch),
36+
downloaded_file_path = "rosetta",
37+
executable = True,
38+
integrity = rosetta_integrity[platform_arch],
39+
urls = ["https://static.aspect.build/aspect/{0}/rosetta_real_{1}".format(rosetta_version, platform_arch.replace("aarch64", "arm64"))],
40+
)
41+
42+
for platform_arch in circleci_config_merge_integrity.keys():
43+
http_archive(
44+
name = "circleci_config_merge_{}".format(platform_arch),
45+
build_file_content = "exports_files([\"circleci-config-merge\"])",
46+
integrity = circleci_config_merge_integrity[platform_arch],
47+
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"))],
48+
)

.circleci/BUILD.bazel

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
2+
3+
CIRCLECI_ORG = "aspect-build"
4+
5+
CIRCLECI_USER_CONFIG_FILE = "//.circleci:user-config.yml"
6+
7+
alias(
8+
name = "rosetta",
9+
actual = select({
10+
"@bazel_tools//src/conditions:darwin_arm64": "@rosetta_darwin_aarch64//file:rosetta",
11+
"@bazel_tools//src/conditions:darwin_x86_64": "@rosetta_darwin_x86_64//file:rosetta",
12+
"@bazel_tools//src/conditions:linux_aarch64": "@rosetta_linux_aarch64//file:rosetta",
13+
"@bazel_tools//src/conditions:linux_x86_64": "@rosetta_linux_x86_64//file:rosetta",
14+
}),
15+
)
16+
17+
alias(
18+
name = "circleci-config-merge",
19+
actual = select({
20+
"@bazel_tools//src/conditions:darwin_arm64": "@circleci_config_merge_darwin_aarch64//:circleci-config-merge",
21+
"@bazel_tools//src/conditions:darwin_x86_64": "@circleci_config_merge_darwin_x86_64//:circleci-config-merge",
22+
"@bazel_tools//src/conditions:linux_aarch64": "@circleci_config_merge_linux_aarch64//:circleci-config-merge",
23+
"@bazel_tools//src/conditions:linux_x86_64": "@circleci_config_merge_linux_x86_64//:circleci-config-merge",
24+
}),
25+
)
26+
27+
genrule(
28+
name = "aspect_workflows_config",
29+
srcs = ["//.aspect/workflows:config.yaml"],
30+
outs = [":aspect-workflows-config.yml"],
31+
cmd = "CI=1 CIRCLE_PROJECT_USERNAME={0} ASPECT_WORKFLOWS_DISABLE_TRACES_COLLECTION=1 $(execpath :rosetta) steps --configuration .aspect/workflows/config.yaml --host circleci > $@".format(CIRCLECI_ORG),
32+
tools = [":rosetta"],
33+
)
34+
35+
genrule(
36+
name = "merge_config",
37+
srcs = [
38+
":aspect-workflows-config.yml",
39+
CIRCLECI_USER_CONFIG_FILE,
40+
],
41+
outs = [":_config.yml"],
42+
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),
43+
tools = [":circleci-config-merge"],
44+
)
45+
46+
write_source_file(
47+
name = "write_merged_config",
48+
in_file = ":_config.yml",
49+
out_file = "config.yml",
50+
)

.circleci/config.yml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# GENERATED FILE - DO NOT EDIT!
2+
# Update with: bazel run //.circleci:write_merged_config
3+
version: 2.1
4+
workflows:
5+
aspect-workflows:
6+
jobs:
7+
- aw-format:
8+
context: []
9+
workspace: .
10+
- aw-lint:
11+
context: []
12+
workspace: .
13+
- aw-test:
14+
context: []
15+
workspace: .
16+
when:
17+
not:
18+
equal:
19+
- scheduled_pipeline
20+
- << pipeline.trigger_source >>
21+
aspect-workflows-warming:
22+
jobs:
23+
- aw-warming: {}
24+
when:
25+
and:
26+
- equal:
27+
- scheduled_pipeline
28+
- << pipeline.trigger_source >>
29+
- equal:
30+
- aspect-workflows-warming
31+
- << pipeline.schedule.name >>
32+
user-workflow:
33+
jobs:
34+
- user-job
35+
when:
36+
and:
37+
- not:
38+
equal:
39+
- << pipeline.trigger_source >>
40+
- scheduled_pipeline
41+
jobs:
42+
aw-format:
43+
environment:
44+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_NUMBER: << pipeline.number >>
45+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_PROJECT_TYPE: << pipeline.project.type >>
46+
ASPECT_WORKFLOWS_CIRCLE_WORKFLOW_BASE_NAME: aspect-workflows
47+
ASPECT_WORKFLOWS_CONFIG: .aspect/workflows/config.yaml
48+
ASPECT_WORKFLOWS_WORKSPACE: << parameters.workspace >>
49+
XDG_CACHE_HOME: /mnt/ephemeral/caches
50+
machine: true
51+
parameters:
52+
workspace:
53+
type: string
54+
resource_class: aspect-build/aspect-default
55+
steps:
56+
- run:
57+
command: /etc/aspect/workflows/bin/configure_workflows_env
58+
name: Workflows environment
59+
- checkout
60+
- run:
61+
command: rm -rf /workflows/artifacts /workflows/testlogs
62+
name: Prepare archive directories
63+
- run:
64+
command: /etc/aspect/workflows/bin/agent_health_check
65+
name: Agent health check
66+
no_output_timeout: 180m
67+
- run:
68+
command: rosetta run checkout
69+
name: Checkout health
70+
no_output_timeout: 180m
71+
- run:
72+
command: rosetta run format --workspace << parameters.workspace >>
73+
name: Format
74+
no_output_timeout: 180m
75+
- store_artifacts:
76+
path: /workflows/artifacts
77+
- run:
78+
command: rosetta run finalization
79+
name: Finalization
80+
no_output_timeout: 10m
81+
when: always
82+
working_directory: /mnt/ephemeral/workdir
83+
aw-lint:
84+
environment:
85+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_NUMBER: << pipeline.number >>
86+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_PROJECT_TYPE: << pipeline.project.type >>
87+
ASPECT_WORKFLOWS_CIRCLE_WORKFLOW_BASE_NAME: aspect-workflows
88+
ASPECT_WORKFLOWS_CONFIG: .aspect/workflows/config.yaml
89+
ASPECT_WORKFLOWS_WORKSPACE: << parameters.workspace >>
90+
XDG_CACHE_HOME: /mnt/ephemeral/caches
91+
machine: true
92+
parameters:
93+
workspace:
94+
type: string
95+
resource_class: aspect-build/aspect-default
96+
steps:
97+
- run:
98+
command: /etc/aspect/workflows/bin/configure_workflows_env
99+
name: Workflows environment
100+
- checkout
101+
- run:
102+
command: rm -rf /workflows/artifacts /workflows/testlogs
103+
name: Prepare archive directories
104+
- run:
105+
command: /etc/aspect/workflows/bin/agent_health_check
106+
name: Agent health check
107+
no_output_timeout: 180m
108+
- run:
109+
command: rosetta run checkout
110+
name: Checkout health
111+
no_output_timeout: 180m
112+
- run:
113+
command: rosetta run lint --workspace << parameters.workspace >>
114+
name: Lint
115+
no_output_timeout: 180m
116+
- store_artifacts:
117+
path: /workflows/artifacts
118+
- run:
119+
command: rosetta run finalization
120+
name: Finalization
121+
no_output_timeout: 10m
122+
when: always
123+
working_directory: /mnt/ephemeral/workdir
124+
aw-test:
125+
environment:
126+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_NUMBER: << pipeline.number >>
127+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_PROJECT_TYPE: << pipeline.project.type >>
128+
ASPECT_WORKFLOWS_CIRCLE_WORKFLOW_BASE_NAME: aspect-workflows
129+
ASPECT_WORKFLOWS_CONFIG: .aspect/workflows/config.yaml
130+
ASPECT_WORKFLOWS_WORKSPACE: << parameters.workspace >>
131+
XDG_CACHE_HOME: /mnt/ephemeral/caches
132+
machine: true
133+
parameters:
134+
workspace:
135+
type: string
136+
resource_class: aspect-build/aspect-default
137+
steps:
138+
- run:
139+
command: /etc/aspect/workflows/bin/configure_workflows_env
140+
name: Workflows environment
141+
- checkout
142+
- run:
143+
command: rm -rf /workflows/artifacts /workflows/testlogs
144+
name: Prepare archive directories
145+
- run:
146+
command: /etc/aspect/workflows/bin/agent_health_check
147+
name: Agent health check
148+
no_output_timeout: 180m
149+
- run:
150+
command: rosetta run checkout
151+
name: Checkout health
152+
no_output_timeout: 180m
153+
- run:
154+
command: rosetta run test --workspace << parameters.workspace >>
155+
name: Test
156+
no_output_timeout: 180m
157+
- store_test_results:
158+
path: /workflows/testlogs
159+
- store_artifacts:
160+
path: /workflows/testlogs
161+
- store_artifacts:
162+
path: /workflows/artifacts
163+
- run:
164+
command: rosetta run finalization
165+
name: Finalization
166+
no_output_timeout: 10m
167+
when: always
168+
working_directory: /mnt/ephemeral/workdir
169+
aw-warming:
170+
environment:
171+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_NUMBER: << pipeline.number >>
172+
ASPECT_WORKFLOWS_CIRCLE_PIPELINE_PROJECT_TYPE: << pipeline.project.type >>
173+
ASPECT_WORKFLOWS_CIRCLE_WORKFLOW_BASE_NAME: aspect-workflows
174+
ASPECT_WORKFLOWS_CONFIG: .aspect/workflows/config.yaml
175+
XDG_CACHE_HOME: /mnt/ephemeral/caches
176+
machine: true
177+
resource_class: aspect-build/aspect-warming
178+
steps:
179+
- run:
180+
command: /etc/aspect/workflows/bin/configure_workflows_env
181+
name: Workflows environment
182+
- checkout
183+
- run:
184+
command: /etc/aspect/workflows/bin/agent_health_check
185+
name: Agent health check
186+
no_output_timeout: 180m
187+
- run:
188+
command: rosetta run warming --workspace .
189+
name: Create warming archive for root
190+
no_output_timeout: 180m
191+
- run:
192+
command: /etc/aspect/workflows/bin/warming_archive
193+
name: Archive warming tars
194+
working_directory: /mnt/ephemeral/workdir
195+
user-job:
196+
docker:
197+
- image: cimg/base:2023.03
198+
steps:
199+
- checkout
200+
- run: echo "Example user CircleCI job that is not generated by Aspect Workflows."

.circleci/user-config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This is an example of a user CircleCI configuration that is not generated by
2+
# Aspect Workflows. The naming of this file is arbitrary. This configuration is
3+
# merged with the generated Aspect Workflows CircleCI configuration into the
4+
# load bearing load `.circleci/config.yaml` configuration file that is used by
5+
# CircleCI.
6+
#
7+
# To update `.circleci/config.yaml` after editing this file run:
8+
#
9+
# bazel run //.circleci:write_merged_config
10+
#
11+
#
12+
# Aspect Workflows workflow names are all prefixed with "aspect-workflows-".
13+
# These currently include:
14+
#
15+
# - aspect-workflows
16+
# - aspect-workflows-warming
17+
# - aspect-workflows-manual-deliver
18+
#
19+
# Aspect Workflows job names are all prefixed with "aw-". These currently
20+
# include.
21+
#
22+
# - aw-auto-deliver
23+
# - aw-buildifier
24+
# - aw-configure
25+
# - aw-format
26+
# - aw-gazelle
27+
# - aw-manual-deliver
28+
# - aw-test
29+
# - aw-warming
30+
#
31+
# In your user CircleCI configuration, avoid workflow names prefixed with
32+
# `aspect-workflows-` and job names prefixed with `aw-`. Conflicting workflow or
33+
# job names will result in a bad configuration merge.
34+
version: 2.1
35+
jobs:
36+
user-job:
37+
docker:
38+
- image: cimg/base:2023.03
39+
steps:
40+
- checkout
41+
- run: echo "Example user CircleCI job that is not generated by Aspect Workflows."
42+
workflows:
43+
user-workflow:
44+
jobs:
45+
- user-job
46+
when:
47+
and:
48+
- not:
49+
equal:
50+
- << pipeline.trigger_source >>
51+
- scheduled_pipeline

WORKSPACE.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# Workaround https://github.com/bazelbuild/bazel-watcher/pull/647
1+
load("//.aspect/workflows:deps.bzl", "fetch_workflows_deps")
2+
3+
fetch_workflows_deps()

0 commit comments

Comments
 (0)