Skip to content

Commit fd118d4

Browse files
committed
build: rewrite CI to use matrices and cut down on workflow calls
1 parent ca3ffaa commit fd118d4

File tree

14 files changed

+569
-1024
lines changed

14 files changed

+569
-1024
lines changed

.github/workflows/_build-app.yml

Lines changed: 0 additions & 148 deletions
This file was deleted.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Build Images
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
# A stringified JSON object containing a list of projects
7+
# (worker, codecov-api, shared) for which CI should run.
8+
changes:
9+
type: string
10+
required: true
11+
12+
# Whether to build production images
13+
build-prod:
14+
type: boolean
15+
default: true
16+
17+
# Whether to build self-hosted images
18+
build-self-hosted:
19+
type: boolean
20+
default: false
21+
22+
env:
23+
AR_REQS_REPO: ${{ vars.CODECOV_UMBRELLA_REQS_IMAGE || 'codecov/umbrella-reqs-fallback' }}
24+
25+
jobs:
26+
build:
27+
name: Build App
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
include:
32+
- project: worker
33+
enabled: ${{ contains(fromJSON(inputs.changes), 'worker') }}
34+
repo: ${{ vars.CODECOV_WORKER_IMAGE_V2 || vars.CODECOV_WORKER_IMAGE_V2_SELF_HOSTED || 'codecov/self-hosted-worker' }}
35+
output_directory: apps/worker
36+
make_target_prefix: worker.
37+
38+
- project: codecov-api
39+
enabled: ${{ contains(fromJSON(inputs.changes), 'codecov-api') }}
40+
repo: ${{ vars.CODECOV_API_IMAGE_V2 || vars.CODECOV_API_IMAGE_V2_SELF_HOSTED || 'codecov/self-hosted-api' }}
41+
output_directory: apps/codecov-api
42+
make_target_prefix: api.
43+
44+
- project: shared
45+
enabled: ${{ contains(fromJSON(inputs.changes), 'shared') }}
46+
repo: codecov/dev-shared
47+
output_directory: apps/shared
48+
make_target_prefix: shared.
49+
50+
env:
51+
AR_REPO: ${{ matrix.repo }}
52+
steps:
53+
- name: Checkout
54+
if: ${{ matrix.enabled }}
55+
uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 2
58+
submodules: 'recursive'
59+
60+
- id: "auth"
61+
if: ${{ matrix.enabled && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
62+
name: "Authenticate to Google Cloud"
63+
uses: "google-github-actions/auth@v2.1.2"
64+
with:
65+
token_format: "access_token"
66+
workload_identity_provider: ${{ secrets.CODECOV_GCP_WIDP }}
67+
service_account: ${{ secrets.CODECOV_GCP_WIDSA }}
68+
69+
- name: Docker configuration
70+
if: ${{ matrix.enabled && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
71+
run: |-
72+
echo ${{steps.auth.outputs.access_token}} | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.dev
73+
74+
- name: Cache Requirements
75+
id: cache-requirements
76+
if: ${{ matrix.enabled }}
77+
uses: actions/cache@v4
78+
env:
79+
# Forks can't access the variable containing our actual image repository. We want to
80+
# use a separate cache to make sure they don't interfere with reqs images being pushed.
81+
cache-name: ${{ !github.event.pull_request.repo.fork && 'umbrella-requirements' || 'umbrella-requirements-fork' }}
82+
with:
83+
path: |
84+
./requirements.tar
85+
key: ${{ runner.os }}-${{ runner.arch }}-${{ env.cache-name }}-${{ hashFiles('uv.lock') }}-${{ hashFiles('docker/Dockerfile.requirements') }}-${{ hashFiles('libs/shared/**') }}
86+
87+
- name: Cache App
88+
id: cache-app
89+
if: ${{ matrix.enabled && inputs.build-prod }}
90+
uses: actions/cache@v4
91+
env:
92+
cache-name: ${{ matrix.repo }}-app
93+
with:
94+
path: |
95+
${{ matrix.output_directory }}/app.tar
96+
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.run_id }}
97+
98+
- name: Cache Self-Hosted
99+
id: cache-self-hosted
100+
if: ${{ matrix.enabled && inputs.build-self-hosted }}
101+
uses: actions/cache@v4
102+
env:
103+
cache-name: ${{ matrix.repo }}-self-hosted
104+
with:
105+
path: |
106+
${{ matrix.output_directory }}/self-hosted-runtime.tar
107+
${{ matrix.output_directory }}/self-hosted.tar
108+
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.run_id }}
109+
110+
- name: Load requirements from cache
111+
if: ${{ matrix.enabled && steps.cache-requirements.outputs.cache-hit == 'true' }}
112+
run: |
113+
make load.requirements
114+
115+
# This shouldn't happen; the _build-requirements.yml job should have run.
116+
- name: Build/pull requirements
117+
if: ${{ matrix.enabled && steps.cache-requirements.outputs.cache-hit != 'true' }}
118+
run: |
119+
echo "Warning: requirements image not in cache, building a new one"
120+
make build.requirements
121+
make save.requirements
122+
123+
- name: Build Prod
124+
if: ${{ matrix.enabled && inputs.build-prod }}
125+
run: |
126+
make ${{ matrix.make_target_prefix }}build.app
127+
make ${{ matrix.make_target_prefix }}save.app
128+
129+
- name: Build Self-Hosted
130+
if: ${{ matrix.enabled && inputs.build-self-hosted }}
131+
run: |
132+
make ${{ matrix.make_target_prefix }}build.self-hosted
133+
make ${{ matrix.make_target_prefix }}save.self-hosted

0 commit comments

Comments
 (0)