-
Notifications
You must be signed in to change notification settings - Fork 24
243 lines (234 loc) · 9.87 KB
/
pr-debug-publish.yaml
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
name: Produce PR dev images (on Request)
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number to build image for'
required: true
type: number
concurrency:
group: prs-${{ github.event.inputs.pr_number }}
cancel-in-progress: true
env:
GHCR_REGISTRY: ghcr.io
REGISTRY: docker.io
IMAGE_NAME: ${{ github.repository }}
YQ_VERSION: v4.44.3
GH_TOKEN: ${{ github.token }}
jobs:
prepare_pr_info:
name: Identify PR Info
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
outputs:
head_sha: ${{ steps.get_head_sha.outputs.head_sha }}
head_sha_short: ${{ steps.get_head_sha.outputs.head_sha_short }}
steps:
# Checkout the code at the head of the specified PR
- name: Checkout the repository
uses: actions/checkout@v4
- name: Get Pull Request Head SHA
id: get_head_sha
run: |
pr_number=${{ github.event.inputs.pr_number }}
echo "Fetching details for PR #$pr_number"
pr_response=$(gh api repos/${{ github.repository }}/pulls/$pr_number)
head_sha=$(echo "$pr_response" | jq -r '.head.sha')
echo "head_sha=${head_sha}" >> $GITHUB_OUTPUT
echo "head_sha_short=${head_sha:0:7}" >> $GITHUB_OUTPUT
echo "PR ${pr_number}" >> $GITHUB_STEP_SUMMARY
echo "PR SHA: ${head_sha:0:7}" >> $GITHUB_STEP_SUMMARY
echo "PR SHA FULL: ${head_sha}" >> $GITHUB_STEP_SUMMARY
build_dev_helm_locker:
name: Build and push helm-locker
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
needs: prepare_pr_info
permissions:
contents: read
packages: write
attestations: write
id-token: write
outputs:
tags: ${{ steps.meta-helm-locker.outputs.tags }}
steps:
# Checkout the code at the head of the specified PR
- name: Checkout PR Head
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_pr_info.outputs.head_sha }}
# Proceed to build images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for helm-locker image
id: meta-helm-locker
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}/helm-locker
tags: |
type=raw,value=pr-${{ github.event.inputs.pr_number }}-${{ needs.prepare_pr_info.outputs.head_sha_short }}
type=raw,value=pr-${{ github.event.inputs.pr_number }}
- name: Build and push helm-locker image
id: push
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-helm-locker
push: true
tags: ${{ steps.meta-helm-locker.outputs.tags }}
labels: ${{ steps.meta-helm-locker.outputs.labels }}
platforms: linux/amd64,linux/arm64
build_dev_helm_project_operator:
name: Build and push helm-project-operator
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
needs: prepare_pr_info
permissions:
contents: read
packages: write
attestations: write
id-token: write
outputs:
tags: ${{ steps.meta-helm-project-operator.outputs.tags }}
steps:
# Checkout the code at the head of the specified PR
- name: Checkout PR Head
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_pr_info.outputs.head_sha }}
# Proceed to build images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Helm-Project-Operator image
id: meta-helm-project-operator
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}/helm-project-operator
tags: |
type=raw,value=pr-${{ github.event.inputs.pr_number }}-${{ needs.prepare_pr_info.outputs.head_sha_short }}
type=raw,value=pr-${{ github.event.inputs.pr_number }}
- name: Build Helm-Project-Operator image
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-helm-project-operator
push: true
tags: ${{ steps.meta-helm-project-operator.outputs.tags }}
labels: ${{ steps.meta-helm-project-operator.outputs.labels }}
platforms: linux/amd64,linux/arm64
build_dev_prometheus_federator:
name: Build and push prometheus-federator
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
needs: prepare_pr_info
permissions:
contents: read
packages: write
attestations: write
id-token: write
outputs:
tags: ${{ steps.meta-prometheus-federator.outputs.tags }}
steps:
# Checkout the code at the head of the specified PR
- name: Checkout PR Head
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_pr_info.outputs.head_sha }}
# Proceed to build images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Prometheus Federator image
id: meta-prometheus-federator
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=pr-${{ github.event.inputs.pr_number }}-${{ needs.prepare_pr_info.outputs.head_sha_short }}
type=raw,value=pr-${{ github.event.inputs.pr_number }}
- name: Build prometheus-federator image
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-prometheus-federator
push: true
tags: ${{ steps.meta-prometheus-federator.outputs.tags }}
labels: ${{ steps.meta-prometheus-federator.outputs.labels }}
platforms: linux/amd64,linux/arm64
comment-on-pr:
name: Comment on PR with image details
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
needs:
- prepare_pr_info
- build_dev_helm_locker
- build_dev_helm_project_operator
- build_dev_prometheus_federator
permissions:
pull-requests: write
steps:
- name: Comment on PR with image details
uses: actions/github-script@v6
env:
meta-helm-locker: ${{ needs.build_dev_helm_locker.outputs.tags }}
meta-helm-project-operator: ${{ needs.build_dev_helm_project_operator.outputs.tags }}
meta-prometheus-federator: ${{ needs.build_dev_prometheus_federator.outputs.tags }}
prNumber: ${{ github.event.inputs.pr_number }}
shortSha: ${{ needs.prepare_pr_info.outputs.head_sha_short }}
with:
script: |
const prNumber = context.payload.inputs.pr_number;
const images = [
{
name: 'Helm Locker',
key: 'meta-helm-locker',
url: `https://github.com/${{ github.repository }}/pkgs/container/prometheus-federator%2Fhelm-locker`
},
{
name: 'Helm Project Operator',
key: 'meta-helm-project-operator',
url: `https://github.com/${{ github.repository }}/pkgs/container/prometheus-federator%2Fhelm-project-operator`
},
{
name: 'Prometheus Federator',
key: 'meta-prometheus-federator',
url: `https://github.com/${{ github.repository }}/pkgs/container/prometheus-federator`
}
];
const prepareContainerImageText = function(imageInfo) {
const rawTags = process.env[imageInfo.key];
const tags = rawTags.split(' ')
.map(tag => `\t- \`${tag}\``)
.join('\n');
return `- [**${imageInfo.name}**](${imageInfo.url}) - Tags:\n${tags}`;
}
const commentBody = images
.map(prepareContainerImageText)
.join('\n');
const helmDebugValues = `#### Helm Debug Values:
\`\`\`yaml
image:
pullPolicy: Always
registry: ghcr.io
repository: rancher/prometheus-federator
tag: pr-${process.env.prNumber}-${process.env.shortSha}
\`\`\`\n`;
const fullCommentBody = `${commentBody}\n\n${helmDebugValues}`;
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Images built for PR #${prNumber}:\n\n${fullCommentBody}`
});