-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (102 loc) · 3.75 KB
/
ci.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
## This GitHub workflow is inspired by a workflow from the Oracle Docker Images repository,
## which is licensed under the Universal Permissive License (UPL) version 1.0.
##
## Copyright (c) 2019, 2023 Oracle and/or its affiliates.
## The Universal Permissive License (UPL), Version 1.0, https://oss.oracle.com/licenses/upl/
##
## https://github.com/oracle/docker-images/blob/73fc5e48f3efffd311a8ca5cc74c4b094855e02e/.github/workflows/build-and-push-dev-images.yml
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
merge_group:
jobs:
prepare:
runs-on: ubuntu-22.04
outputs:
skip_build: ${{ steps.changes.outputs.skip_build }}
matrix: ${{ steps.changes.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create matrix for changed images
id: changes
run: |
changes=$(mktemp)
latest_tag=$(git describe --tags --abbrev=0)
git diff --name-only --patch "${latest_tag}..HEAD" > "${changes}"
matrix=$(
for dockerfile in */Dockerfile; do
image=$(dirname "${dockerfile}")
version=$(grep -m1 'FROM ' "${dockerfile}" | awk -F ':' '{print $2}' | sed 's/[^0-9.]//g')
if [ -n "$version" ] && grep -q "${image}" "${changes}"; then
echo "${image};${version}"
fi
done | jq --slurp --raw-input --compact-output '
split("\n") |
.[:-1] |
map(split(";")) |
map({"image": .[0], "version": .[1]})'
)
rm "${changes}"
if [[ ${matrix} == "[]" ]]; then
# Empty array -- change didn't impact any image
skip_build=true
else
skip_build=false
matrix=$(jq --compact-output '{ "include": .}' <<<"${matrix}")
fi
echo "skip_build=${skip_build}" >> "$GITHUB_OUTPUT"
echo "matrix=${matrix}" >> "$GITHUB_OUTPUT"
build:
needs: [ prepare ]
if: always() && needs.prepare.outputs.skip_build == 'false'
strategy:
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
fail-fast: false
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/#-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.image }}
load: true
tags: "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}:${{ matrix.version }}"
- name: Push image
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
docker push "ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}:${{ matrix.version }}"
- name: Tag commit
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git tag "${{ matrix.image }}-${{ matrix.version }}"
git push origin "${{ matrix.image }}-${{ matrix.version }}"
- name: Inspect image
run: |
docker image inspect ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}:${{ matrix.version }}
## This job is used to aggregate the result of the 'build' matrix job.
## There doesn't seem to be another way to have status checks based on "dynamic" matrix jobs.
build_success:
needs: [ build ]
runs-on: ubuntu-22.04
steps:
- name: Build success
run: echo "Build success"