-
Notifications
You must be signed in to change notification settings - Fork 19
261 lines (230 loc) · 8.77 KB
/
build.yml
File metadata and controls
261 lines (230 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: R builds
on:
push:
workflow_dispatch:
inputs:
platforms:
description: |
Comma-separated list of platforms. Specify "all" to use all platforms (the default).
required: false
default: 'all'
type: string
r_versions:
description: |
Comma-separated list of R versions. Specify "last-N" to use the
last N minor R versions, or "all" to use all minor R versions since R 3.1.
Use "all-patch" to use all patch versions since R 3.1.
Defaults to "last-5,3.6.3,devel".
required: false
default: 'last-5,3.6.3,devel'
type: string
arch:
description: |
Comma-separated list of architectures. Specify "amd64", "arm64", or both.
Defaults to "amd64,arm64".
required: false
default: 'amd64,arm64'
type: choice
options:
- 'amd64,arm64'
- 'amd64'
- 'arm64'
publish:
description: |
Publish the builds to S3 staging or production? Defaults to not publishing.
required: false
default: ''
type: choice
options:
- ''
- staging
- production
workflow_call:
inputs:
platforms:
description: |
Comma-separated list of platforms. Specify "all" to use all platforms (the default).
required: false
default: 'all'
type: string
r_versions:
description: |
Comma-separated list of R versions. Specify "last-N" to use the
last N minor R versions, or "all" to use all minor R versions since R 3.1.
Defaults to "last-5,3.6.3,devel".
required: false
default: 'last-5,3.6.3,devel'
type: string
arch:
description: |
Comma-separated list of architectures. Specify "amd64", "arm64", or both.
Defaults to "amd64,arm64".
required: false
default: 'amd64,arm64'
type: string
publish:
description: |
Publish the builds to S3 staging or production? Allowed values are "staging", "production", or empty (default).
required: false
default: ''
type: string
secrets:
AWS_PUBLISH_ROLE:
required: true
AWS_REGION:
required: true
S3_BUCKET_STAGING:
required: true
S3_BUCKET_PRODUCTION:
required: true
permissions:
id-token: write
contents: read
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setup-matrix.outputs.matrix }}
platforms: ${{ steps.setup-matrix.outputs.platforms }}
r_versions: ${{ steps.setup-matrix.outputs.r_versions }}
arch: ${{ steps.setup-matrix.outputs.arch }}
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Set up matrix of platforms and R versions
id: setup-matrix
run: |
# Validate the R versions
r_versions=$(python manage_r_versions.py get "${{ inputs.r_versions }}")
# Filter out unsupported build combinations
build_matrix=$(python get_matrix.py --platforms="${{ inputs.platforms }}" --versions="$r_versions" --arch="${{ inputs.arch }}")
matrix=$(echo "$build_matrix" | jq -c '.matrix')
platforms=$(echo "$build_matrix" | jq -c '.platforms')
r_versions=$(echo "$build_matrix" | jq -c '.r_versions')
arch=$(echo "$build_matrix" | jq -c '.arch')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo "Using matrix: $matrix"
echo "platforms=$platforms" >> $GITHUB_OUTPUT
echo "Using platforms: $platforms"
echo "r_versions=$r_versions" >> $GITHUB_OUTPUT
echo "Using R versions: $r_versions"
echo "arch=$arch" >> $GITHUB_OUTPUT
echo "Using architectures: $arch"
docker-images:
needs: setup-matrix
strategy:
matrix:
platform: ${{ fromJson(needs.setup-matrix.outputs.platforms) }}
arch: ${{ fromJson(needs.setup-matrix.outputs.arch) }}
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
name: Docker image (${{ matrix.platform }}-${{ matrix.arch }})
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
# Enable Docker layer caching without having to push to a registry.
# https://docs.docker.com/build/ci/github-actions/examples/#local-cache
# This may eventually be migrated to the GitHub Actions cache backend,
# which is still considered experimental.
# https://github.com/moby/buildkit#github-actions-cache-experimental
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ matrix.platform }}-${{ matrix.arch }}-buildx-${{ github.sha }}
restore-keys: ${{ matrix.platform }}-${{ matrix.arch }}-buildx-
# Use docker buildx instead of docker-compose here because cache exporting
# does not seem to work as of docker-compose v2.6.0 and buildx v0.8.2, even
# though it works with buildx individually.
- name: Build image
run: |
docker buildx build -t r-builds:${{ matrix.platform }} \
--file builder/Dockerfile.${{ matrix.platform }} \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache-new,mode=max" \
builder
# Temporary workaround for unbounded GHA cache growth with the local cache mode.
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build:
needs: [setup-matrix, docker-images]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
name: ${{ matrix.platform }}-${{ matrix.arch }} (R ${{ matrix.r_version }})
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Restore cached Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ matrix.platform }}-${{ matrix.arch }}-buildx-${{ github.sha }}
restore-keys: ${{ matrix.platform }}-${{ matrix.arch }}-buildx-
- name: Load cached Docker image
run: |
docker buildx build -t r-builds:${{ matrix.platform }} \
--file builder/Dockerfile.${{ matrix.platform }} \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--load \
builder
- name: Build R
run: |
R_VERSION=${{ matrix.r_version }} make build-r-${{ matrix.platform }}
- name: Test R
run: |
R_VERSION=${{ matrix.r_version }} make test-r-${{ matrix.platform }}
- name: Configure AWS Credentials
if: ${{ inputs.publish != '' }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_PUBLISH_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Publish R
if: ${{ inputs.publish != '' }}
run: |
echo "Publishing R for ${{ inputs.publish }}"
s3_bucket=${{ inputs.publish == 'staging' && secrets.S3_BUCKET_STAGING || secrets.S3_BUCKET_PRODUCTION }}
S3_BUCKET=$s3_bucket make publish-r-${{ matrix.platform }}
update-versions-json:
if: ${{ inputs.publish != '' }}
needs: [build, setup-matrix]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_PUBLISH_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Update versions.json
run: |
echo "Publishing versions.json for ${{ inputs.publish }}"
s3_bucket=${{ inputs.publish == 'staging' && secrets.S3_BUCKET_STAGING || secrets.S3_BUCKET_PRODUCTION }}
versions=$(echo '${{ needs.setup-matrix.outputs.r_versions }}' | jq -r 'join(",")')
python manage_r_versions.py publish --s3-bucket="$s3_bucket" --versions="$versions"