generated from im-open/composite-action-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
73 lines (64 loc) · 2.7 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
name: is-tag-reachable-from-default-branch
description: Determines whether a tag is reachable from the default branch
inputs:
tag:
description: 'The tag to be checked'
required: true
default-branch:
description: 'The default branch for the repository. Defaults to main.'
required: true
default: 'main'
ref:
description: 'Required when a `ref` arg was used with `actions/checkout` or if a non-default branch was selected when starting the workflow. Specify the same ref here so the action can return the repository to that ref.'
required: false
error-if-not-reachable:
description: 'Throw an error if the tag is not reachable from the default branch'
required: true
default: 'true'
outputs:
reachable:
description: 'Whether the tag is reachable from the default branch.'
value: '${{ steps.check-tag.outputs.reachable }}'
runs:
using: 'composite'
steps:
- name: Check if tag is reachable from the default branch
id: check-tag
shell: bash
run: |
errorIfNotReachable=${{ inputs.error-if-not-reachable }}
tag=${{ inputs.tag }}
defaultBranch=${{ inputs.default-branch }}
ref=${{ inputs.ref }}
echo "Checking tag: $tag"
echo "ErrorIfNotReachable: $errorIfNotReachable"
if [ $(echo ${#ref}) -gt 0 ]; then
echo "::group::Switching to the default branch"
git checkout $defaultBranch -f
echo "::endgroup::"
fi
# Store the list of tags reachable from the default branch (--merged)
# and sort them by ascending version number, interpreting the tag name as a version number (--sort="version:refname")
mergedTags=$(git tag --list --sort="version:refname" --merged)
echo "Checking tag: $tag"
echo "::group::The repository contains the following tags which are reachable from $defaultBranch"
printf '%s\n' "${mergedTags[@]}"
echo "::endgroup::"
if [ $(echo ${#ref}) -gt 0 ]; then
echo "::group::Switching back to $ref"
git checkout $ref -f
echo "::endgroup::"
fi
if printf '%s\n' "${mergedTags[@]}" | grep -q -w $tag ;
then
echo "The tag appears in the list of reachable tags"
echo "reachable=true" >> $GITHUB_OUTPUT
else
echo "reachable=false" >> $GITHUB_OUTPUT
if [ "$errorIfNotReachable" == "true" ]; then
echo "::error::The tag does not appear to be reachable from $defaultBranch."
exit 1
else
echo "::warning::The tag does not appear to be reachable from $defaultBranch."
fi
fi