-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (85 loc) · 3.73 KB
/
docker-metadata.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
---
name: "Calculate Docker metadata"
# This reusable workflow calculates the labels and tags for a Docker image.
# These tags will vary depending on the event that triggered the workflow.
on:
workflow_call:
inputs:
# Required inputs
image_name:
description: "The Docker image name"
required: true
type: string
outputs:
image_labels:
description: "The calculated image labels"
value: ${{ jobs.metadata.outputs.image_labels }}
image_tags:
description: "The calculated image tags"
value: ${{ jobs.metadata.outputs.image_tags }}
latest:
description: "True if the image is the latest version"
value: ${{ jobs.metadata.outputs.latest }}
source_version:
description: "The version declared in the source code"
value: ${{ jobs.metadata.outputs.source_version }}
jobs:
metadata:
name: "Calculate variables"
runs-on: ubuntu-latest
outputs:
image_labels: ${{ steps.docker_meta.outputs.labels }}
image_tags: ${{ steps.docker_meta.outputs.tags }}
latest: ${{ steps.is_latest.outputs.latest }}
source_version: ${{ steps.source_values.outputs.source_version }}
tags: ${{ steps.prep.outputs.tags }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # tag=v2.10.2
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2
- name: Calculate values from source
id: source_values
run: |
echo "source_version=$(./bump_version.sh show)" >> $GITHUB_OUTPUT
- name: Determine if release is marked as latest
id: is_latest
run: |
if [ "${{ github.event_name }}" = "release" ] && [ "${{ github.event.release.prerelease }}" = "false" ]; then
# Check to see if this release was designated as the latest release
latest_release_id=$(curl -s -H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/releases/latest | jq .id)
if [ "$latest_release_id" = "${{ github.event.release.id }}" ]; then
echo "latest=true" >> $GITHUB_OUTPUT
exit 0
fi
fi
echo "latest=false" >> $GITHUB_OUTPUT
- name: Calculate Docker metadata
id: docker_meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # tag=v5.6.1
with:
flavor: |
latest=false
images: |
${{ inputs.image_name }}
ghcr.io/${{ inputs.image_name }}
labels: |
org.opencontainers.image.version=${{ steps.source_values.outputs.source_version }}
tags: |
type=edge
type=raw,value=latest,enable=${{ steps.is_latest.outputs.latest == 'true' }}
type=raw,value=prerelease,enable=${{ github.event_name == 'release' && github.event.release.prerelease }}
type=raw,value=release,enable=${{ steps.is_latest.outputs.latest == 'true' }}
type=raw,event=workflow_dispatch,value=${{ github.event.inputs.dispatch-tag }}
type=ref,event=branch
type=ref,event=pr
type=schedule,pattern=nightly
type=semver,pattern={{major}},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=sha