@@ -24,6 +24,10 @@ inputs:
24
24
description : ' Number of latest tags to add to build matrix. Default: 0'
25
25
required : false
26
26
default : 0
27
+ disable_refs :
28
+ description : ' A Flag to disable refs alltogether and return an empty matrix and has_refs=0.'
29
+ required : false
30
+ default : 0
27
31
28
32
outputs :
29
33
matrix :
@@ -43,85 +47,95 @@ runs:
43
47
ref : ${{ inputs.repository_default_branch }}
44
48
fetch-depth : 0
45
49
path : .git-ref-matrix-action
46
- if : ${{ inputs.num_latest_tags > 0 }}
50
+ if : ${{ inputs.disable_refs == 0 && inputs. num_latest_tags > 0 }}
47
51
48
52
- name : " [SETUP] Build and Export Matrix"
49
53
id : set-matrix
50
54
shell : bash
51
55
run : |
52
- ###
53
- ### Convert comma separated branches and tags to newline separated
54
- ###
55
- BRANCHES="$( echo "${{ inputs.branches }}" | sed 's/,/\n/g' )"
56
- TAGS="$( echo "${{ inputs.tags }}" | sed 's/,/\n/g' )"
57
-
58
- echo "BRANCHES:"
59
- echo "-------------------------"
60
- echo "${BRANCHES}"
61
- echo
62
-
63
- echo "TAGS:"
64
- echo "-------------------------"
65
- echo "${TAGS}"
66
- echo
67
-
68
- ###
69
- ### Get x number of latest tags of this repository (newline separated)
70
- ###
71
- if [ "${{ inputs.num_latest_tags }}" != "0" ]; then
72
- LATEST_TAGS="$( cd .git-ref-matrix-action && git tag --sort=creatordate | tail -${{ inputs.num_latest_tags }} )"
73
- rm -r .git-ref-matrix-action
56
+ if [ "${{ inputs.disable_refs }}" = "1" ]; then
57
+ ###
58
+ ### Output matrix
59
+ ###
60
+ echo "::set-output name=matrix::[]"
61
+ echo "::set-output name=has_refs::0"
62
+ echo "matrix=[]"
63
+ echo "has_refs=0"
74
64
else
75
- LATEST_TAGS=''
76
- fi
65
+ ###
66
+ ### Convert comma separated branches and tags to newline separated
67
+ ###
68
+ BRANCHES="$( echo "${{ inputs.branches }}" | sed 's/,/\n/g' )"
69
+ TAGS="$( echo "${{ inputs.tags }}" | sed 's/,/\n/g' )"
70
+
71
+ echo "BRANCHES:"
72
+ echo "-------------------------"
73
+ echo "${BRANCHES}"
74
+ echo
75
+
76
+ echo "TAGS:"
77
+ echo "-------------------------"
78
+ echo "${TAGS}"
79
+ echo
80
+
81
+ ###
82
+ ### Get x number of latest tags of this repository (newline separated)
83
+ ###
84
+ if [ "${{ inputs.num_latest_tags }}" != "0" ]; then
85
+ LATEST_TAGS="$( cd .git-ref-matrix-action && git tag --sort=creatordate | tail -${{ inputs.num_latest_tags }} )"
86
+ rm -r .git-ref-matrix-action
87
+ else
88
+ LATEST_TAGS=''
89
+ fi
77
90
78
- echo "LATEST_TAGS:"
79
- echo "-------------------------"
80
- echo "${LATEST_TAGS}"
81
- echo
82
-
83
- ###
84
- ### All newline separated refs (and make unique in case of duplicated tags)
85
- ###
86
- REFS="$( printf "%s\n%s\n%s\n" "${BRANCHES}" "${TAGS}" "${LATEST_TAGS}" | grep -Ev '^$' || true | sort -u )"
87
-
88
- echo "REFS:"
89
- echo "-------------------------"
90
- echo "${REFS}"
91
- echo
92
-
93
- ###
94
- ### Create element double-quoted and comma separated string (has leading comma)
95
- ###
96
- JSON=''
97
- while IFS= read -r line; do
98
- if [ -n "${line}" ]; then
99
- JSON="${JSON},$( printf '"%s"' "${line}" )"
91
+ echo "LATEST_TAGS:"
92
+ echo "-------------------------"
93
+ echo "${LATEST_TAGS}"
94
+ echo
95
+
96
+ ###
97
+ ### All newline separated refs (and make unique in case of duplicated tags)
98
+ ###
99
+ REFS="$( printf "%s\n%s\n%s\n" "${BRANCHES}" "${TAGS}" "${LATEST_TAGS}" | grep -Ev '^$' || true | sort -u )"
100
+
101
+ echo "REFS:"
102
+ echo "-------------------------"
103
+ echo "${REFS}"
104
+ echo
105
+
106
+ ###
107
+ ### Create element double-quoted and comma separated string (has leading comma)
108
+ ###
109
+ JSON=''
110
+ while IFS= read -r line; do
111
+ if [ -n "${line}" ]; then
112
+ JSON="${JSON},$( printf '"%s"' "${line}" )"
113
+ fi
114
+ done <<< "${REFS}"
115
+
116
+ ###
117
+ ### Remove leading comma and encapsulate in square brackets
118
+ ###
119
+ JSON="$( printf '[%s]' "${JSON#,}" )"
120
+
121
+ ###
122
+ ### Set final output for 'matrix'
123
+ ###
124
+ echo "::set-output name=matrix::${JSON}"
125
+
126
+ ###
127
+ ### Set 'has_refs'
128
+ ###
129
+ if [ "${JSON}" = "[]" ]; then
130
+ HAS_REFS="0"
131
+ else
132
+ HAS_REFS="1"
100
133
fi
101
- done <<< "${REFS}"
102
-
103
- ###
104
- ### Remove leading comma and encapsulate in square brackets
105
- ###
106
- JSON="$( printf '[%s]' "${JSON#,}" )"
107
-
108
- ###
109
- ### Set final output for 'matrix'
110
- ###
111
- echo "::set-output name=matrix::${JSON}"
112
-
113
- ###
114
- ### Set 'has_refs'
115
- ###
116
- if [ "${JSON}" = "[]" ]; then
117
- HAS_REFS="0"
118
- else
119
- HAS_REFS="1"
120
- fi
121
- echo "::set-output name=has_refs::${HAS_REFS}"
134
+ echo "::set-output name=has_refs::${HAS_REFS}"
122
135
123
- ###
124
- ### Output matrix
125
- ###
126
- echo "matrix=${JSON}"
127
- echo "has_refs=${HAS_REFS}"
136
+ ###
137
+ ### Output matrix
138
+ ###
139
+ echo "matrix=${JSON}"
140
+ echo "has_refs=${HAS_REFS}"
141
+ fi
0 commit comments