Skip to content

Commit f5f032a

Browse files
authored
Initial implementation (#2)
1 parent 7f537e4 commit f5f032a

File tree

6 files changed

+229
-30
lines changed

6 files changed

+229
-30
lines changed

.github/workflows/setup-test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test workflow
2+
on:
3+
workflow_call:
4+
inputs:
5+
matrix-step-name:
6+
required: false
7+
type: string
8+
matrix-key:
9+
required: false
10+
type: string
11+
outputs:
12+
result:
13+
description: "Result"
14+
value: ${{ jobs.do.outputs.result }}
15+
16+
jobs:
17+
do:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Setup
21+
run: echo "Do setup"
22+
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
26+
- uses: ./
27+
id: writer
28+
with:
29+
matrix-step-name: ${{ inputs.matrix-step-name }}
30+
matrix-key: ${{ inputs.matrix-key }}
31+
outputs: |-
32+
result: ${{ inputs.matrix-key }}
33+
34+
outputs:
35+
result: ${{ inputs.matrix-key }}

.github/workflows/test-negative.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,43 @@ on:
1010
jobs:
1111
setup:
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
target: ["one", "two"]
1316
steps:
1417
- name: Setup
1518
run: echo "Do setup"
1619

17-
test:
18-
runs-on: ubuntu-latest
19-
needs: [setup]
20-
continue-on-error: true
21-
steps:
2220
- name: Checkout
2321
uses: actions/checkout@v3
2422

2523
- uses: ./
26-
id: current
24+
id: writer
2725
with:
28-
param1: 'false'
26+
matrix-step-name: ${{ github.job }}
27+
matrix-key: ${{ matrix.target }}
28+
29+
test:
30+
runs-on: ubuntu-latest
31+
continue-on-error: true
32+
needs: [setup]
33+
steps:
34+
- uses: actions/download-artifact@v3
35+
36+
- id: current
37+
run: |-
38+
echo "result=$(ls | wc -l)" >> $GITHUB_OUTPUT
2939
3040
outputs:
31-
result: "${{ steps.current.outputs.result1 }}"
41+
result: "${{ steps.current.outputs.result }}"
3242

3343
assert:
3444
runs-on: ubuntu-latest
3545
needs: [test]
3646
steps:
3747
- uses: nick-fields/assert-action@v1
3848
with:
39-
expected: 'false'
49+
expected: '0'
4050
actual: "${{ needs.test.outputs.result }}"
4151

4252
teardown:

.github/workflows/test-non-matrix.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test example non-matrix
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
setup:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup
15+
run: echo "Do setup"
16+
17+
test:
18+
runs-on: ubuntu-latest
19+
continue-on-error: true
20+
needs: [setup]
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- uses: ./
26+
id: current
27+
with:
28+
outputs: |-
29+
result: one
30+
31+
outputs:
32+
result: "${{ steps.current.outputs.result }}"
33+
34+
assert:
35+
runs-on: ubuntu-latest
36+
needs: [test]
37+
steps:
38+
- uses: nick-fields/assert-action@v1
39+
with:
40+
expected: '{"result":"one"}'
41+
actual: "${{ needs.test.outputs.result }}"
42+
43+
- uses: nick-fields/assert-action@v1
44+
with:
45+
expected: 'one'
46+
actual: ${{ fromJson(needs.test.outputs.result).result }}
47+
48+
teardown:
49+
runs-on: ubuntu-latest
50+
needs: [assert]
51+
if: ${{ always() }}
52+
steps:
53+
- name: Tear down
54+
run: echo "Do Tear down"

.github/workflows/test-positive.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,45 @@ on:
1010
jobs:
1111
setup:
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
target: ["one", "two"]
1316
steps:
1417
- name: Setup
1518
run: echo "Do setup"
1619

20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- uses: ./
24+
id: writer
25+
with:
26+
matrix-step-name: ${{ github.job }}
27+
matrix-key: ${{ matrix.target }}
28+
outputs: |-
29+
result: ${{ matrix.target }}
30+
1731
test:
1832
runs-on: ubuntu-latest
1933
continue-on-error: true
2034
needs: [setup]
2135
steps:
22-
- name: Checkout
23-
uses: actions/checkout@v3
36+
- uses: actions/download-artifact@v3
2437

25-
- uses: ./
26-
id: current
27-
with:
28-
param1: 'true'
38+
- id: current
39+
run: |-
40+
echo "result=$(ls | wc -l)" >> $GITHUB_OUTPUT
2941
3042
outputs:
31-
result: "${{ steps.current.outputs.result1 }}"
43+
result: "${{ steps.current.outputs.result }}"
3244

3345
assert:
3446
runs-on: ubuntu-latest
3547
needs: [test]
3648
steps:
3749
- uses: nick-fields/assert-action@v1
3850
with:
39-
expected: 'true'
51+
expected: '2'
4052
actual: "${{ needs.test.outputs.result }}"
4153

4254
teardown:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Test reusable workflow
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
setup:
12+
uses: cloudposse/github-action-matrix-outputs-write/.github/workflows/setup-test.yml@initail
13+
strategy:
14+
matrix:
15+
target: ["one", "two"]
16+
with:
17+
matrix-step-name: setup
18+
matrix-key: ${{ matrix.target }}
19+
20+
test:
21+
runs-on: ubuntu-latest
22+
continue-on-error: true
23+
needs: [setup]
24+
steps:
25+
- uses: actions/download-artifact@v3
26+
27+
- id: current
28+
run: |-
29+
echo "result=$(ls | wc -l)" >> $GITHUB_OUTPUT
30+
31+
outputs:
32+
result: "${{ steps.current.outputs.result }}"
33+
34+
assert:
35+
runs-on: ubuntu-latest
36+
needs: [test]
37+
steps:
38+
- uses: nick-fields/assert-action@v1
39+
with:
40+
expected: '2'
41+
actual: "${{ needs.test.outputs.result }}"
42+
43+
teardown:
44+
runs-on: ubuntu-latest
45+
needs: [assert]
46+
if: ${{ always() }}
47+
steps:
48+
- name: Tear down
49+
run: echo "Do Tear down"

action.yml

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
1-
name: 'Example composite GitHub action'
2-
description: 'Example composite GitHub action'
1+
name: 'Matrix outputs write'
2+
description: 'Write outputs for matrix'
33
44
branding:
5-
icon: 'file'
5+
icon: 'chevrons-up'
66
color: 'white'
77
inputs:
8-
param1:
9-
required: true
10-
description: "Input parameter placeholder"
11-
default: "true"
8+
matrix-step-name:
9+
required: false
10+
description: "Matrix step name"
11+
matrix-key:
12+
required: false
13+
description: "Matrix key"
14+
outputs:
15+
required: false
16+
description: "YAML structured map of outputs"
1217
outputs:
13-
result1:
14-
description: "Output result placeholder"
15-
value: "${{ steps.context.outputs.action-result }}"
18+
result:
19+
description: "Outputs result"
20+
value: "${{ steps.write.outputs.result }}"
1621
runs:
1722
using: "composite"
1823
steps:
19-
- id: context
20-
shell: bash
24+
- uses: nick-fields/assert-action@v1
25+
if: ${{ inputs.matrix-key != '' }}
26+
with:
27+
expected: ''
28+
actual: "${{ inputs.matrix-step-name }}"
29+
comparison: notEqual
30+
31+
- uses: nick-fields/assert-action@v1
32+
if: ${{ inputs.matrix-step-name != '' }}
33+
with:
34+
expected: ''
35+
actual: "${{ inputs.matrix-key }}"
36+
comparison: notEqual
37+
38+
- uses: cloudposse/[email protected]
39+
id: write
40+
with:
41+
query: .${{ inputs.matrix-key == '' }}
42+
config: |-
43+
true:
44+
result:
45+
${{ inputs.outputs }}
46+
false:
47+
result:
48+
${{ inputs.matrix-key || 'null' }}:
49+
${{ inputs.outputs }}
50+
51+
- shell: bash
52+
if: ${{ inputs.outputs != '' && inputs.matrix-step-name != '' }}
2153
run: |
22-
echo "::set-output name=action-result::${{ inputs.param1 }}"
54+
echo '${{ steps.write.outputs.result }}' > ${{ inputs.matrix-step-name }}
55+
id: matrix
2356

57+
- uses: actions/upload-artifact@v3
58+
if: ${{ inputs.outputs != '' && inputs.matrix-step-name != '' }}
59+
with:
60+
name: ${{ hashFiles( inputs.matrix-step-name ) || 'none' }}
61+
path: ${{ inputs.matrix-step-name }}
62+
if-no-files-found: warn

0 commit comments

Comments
 (0)