-
Notifications
You must be signed in to change notification settings - Fork 3
81 lines (73 loc) · 3.01 KB
/
build-publish.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
name: Container Image
on:
push:
pull_request_target:
jobs:
build:
name: Build & Publish
runs-on: ubuntu-24.04
# run on same-repo pushes or forks
# this avoids running the action twice for
# pull requests from same-repo branches
if: ${{ github.event_name == 'push' || github.event.pull_request.base.repo.full_name != github.event.pull_request.head.repo.full_name }}
steps:
- name: Compute Labels
if: ${{ github.event_name == 'push' }}
id: meta
uses: docker/metadata-action@v5
with:
images: quay.io/ffddorf/unms-exporter
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
org.opencontainers.image.url=https://github.com/ffddorf/unms-exporter
org.opencontainers.image.source=https://github.com/ffddorf/unms-exporter
org.opencontainers.image.revision=45bf621f0ff5cbc7f04d51f5899220b83f088b4d
- id: short-sha
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/[email protected]
with:
script: |
const sha = context.payload.pull_request.head.sha.substr(0,7)
core.setOutput('sha', sha)
- name: Compute Labels for fork
if: ${{ github.event_name == 'pull_request_target' }}
id: forkmeta
uses: docker/metadata-action@v5
with:
images: quay.io/ffddorf/unms-exporter
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=pr
type=raw,sha-${{ steps.short-sha.outputs.sha }}
labels: |
org.opencontainers.image.url=https://github.com/${{ github.event.pull_request.head.repo.full_name }}
org.opencontainers.image.source=https://github.com/${{ github.event.pull_request.head.repo.full_name }}
org.opencontainers.image.revision=${{ github.event.pull_request.head.sha }}
- name: Login to Quay
uses: docker/login-action@v3
with:
registry: quay.io
username: ffddorf+github_actions
password: ${{ secrets.QUAY_BOT_PASSWORD }}
- name: Build Image
if: ${{ github.event_name == 'push' }}
uses: docker/build-push-action@v6
with:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
- name: Build Image for fork PR
if: ${{ github.event_name == 'pull_request_target' }}
uses: docker/build-push-action@v6
with:
context: https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git#${{ github.event.pull_request.head.sha }}
tags: ${{ steps.forkmeta.outputs.tags }}
labels: ${{ steps.forkmeta.outputs.labels }}
push: true