Skip to content

Commit 4e5c04d

Browse files
authored
added env.VAR example to GHA part11d.md
1 parent 9ba2c62 commit 4e5c04d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/content/11/en/part11d.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,31 @@ You most likely need functions [contains](https://docs.github.com/en/actions/lea
280280
281281
Developing workflows is not easy, and quite often the only option is trial and error. It might actually be advisable to have a separate repository for getting the configuration right, and when it is done, to copy the right configurations to the actual repository.
282282
283+
It would also make sense to re-use longer conditions by moving them to commonly accessible variables and referring these variables on job/step levels:
284+
285+
```yaml
286+
name: some workflow name
287+
288+
env:
289+
# the below will be 'true'
290+
CONDITION: ${{ contains('kissa', 'ss') && contains('koira', 'ra') && contains('pretty long array of criteria to repeat in multiple places', 'crit') }}
291+
292+
jobs:
293+
job1:
294+
# rest of the job
295+
steps:
296+
- if: ${{ env.CONDITION == 'true' }}
297+
run: echo 'this step is executed'
298+
299+
- if: ${{ env.CONDITION == 'false' }}
300+
run: echo 'this step will not be executed'
301+
302+
job2:
303+
# this job will be dependent on the above env.CONDITION, not the `github.` prefix which seem to be required while referencing the variable on the job level, but not the step level
304+
if: ${{ github.env.CONDITION == 'true' }}
305+
# rest of the job
306+
```
307+
283308
It would also be possible to install a tool such as [act](https://github.com/nektos/act) that makes it possible to run your workflows locally. Unless you end up using more involved use cases like creating your [own custom actions](https://docs.github.com/en/free-pro-team@latest/actions/creating-actions), going through the burden of setting up a tool such as act is most likely not worth the trouble.
284309

285310
</div>

0 commit comments

Comments
 (0)