Skip to content

Commit 985a401

Browse files
authored
Merge pull request #8 from cytopia/release-0.1.7
Add input: disable_refs
2 parents 83aed64 + ae2a8fd commit 985a401

File tree

5 files changed

+135
-104
lines changed

5 files changed

+135
-104
lines changed

.github/workflows/test-disabled.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: test-disabled
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
get-matrix:
8+
runs-on: ubuntu-latest
9+
name: get-matrix
10+
outputs:
11+
matrix: ${{ steps.set-matrix.outputs.matrix }}
12+
has_refs: ${{ steps.set-matrix.outputs.has_refs }}
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
- name: Fetch matrix
19+
id: set-matrix
20+
uses: ./
21+
with:
22+
repository_default_branch: master
23+
branches: master
24+
tags: v0.1.0
25+
num_latest_tags: 1
26+
disable_refs: 1
27+
28+
info:
29+
needs: [get-matrix]
30+
runs-on: ubuntu-latest
31+
name: info
32+
steps:
33+
- name: Show outputs
34+
run: |
35+
echo 'matrix=${{ needs.get-matrix.outputs.matrix }}'
36+
echo 'has_refs=${{ needs.get-matrix.outputs.has_refs }}'

.github/workflows/test-with-refs.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
name: get-matrix
1010
outputs:
1111
matrix: ${{ steps.set-matrix.outputs.matrix }}
12+
has_refs: ${{ steps.set-matrix.outputs.has_refs }}
1213
steps:
1314
- name: Checkout repository
1415
uses: actions/checkout@v3
@@ -28,12 +29,10 @@ jobs:
2829
runs-on: ubuntu-latest
2930
name: info
3031
steps:
31-
- name: Show outputs (raw)
32+
- name: Show outputs
3233
run: |
33-
echo ${{ needs.get-matrix.outputs.matrix }}
34-
- name: Show outputs (json)
35-
run: |
36-
echo ${{ fromJson(needs.get-matrix.outputs.matrix) }}
34+
echo 'matrix=${{ needs.get-matrix.outputs.matrix }}'
35+
echo 'has_refs=${{ needs.get-matrix.outputs.has_refs }}'
3736
3837
build:
3938
needs: [get-matrix]

.github/workflows/test-without-refs.yml

+4-24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
name: get-matrix
1010
outputs:
1111
matrix: ${{ steps.set-matrix.outputs.matrix }}
12+
has_refs: ${{ steps.set-matrix.outputs.has_refs }}
1213
steps:
1314
- name: Checkout repository
1415
uses: actions/checkout@v3
@@ -28,28 +29,7 @@ jobs:
2829
runs-on: ubuntu-latest
2930
name: info
3031
steps:
31-
- name: Show outputs (raw)
32+
- name: Show outputs
3233
run: |
33-
echo ${{ needs.get-matrix.outputs.matrix }}
34-
- name: Show outputs (json)
35-
run: |
36-
echo ${{ fromJson(needs.get-matrix.outputs.matrix) }}
37-
38-
build:
39-
needs: [get-matrix]
40-
runs-on: ubuntu-latest
41-
name: build
42-
strategy:
43-
fail-fast: false
44-
matrix:
45-
refs:
46-
- ${{ fromJson(needs.get-matrix.outputs.matrix) }}
47-
steps:
48-
- name: "[SETUP] Checkout repository (ref: ${{ matrix.refs }})"
49-
uses: actions/checkout@v3
50-
with:
51-
fetch-depth: 0
52-
ref: ${{ matrix.refs }}
53-
- name: Show git
54-
run: |
55-
git log | head -20
34+
echo 'matrix=${{ needs.get-matrix.outputs.matrix }}'
35+
echo 'has_refs=${{ needs.get-matrix.outputs.has_refs }}'

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
[![GitHub release](https://img.shields.io/github/release/cytopia/git-ref-matrix-action.svg?logo=github)](https://github.com/cytopia/git-ref-matrix-action/releases/latest)
44
[![GitHub marketplace](https://img.shields.io/badge/marketplace-git--ref--matrix--action-blue?logo=github)](https://github.com/marketplace/actions/git-ref-matrix-action)
55
[![](https://img.shields.io/badge/github-cytopia%2Fgit--ref--matrix--action-red.svg?logo=github)](https://github.com/cytopia/git-ref-matrix-action "github.com/cytopia/git-ref-matrix-action")
6-
[![test-with](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test.yml/badge.svg)](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-with.yml)
7-
[![test-without](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test.yml/badge.svg)](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-without.yml)
6+
[![test-with](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-with-refs.yml/badge.svg)](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-with-refs.yml)
7+
[![test-disabled](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-disabled.yml/badge.svg)](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-disabled.yml)
8+
[![test-without](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-without-refs.yml/badge.svg)](https://github.com/cytopia/git-ref-matrix-action/actions/workflows/test-without-refs.yml)
89

910
This composite action creates a stringified JSON list of git refs to be used as a build matrix.
1011

@@ -19,6 +20,7 @@ The following inputs can be used to alter the Docker tag name determination:
1920
| `branches` | No | `` | Optionally specify a comma separated list of branches to add to the build matrix. |
2021
| `tags` | No | `` | Optionally specify a comma separated list of tags to add to the build matrix. |
2122
| `num_latest_tags` | No | `0` | Optionally add x number of latest git tags to the build matrix (requires `repository_default_branch` to point to your repository's main branch. |
23+
| `disable_refs` | No | `0` | Optionally force to disable all refs alltogether by returning an empty matrix and has_refs=0. |
2224

2325

2426
## :arrow_backward: Outputs

action.yml

+87-73
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
description: 'Number of latest tags to add to build matrix. Default: 0'
2525
required: false
2626
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
2731

2832
outputs:
2933
matrix:
@@ -43,85 +47,95 @@ runs:
4347
ref: ${{ inputs.repository_default_branch }}
4448
fetch-depth: 0
4549
path: .git-ref-matrix-action
46-
if: ${{ inputs.num_latest_tags > 0 }}
50+
if: ${{ inputs.disable_refs == 0 && inputs.num_latest_tags > 0 }}
4751

4852
- name: "[SETUP] Build and Export Matrix"
4953
id: set-matrix
5054
shell: bash
5155
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"
7464
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
7790
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"
100133
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}"
122135
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

Comments
 (0)