-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
110 lines (102 loc) · 4.04 KB
/
action.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
name: 'Illarion versioning for docker images'
description: 'This action creates all the version information for the docker images handled by Illarion in one go.'
inputs:
image-name:
description: 'The name of the image, including the registry, but excluding the tag. The name will be normalized to lower case.'
required: false
default: 'ghcr.io/${{ github.repository }}'
latest-on-tags:
description: 'Set the "latest" tag on images that are build from tags.'
required: false
default: true
latest-on-branches:
description: 'Set the "latest" tag on images for branches matching this expression'
required: false
default: ''
registry-secret:
description: 'The secret that is used to push the images to the registry. This is used to check if the secret is around and set the docker-secret output.'
required: false
default: ''
outputs:
version:
description: "The version of the image"
value: ${{ steps.generate-versions.outputs.version }}
tags:
description: "The tags that are supposed to be applied to the image"
value: ${{ steps.generate-versions.outputs.tags }}
created:
description: "The creation date of the image"
value: ${{ steps.generate-versions.outputs.created }}
docker-secret:
description: "The password that can be used to authenticate with the docker registry"
value: ${{ steps.generate-versions.outputs.docker_secret }}
has-docker-secret:
description: "This is set to 'true' in case the secret for the docker authentication is set."
value: ${{ steps.generate-versions.outputs.has_docker_secret }}
runs:
using: "composite"
steps:
- name: Generate docker versions
id: generate-versions
shell: bash
env:
IMAGE_NAME: ${{ inputs.image-name }}
run: |
DOCKER_IMAGE=${IMAGE_NAME,,}
VERSION_SOURCE=?
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
VERSION_SOURCE=TAG
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
VERSION_SOURCE=BRANCH
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
VERSION_SOURCE=PR
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
LATEST_IS_SET=false
LABEL_VERSION=${VERSION}
if [[ "$VERSION_SOURCE" == "TAG" ]]; then
if [[ $VERSION =~ ^.+\..+$ ]]; then
LAST_VERSION=${VERSION}
VERSION=${VERSION%.*}
while [ "${VERSION}" != "${LAST_VERSION}" ]
do
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}"
LAST_VERSION=${VERSION}
VERSION=${VERSION%.*}
done
fi
if [[ "${{ inputs.latest-on-tags }}" == "true" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
LATEST_IS_SET=true
fi
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
if [[ "$LATEST_IS_SET" == "false" ]]; then
if [ -n "${{ inputs.latest-on-branches }}" ]; then
if [[ $VERSION =~ "${{ inputs.latest-on-branches }}" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
LATEST_IS_SET=true
fi
fi
fi
if [ -n "${{ inputs.registry-secret }}" ]; then
DOCKER_SECRET=${{ inputs.registry-secret }}
fi
if [ "${{ github.event_name }}" != 'pull_request' ] && [ -n "${DOCKER_SECRET}" ]; then
HAS_SECRET=true
else
HAS_SECRET=false
DOCKER_SECRET=
fi
echo "Version: ${LABEL_VERSION}"
echo "Tags: ${TAGS}"
echo "Secret available: ${HAS_SECRET}"
echo "version=${LABEL_VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "has_docker_secret=${HAS_SECRET}" >> $GITHUB_OUTPUT
echo "docker_secret=${DOCKER_SECRET}" >> $GITHUB_OUTPUT