Skip to content

Commit 6743be4

Browse files
authored
chore: add Aspect Workflows GitHub Actions configuration (#384)
1 parent 6749298 commit 6743be4

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# ==================================================================================================
2+
# Aspect Workflows Reusable Workflow for GitHub Actions (v5.12.0-alpha0.dev.68.g41b1e2f)
3+
#
4+
# https://github.com/marketplace/actions/aspect-workflows?version=5.12.0-alpha0.dev.68.g41b1e2f
5+
#
6+
# At this time, GitHub Actions does not allow referencing reusable workflows from public
7+
# repositories in other organizations. See
8+
# https://docs.github.com/en/actions/using-workflows/reusing-workflows#access-to-reusable-workflows
9+
# for more info.
10+
#
11+
# Use the Aspect Workflows Reusable Workflow with GitHub Actions by doing one of the following:
12+
#
13+
# 1. Vendor this file into the `.github/workflows` folder of your repository and reference it with
14+
# `uses:` in a workflow file such as `.github/workflows/aspect-workflows.yaml`:
15+
#
16+
# ```
17+
# name: Aspect Workflows
18+
#
19+
# on:
20+
# push:
21+
# branches: [main]
22+
# pull_request:
23+
# branches: [main]
24+
# workflow_dispatch:
25+
#
26+
# jobs:
27+
# aspect-workflows:
28+
# name: Aspect Workflows
29+
# uses: ./.github/workflows/.aspect-workflows-reusable.yaml
30+
# ```
31+
#
32+
# 2. Create a fork of https://github.com/aspect-build/workflows-action in your
33+
# GitHub org and change the `uses` line above to reference the reusable work
34+
# from your fork:
35+
#
36+
# ```
37+
# jobs:
38+
# aspect-workflows:
39+
# name: Aspect Workflows
40+
# uses: my-github-org/workflows-action/.github/workflows/.aspect-workflows-reusable.yaml@5.12.0-alpha0.dev.68.g41b1e2f
41+
# ```
42+
# ==================================================================================================
43+
name: Aspect Workflows Reusable Workflow (v5.12.0-alpha0.dev.68.g41b1e2f)
44+
on:
45+
# Makes this workflow reusable, see
46+
# https://github.blog/2022-02-10-using-reusable-workflows-github-actions
47+
workflow_call:
48+
inputs:
49+
aspect-config:
50+
description: Path to the Aspect Workflows config.yaml file
51+
type: string
52+
default: .aspect/workflows/config.yaml
53+
delivery-workflow:
54+
description: The name of the file which contains the delivery workflow
55+
type: string
56+
default: aspect-workflows-delivery.yaml
57+
queue:
58+
description: The queue / runner pool that the setup step will run on
59+
type: string
60+
default: aspect-default
61+
slack_webhook_url:
62+
description: 'If set, then a webhook notification will be sent for failing builds on a release branch. Input should match the name of a secret. "secrets: inherit" must also be set'
63+
type: string
64+
inherited_secrets:
65+
description: 'Comma separated list of secrets or regex (Oniguruma) describing secrets to be made available during the build. "secrets: inherit" must also be set. The regex is used by jq internally which uses the Oniguruma regular expression library: https://jqlang.github.io/jq/manual/'
66+
type: string
67+
jobs:
68+
setup:
69+
runs-on: [self-hosted, aspect-workflows, "${{ inputs.queue }}"]
70+
steps:
71+
- uses: actions/checkout@v4
72+
- id: rosetta-generate
73+
run: |
74+
ROSETTA_RESULT=$( \
75+
rosetta steps \
76+
--config ${{ inputs.aspect-config }} \
77+
--gha_task generate \
78+
--gha_json_pretty_print=false \
79+
)
80+
tee "${GITHUB_OUTPUT}" <<< "json=${ROSETTA_RESULT}"
81+
outputs:
82+
cfg: ${{ steps.rosetta-generate.outputs.json }}
83+
bazel:
84+
needs: [setup]
85+
runs-on: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].labels }}
86+
strategy:
87+
fail-fast: false
88+
matrix: ${{ fromJson(needs.setup.outputs.cfg).matrix_config }}
89+
env:
90+
ASPECT_WORKFLOWS_CONFIG: ${{ inputs.aspect-config }}
91+
steps:
92+
- name: Workflows environment
93+
run: ${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/configure_workflows_env
94+
- name: Clone repo
95+
uses: actions/checkout@v4
96+
with:
97+
fetch-depth: ${{ !endsWith(matrix.job, 'lint') && 1 || 2 }}
98+
- name: Agent health check
99+
# Set RUNNER_TRACKER_ID="" to prevent GitHub Actions from killing the Bazel server started
100+
# during health check when "Cleaning up orphan processes" in the "Complete job" step.
101+
# See https://github.com/actions/runner/issues/598.
102+
run: RUNNER_TRACKING_ID="" && ${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/agent_health_check
103+
timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].health_check_timeout }}
104+
- name: Process secrets
105+
id: process_secrets
106+
if: inputs.inherited_secrets != ''
107+
run: |
108+
REQUIRED_SECRETS=$(${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/jq -R --compact-output 'gsub("\\s+";"";"g") | split(",")' <<< "${{ inputs.inherited_secrets }}")
109+
FILTERED_SECRETS=$(${{ fromJson(needs.setup.outputs.cfg).platform.directories.WORKFLOWS_BIN_DIR }}/jq --compact-output --argjson secrets "${REQUIRED_SECRETS}" 'with_entries( select (.key | test($secrets[]) ) )' <<< '''${{ toJson(secrets) }}''' )
110+
echo "filtered_secrets=${FILTERED_SECRETS}" | tee ${GITHUB_OUTPUT}
111+
- name: Prepare archive directories
112+
run: rm -rf ${{ join(fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].artifact_paths, ' ') }}
113+
- name: Determine changed files
114+
uses: tj-actions/changed-files@v42
115+
if: endsWith(matrix.job, 'format')
116+
with:
117+
json: true
118+
write_output_files: true
119+
output_dir: ${{ fromJson(needs.setup.outputs.cfg).platform.directories.ARTIFACTS_DIR }}
120+
- name: Checkout health
121+
uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f
122+
timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].checkout_task_timeout }}
123+
if: fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].has_checkout_task
124+
with:
125+
workspace: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }}
126+
task: checkout
127+
- name: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].name }}
128+
uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f
129+
env: ${{ inputs.inherited_secrets != '' && fromJson(steps.process_secrets.outputs.filtered_secrets) || fromJson('{}') }}
130+
timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].timeout_in_minutes }}
131+
with:
132+
workspace: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }}
133+
task: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].task }}
134+
- name: Send notification to Slack
135+
id: slack
136+
# oncall cares about branches that do delivery, so key this on whether we produce a delivery manifest
137+
if: inputs.slack_webhook_url != '' && failure() && fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].generate_manifest
138+
uses: slackapi/slack-github-action@v1.27.0
139+
with:
140+
payload: |
141+
{
142+
"gha_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
143+
}
144+
env:
145+
SLACK_WEBHOOK_URL: ${{ secrets[inputs.slack_webhook_url] }}
146+
- name: Delivery manifest
147+
if: fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].generate_manifest
148+
uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f
149+
timeout-minutes: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].delivery_manifest_timeout }}
150+
with:
151+
workspace: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }}
152+
task: delivery_manifest
153+
args: "--data TARGETS_SOURCE=${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].task }}"
154+
# Upload all artifacts for the workspace
155+
- name: Upload artifacts
156+
# The `always()` condition makes this step run even if a previous step failed.
157+
# Setting `continue-on-error: true` on previous steps isn't ideal as the UI
158+
# will flag them as having passed even if they failed.
159+
if: ${{ always() }}
160+
uses: actions/upload-artifact@v4
161+
with:
162+
name: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].artifact_prefix }}${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].task }}.artifacts
163+
path: ${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].artifact_upload_pattern }}
164+
overwrite: true
165+
# Codecov
166+
- name: Codecov upload
167+
# The `always()` condition makes this step run even if a previous step failed.
168+
# Setting `continue-on-error: true` on previous steps isn't ideal as the UI
169+
# will flag them as having passed even if they failed.
170+
if: ${{ always() && fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].codecov_upload }}
171+
# https://github.com/marketplace/actions/codecov
172+
uses: codecov/codecov-action@v4
173+
with:
174+
files: bazel-out/_coverage/_coverage_report.dat
175+
token: ${{ secrets.CODECOV_TOKEN }}
176+
functionalities: search # Disable searching for coverage reports. If enabled, it gets confused
177+
# by the bazel convenience symlinks and finds the same coverage report
178+
# under bazel-out and {workspace}/bazel-out.
179+
- name: Trigger delivery
180+
# This uses the following API: https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
181+
run: |
182+
curl \
183+
-X POST \
184+
-H "Accept: application/vnd.github.v3+json" \
185+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
186+
https://api.github.com/repos/${{ github.repository }}/actions/workflows/${{ inputs.delivery-workflow }}/dispatches \
187+
-d "{\"ref\":\"${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].branch }}\",\"inputs\":{\"delivery_commit\":\"${GITHUB_SHA}\",\"workspace\":\"${{ fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].workspace }}\"}}"
188+
shell: bash
189+
if: fromJson(needs.setup.outputs.cfg).workflows_config[matrix.job].delivery
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Aspect Workflows Warming
2+
3+
on:
4+
# Run the workflows on a cron schedule to periodically create an up-to-date warming archive
5+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
6+
schedule:
7+
- cron: '0 8 * * *'
8+
9+
# Allow this to be triggered manually via the GitHub UI Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
warming-archive:
14+
name: Aspect Workflows Warming
15+
runs-on: [self-hosted, aspect-workflows, aspect-warming]
16+
env:
17+
ASPECT_WORKFLOWS_BIN_DIR: /etc/aspect/workflows/bin
18+
steps:
19+
- name: Workflows environment
20+
run: ${ASPECT_WORKFLOWS_BIN_DIR}/configure_workflows_env
21+
- uses: actions/checkout@v4
22+
with:
23+
ref: main-gha
24+
- name: Agent health check
25+
# Set RUNNER_TRACKER_ID="" to prevent GitHub Actions from killing the Bazel server started
26+
# during health check when "Cleaning up orphan processes" in the "Complete job" step.
27+
# See https://github.com/actions/runner/issues/598.
28+
run: RUNNER_TRACKER_ID="" && ${ASPECT_WORKFLOWS_BIN_DIR}/agent_health_check
29+
- name: Create warming archive
30+
uses: aspect-build/workflows-action@5.12.0-alpha0.dev.68.g41b1e2f
31+
with:
32+
task: warming
33+
- name: Archive warming tars
34+
run: ${ASPECT_WORKFLOWS_BIN_DIR}/warming_archive
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Aspect Workflows
2+
3+
on:
4+
# Triggers the workflow on the main-gha branch and on pull requests with main-gha bases
5+
push:
6+
branches: [main-gha]
7+
pull_request:
8+
branches: [main-gha]
9+
10+
# Run the workflows on a cron schedule to run once a day on main branch
11+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
12+
schedule:
13+
- cron: '0 14 * * 1-5'
14+
15+
# Allow this to be triggered manually via the GitHub UI Actions tab
16+
workflow_dispatch:
17+
18+
concurrency:
19+
# Cancel previous actions from the same PR or branch except 'main-gha' branch.
20+
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
21+
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main-gha' && format('::{0}', github.run_id) || ''}}
22+
cancel-in-progress: ${{ github.ref_name != 'main-gha' }}
23+
24+
jobs:
25+
aspect-workflows:
26+
name: Aspect Workflows
27+
uses: ./.github/workflows/.aspect-workflows-reusable.yaml
28+
with:
29+
queue: aspect-small

0 commit comments

Comments
 (0)