-
Notifications
You must be signed in to change notification settings - Fork 73
/
action.yaml
78 lines (72 loc) · 3.11 KB
/
action.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
#
# Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Determine Docker image tag"
description: "A action to determine Docker image tag"
outputs:
PRIMARY_TAG:
description: "Primary tag"
value: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }}
DEFAULT_TAG:
description: "default tag. Tag to be used if the primary tag does not exist"
value: ${{ steps.determine_tag_name.outputs.DEFAULT_TAG }}
runs:
using: "composite"
steps:
- name: Dump Github context
shell: bash
run: |
echo "GITHUB_REF $GITHUB_REF"
echo "GITHUB_BASE_REF $GITHUB_BASE_REF"
echo "GITHUB_EVENT_PATH $GITHUB_EVENT_PATH"
echo "GITHUB_EVENT_NAME ${{ github.event_name }}"
echo "GITHUB_EVENT_NUMBER ${{ github.event.number }}"
- name: Determine tag name
shell: bash
id: determine_tag_name
run: |
if [[ "$GITHUB_REF" =~ ^refs/tags/.* ]]; then
tag_name=`echo $GITHUB_REF | sed -e 's:^refs/tags/::'`
echo "${tag_name}" > versions/VALD_VERSION
primary_tag="${tag_name}"
default_tag="nightly"
elif [[ "${{ github.event_name }}" = "pull_request" || "${{ github.event_name }}" = "pull_request_target" ]]; then
pr_num=`cat $GITHUB_EVENT_PATH | jq -r ".number"`
echo "PR-${pr_num}" > versions/VALD_VERSION
primary_tag="pr-${pr_num}"
default_tag="nightly"
# For pull request to the release branch, use the release branch latest tag as the default tag (vx.x).
# This is only set if the event that triggers the workflow execution is pull_request or pull_request_target.
if [[ "$GITHUB_BASE_REF" =~ ^release/v([0-9]+)\.([0-9]+)$ ]]; then
tag_name=`echo $GITHUB_BASE_REF | sed -e 's:^release/::'`
default_tag="${tag_name}"
fi
elif [ "$GITHUB_REF" = "refs/heads/main" ]; then
echo "nightly" > versions/VALD_VERSION
primary_tag="nightly"
default_tag="nightly"
elif [[ "$GITHUB_REF" =~ ^refs/heads/release/v([0-9]+)\.([0-9]+)$ ]]; then
tag_name=`echo $GITHUB_REF | sed -e 's:^refs/heads/release/::'`
echo "${tag_name}" > versions/VALD_VERSION
primary_tag="${tag_name}"
default_tag="nightly"
else
primary_tag="unknown"
default_tag="unknown"
fi
echo "PRIMARY_TAG is determined: ${primary_tag}"
echo "DEFAULT_TAG is determined: ${default_tag}"
echo "PRIMARY_TAG=${primary_tag}" >> $GITHUB_OUTPUT
echo "DEFAULT_TAG=${default_tag}" >> $GITHUB_OUTPUT