forked from open-cluster-management-io/addon-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (141 loc) · 4.95 KB
/
Copy pathpost.yml
File metadata and controls
155 lines (141 loc) · 4.95 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
name: Post
on:
push:
branches:
- main
workflow_dispatch: {}
concurrency:
group: post-${{ github.ref }}
cancel-in-progress: true
jobs:
generate-matrix:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
repositories: ${{ steps.repo-matrix.outputs.repositories }}
artifacts: ${{ steps.generate.outputs.artifacts }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
ref: ${{ github.sha }}
- name: Compute diff refs
id: compute-refs
run: |
set -e
BASE_SHA=${{ github.event.before }}
HEAD_SHA=${{ github.sha }}
# Ensure we have both the base and head commits
git fetch --depth=1 origin $BASE_SHA
git fetch --depth=1 origin $HEAD_SHA
echo "BASE_SHA=$BASE_SHA" >> $GITHUB_ENV
echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV
# echo "Diff will compare $BASE_SHA with $HEAD_SHA"
echo "Diff will compare main ($BASE_SHA) with $HEAD_SHA"
- name: Generate repository matrix
id: repo-matrix
uses: ./.github/actions/generate-repo-matrix
with:
repoRoot: "."
- name: Build changed project matrix
id: generate
run: |
set -e
# Get repository names and check for changes
repositories_json='${{ steps.repo-matrix.outputs.repositories }}'
changed_repos=()
# Check each repository for changes
while IFS= read -r repo; do
if git diff --name-only $BASE_SHA $HEAD_SHA | grep "^$repo/" > /dev/null 2>&1; then
changed_repos+=("$repo")
fi
done < <(echo "$repositories_json" | jq -r 'keys[]')
if [ ${#changed_repos[@]} -eq 0 ]; then
echo "No changes detected for any project"
echo "matrix=" >> $GITHUB_OUTPUT
echo "artifacts={}" >> $GITHUB_OUTPUT
else
# Convert changed repos array to JSON
changed_repos_json=$(printf '%s\n' "${changed_repos[@]}" | jq -R . | jq -s .)
matrixJson=$(echo "$changed_repos_json" | jq -c '{"repo": .}')
# Generate artifacts JSON with workspace prefix
artifacts_json=$(
echo "$repositories_json" | jq -c \
--argjson changed_repos "$changed_repos_json" \
--arg workspace "${{ github.workspace }}" \
'
to_entries
| map(select(.key as $repo | $changed_repos | index($repo) != null))
| from_entries
| with_entries(
.key as $repo
| .value = (
.value["e2e-artifacts"]
| map($workspace + "/" + $repo + "/" + .)
| join("\n")
)
)
'
)
echo "matrix=$matrixJson" >> $GITHUB_OUTPUT
echo "artifacts=$artifacts_json" >> $GITHUB_OUTPUT
fi
echo "Matrix: $matrixJson"
echo "Artifacts: $artifacts_json"
images:
name: Build and Push Images
needs: generate-matrix
if: needs.generate-matrix.outputs.matrix != ''
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
repo: ${{ fromJson(needs.generate-matrix.outputs.matrix).repo }}
arch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: install Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: install imagebuilder
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.16
- name: pull base image
run: docker pull registry.access.redhat.com/ubi9/ubi-minimal:latest --platform=linux/${{ matrix.arch }}
- name: build image
run: |
set -e
cd ${{ matrix.repo }}
IMAGE_TAG=latest-${{ matrix.arch }} \
IMAGE_BUILD_EXTRA_FLAGS="--build-arg OS=linux --build-arg ARCH=${{ matrix.arch }}" \
make image
- name: push image
run: |
set -e
cd ${{ matrix.repo }}
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
IMAGE_TAG=latest-${{ matrix.arch }} \
make image-push
image-manifest:
name: Create and Push Image Manifest
needs: [images, generate-matrix]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
repo: ${{ fromJson(needs.generate-matrix.outputs.matrix).repo }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: create and push manifest
run: |
set -e
cd ${{ matrix.repo }}
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
IMAGE_TAG=latest \
make image-manifest