-
Notifications
You must be signed in to change notification settings - Fork 3
147 lines (127 loc) · 4.81 KB
/
build.yml
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
name: Build images
on:
pull_request:
branches:
- trunk
merge_group:
workflow_dispatch:
permissions:
contents: read
jobs:
prepare:
name: Prepare list of images to build
runs-on: ubuntu-latest
outputs:
images: ${{ steps.set-matrix.outputs.images }}
steps:
- name: Check out the repo
uses: actions/[email protected]
- name: Set matrix
id: set-matrix
run: echo images="$(jq '."x-build"' base-images/src/*/.devcontainer.json | jq --slurp -c .)" >> "${GITHUB_OUTPUT}"
prepare-others:
name: Prepare list of other images to build
runs-on: ubuntu-latest
outputs:
images: ${{ steps.set-matrix.outputs.images }}
steps:
- name: Check out the source code
uses: actions/[email protected]
- name: Set matrix
id: set-matrix
run: echo images="$(jq '."x-build"' images/src/*/.devcontainer.json | jq --slurp -c .)" >> "${GITHUB_OUTPUT}"
build:
needs: prepare
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.prepare.outputs.images) }}
name: Build image ${{ matrix.image.name }}
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Check changed files
id: changes
run: |
base="${{ github.event.pull_request.base.sha }}"
head="${{ github.event.pull_request.head.sha }}"
image="base-images/src/${{ matrix.image.image-name }}"
changes="$(git diff --name-only "${base}" "${head}" -- "${image}" | grep -Fv "${image}/README.md" || true)"
if [ -n "${changes}" ]; then
echo needs_build=true >> "${GITHUB_OUTPUT}"
else
echo needs_build=false >> "${GITHUB_OUTPUT}"
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
if: steps.changes.outputs.needs_build == 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
if: steps.changes.outputs.needs_build == 'true'
- name: Install @devcontainers/cli
run: npm install -g @devcontainers/cli
if: steps.changes.outputs.needs_build == 'true'
- name: Expose GitHub Runtime
uses: Automattic/vip-actions/expose-github-runtime@e1faabf165941008de4c0c1381df153e49d8ad2c # v0.6.0
if: steps.changes.outputs.needs_build == 'true'
- name: Build image
run: |
devcontainer build \
--workspace-folder "base-images/src/${{ matrix.image.image-name }}" \
--platform linux/amd64,linux/arm64 \
--output type=image \
--cache-from type=gha \
--cache-to type=gha,mode=max
if: steps.changes.outputs.needs_build == 'true'
build-other-images:
needs:
- prepare-others
name: 'Build image ${{ matrix.image.name }}'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.prepare-others.outputs.images) }}
steps:
- name: Check out the repo
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Check changed files
id: changes
run: |
base="${{ github.event.pull_request.base.sha }}"
head="${{ github.event.pull_request.head.sha }}"
image="images/src/${{ matrix.image.image-name }}"
changes="$(git diff --name-only "${base}" "${head}" -- "${image}" | grep -Fv "${image}/README.md" || true)"
if [ -n "${changes}" ]; then
echo needs_build=true >> "${GITHUB_OUTPUT}"
else
echo needs_build=false >> "${GITHUB_OUTPUT}"
fi
- name: Expose GitHub Runtime
uses: Automattic/vip-actions/expose-github-runtime@e1faabf165941008de4c0c1381df153e49d8ad2c # v0.6.0
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
if: steps.changes.outputs.needs_build == 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
if: steps.changes.outputs.needs_build == 'true'
- name: Install @devcontainers/cli
run: npm install -g @devcontainers/cli
if: ${{ steps.changes.outputs.needs_build == 'true' }}
- name: Build image
run: |
devcontainer build \
--workspace-folder images/src/${{ matrix.image.image-name }} \
--platform linux/amd64,linux/arm64 \
--output type=image \
--cache-from type=gha \
--cache-to type=gha,mode=max
if: ${{ steps.changes.outputs.needs_build == 'true' }}