Is it possible to check whether a file / directory exists before running a step?
For example, a library might have the ability to create files. A test could be used to check these files, and copy them to a special directory on a mismatch. This directory could then be uploaded as a build artifact. Merely checking for failure() is not sufficient, as not all tests generate a file.
Another use case would be to process a subset of a known set of files (one per step), selected based on the platform being tested. Being able to configure the subset in only one place (where they are created) would be easier to manage, than to use also include it in the strategy params.
A possible workaround could involve the set-env :: command, but that feels quite error-prone.
I don’t believe there is any native support for this yet. But with a little bit of shell magic you can make a certain step optional. For example:
steps:
- name: Only run this if file README exists
run: '(test -f README && echo README exists) || echo README does not exist, skipping step'
This will simply just output the echo on the right if the file does not exist or run the step if it does. Either way, the step will exit “successfully”, not halting your pipeline if the file does not exist.