-
Notifications
You must be signed in to change notification settings - Fork 102
150 lines (133 loc) · 4.58 KB
/
16-conditional.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: 16 - Conditional
on:
issues:
types: [opened]
workflow_dispatch:
jobs:
job1:
runs-on: ubuntu-latest
steps:
- name: handle-all-issues
run: echo "This step runs for all issues"
- if: startsWith(github.event.issue.title, 'bug')
name: handle-bug-reports
run: echo "This step runs only for bug reports"
- if: startsWith(github.event.issue.title, 'feature request')
name: handle-feature-requests
run: echo "This step runs only for feature requests"
- name: Create file status_job1.txt and write the job status into it
if: always()
run: |
echo ${{ job.status }} > status_job1.txt
- name: Upload file status_job1.txt as an artifact
if: always()
uses: actions/[email protected]
with:
name: pass_status_job1
path: status_job1.txt
job2:
runs-on: ubuntu-latest
needs: job1
continue-on-error: true
steps:
- if: true
name: step-1
run: echo "Step 1"
- if: always()
name: step-2
run: echo "Step 2"
- if: 1 == 1
name: step-3
run: echo "Step 3"
- if: startsWith('foo', 'f')
name: step-4
run: echo "Step 4"
- run: cat ERROR.md
- name: Create file status_job2.txt and write the job status into it
if: always()
run: |
echo ${{ job.status }} > status_job2.txt
- name: Upload file status_job2.txt as an artifact
if: always()
uses: actions/[email protected]
with:
name: pass_status_job2
path: status_job2.txt
job3:
runs-on: ubuntu-latest
needs: job2
if: always()
steps:
- run: echo "THis command will always be executed even if previous job2 fails"
- name: Create file status_job3.txt and write the job status into it
if: always()
run: |
echo ${{ job.status }} > status_job3.txt
- name: Upload file status_job3.txt as an artifact
if: always()
uses: actions/[email protected]
with:
name: pass_status_job3
path: status_job3.txt
job4:
runs-on: ubuntu-latest
needs: [job1, job2, job3]
if: always()
steps:
- name: Download artifact pass_status_job1
uses: actions/[email protected]
with:
name: pass_status_job1
- name: Download artifact pass_status_job2
uses: actions/[email protected]
with:
name: pass_status_job2
- name: Download artifact pass_status_job3
uses: actions/[email protected]
with:
name: pass_status_job3
- name: Set the statuses of Job 1, Job 2, Job3 as output parameters
id: set_outputs
run: |
echo "::set-output name=status_job1::$(<pass_status_job1/status_job1.txt)"
echo "::set-output name=status_job2::$(<pass_status_job2/status_job2.txt)"
echo "::set-output name=status_job3::$(<pass_status_job3/status_job3.txt)"
- name: Show the values of the outputs
run: |
# using the syntax steps.<step_id>.outputs.<output_name> to access the output parameters
echo "status_job1 = ${{ steps.set_outputs.outputs.status_job1 }}"
echo "status_job2 = ${{ steps.set_outputs.outputs.status_job2 }}"
echo "status_job3 = ${{ steps.set_outputs.outputs.status_job3 }}"
check-secret:
runs-on: ubuntu-latest
outputs:
my-key: ${{ steps.my-key.outputs.defined }}
steps:
- id: my-key
env:
MY_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }}
if: "${{ env.MY_KEY != '' }}"
run: echo "defined=true" >> $GITHUB_OUTPUT
job5:
runs-on: ubuntu-latest
needs: [check-secret]
if: needs.check-secret.outputs.my-key == 'true'
steps:
- run: echo "This command is executed if AWS_ACCESS_KEY_ID secret IS NOT empty"
job6:
runs-on: ubuntu-latest
needs: [check-secret]
if: needs.check-secret.outputs.my-key != 'true'
steps:
- run: echo "This command is executed if AWS_ACCESS_KEY_ID secret IS empty"
job7:
runs-on: ubuntu-latest
steps:
- id: step1
run: echo "test=hello" >> $GITHUB_OUTPUT
- name: step 2
if: contains(steps.step1.outputs.test, 'hello')
run: echo 'is executed'
- name: step 3
if: contains(steps.step1.outputs.test, 'not_hello')
run: echo 'not executed'