-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add conditional execution of action steps #834
Comments
The specific case described in the ticket can be done with plain shell script. Something like the example below:
More complex - well we shall wait for #646 |
@louisgv Well, ok, actually, I want the |
I'd like to have an action that does different things depending upon
|
Is there any plan to add if conditionals to composite actions now that they support |
lol, didn't even realize i needed an if conditional as well. I'm basically building a wrapper for |
Still waiting for actions/runner#834 to make `if`'s legal.
TODO: revert Ref: actions/runner#834
TODO: revert Ref: actions/runner#834
Also have a need for this. It's the last thing keeping me from using composites similar to Azure DevOps pipeline templates... |
I came here looking for an answer to this - and with some inspiration from @louisgv I think I might have been able to come up with a temporary workaround until Instead of this: - uses: actions/cache@v2
id: cache-venv
with:
path: .venv
key: some-key-0
- run: poetry install --no-interaction --no-root
if: steps.cache-venv.outputs.cache-hit != 'true' It looks like this would also work - uses: actions/cache@v2
id: cache-venv
with:
path: .venv
key: some-key-${{ inputs.pip-cache-key }}
- run: |
if echo ${{ steps.cache-venv.outputs.cache-hit }} | grep -c "true"
then
echo "Cache hit - skipping dependency installation"
else
poetry install --no-interaction --no-root
fi
shell: bash Here is a full example workflow. Here is an example of a project using the remote workflow with a cold cache, and here with a warm cache 👍 It seems to work the same at least 🤞 |
super cool interim solution, thanks for sharing, @sondrelg ! |
@sondrelg would like to use your result but have a little different problem I got some input (not required) inputs:
test:
description: "Test command to run"
required: false
runs:
using: "composite"
steps:
- id: install
run: |
npm ci
shell: bash
- id: test
run: |
if [ -z "${{ inputs.test }}" ]
then
echo -e "test exist: ${{ inputs.test }}"
"${{ inputs.test }}"
else
echo -e "\nno test specified"
fi
shell: bash
- id: build
run: |
mkdir dist
npm run build
shell: bash
but it always get into first block even if I not specify test while using action |
I had some trouble with missing values as well @sebastianluszczek - perhaps it would help to set a default value for your input, and check against that, rather than using |
This uses a composite action with conditionals, but these will not yet work per <actions/runner#834>. This commit is just to show the start of the action before transforming it using a shell script workaround. If simpler, that transformation can be reverted to this version when support for conditionals in composite actions is added.
A more robust workaround is to use the construction: if ${{ toJSON(
fromJSON( «input that is either 'true' or 'false'» )
... «rest of boolean expression»
) }}; then
« commands... »;
fi as the value of the A benefit of this approach is that when If you want to have a fallback value in case the input is left empty, then use
A couple full example steps would be: inputs:
target-all:
required: true
default: false
target-test:
required: true
default: false
test-enable-coverage:
required: true
default: false
target-notifications:
required: true
default: false
runs:
using: "composite"
steps:
# Target: target-test
- name: target-test (no coverage)
shell: bash
env:
HARNESS_OPTIONS: ${{ inputs.test-harness-options }}
run: |
if ${{ toJSON(
( fromJSON(inputs.target-all)
|| fromJSON(inputs.target-test)
)
&& ! fromJSON(inputs.test-enable-coverage || 'false')
) }}; then
echo "::group::test (no coverage)"
if [ -f Makefile.PL ]; then
$MYPERL Makefile.PL && make test
else
echo "No file Makefile.PL" >&2
fi
echo "::endgroup::"
fi
# Target: target-notifications
- name: irc push (build messages)
shell: bash
run: |
if ${{ toJSON(
fromJSON(inputs.target-notifications)
&& github.event_name == 'push'
&& github.repository == inputs.repository
) }}; then
echo "commitmsg="$( git show -s --oneline ${{ join(github.event.commits.*.id, ' ') }} ) >> $GITHUB_ENV
fi |
Does this issue include support for |
I also need this functionality. I am trying to run another action based on an |
Big +1 on this functionality. I have a number of composite actions that are stored centrally and checked in and used by a variety of different repos for CI checks. This is to avoid massive amounts of repeated code. Currently each composite action has a final step whereby it uploads essential logs/reports as an artifact. Given that in composite actions one can neither if: always nor continue-on-error (and continue on error still frustratingly results in the job appearing as a success overall), all actions that error out have no error logs uploaded as an artifact. |
+1 |
@fhammerl will https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-actions be updated to denote EDIT: it is being tracked here github/docs#12378 |
GitHub Actions finally fixed the issue, see actions/runner#834 (comment). This reverts #202.
GitHub Actions finally fixed the issue, see actions/runner#834 (comment). This reverts #202.
* If conditional not part of composite actions: see actions/runner#834 * Replace action outputs with global environment variables * Easier to debug as printed in logs * If actions are if-conditioned to not execute, if already run, then their outputs will not exist whereas global env vars will. This makes it possible to retain the env vars while skipping repeated executions of the same actions
* If conditional not part of composite actions: see actions/runner#834 * Replace action outputs with global environment variables * Easier to debug as printed in logs * If actions are if-conditioned to not execute, if already run, then their outputs will not exist whereas global env vars will. This makes it possible to retain the env vars while skipping repeated executions of the same actions
* If conditional not part of composite actions: see actions/runner#834 * Replace action outputs with global environment variables * Easier to debug as printed in logs * If actions are if-conditioned to not execute, if already run, then their outputs will not exist whereas global env vars will. This makes it possible to retain the env vars while skipping repeated executions of the same actions
* If conditional not part of composite actions: see actions/runner#834 * Replace action outputs with global environment variables * Easier to debug as printed in logs * If actions are if-conditioned to not execute, if already run, then their outputs will not exist whereas global env vars will. This makes it possible to retain the env vars while skipping repeated executions of the same actions
* If conditional not part of composite actions: see actions/runner#834 * Replace action outputs with global environment variables * Easier to debug as printed in logs * If actions are if-conditioned to not execute, if already run, then their outputs will not exist whereas global env vars will. This makes it possible to retain the env vars while skipping repeated executions of the same actions
* If conditional not part of composite actions: see actions/runner#834 * Replace action outputs with global environment variables * Easier to debug as printed in logs * If actions are if-conditioned to not execute, if already run, then their outputs will not exist whereas global env vars will. This makes it possible to retain the env vars while skipping repeated executions of the same actions
why do one need to find this thread and not read it in the original documentation?! :( |
@foolioo it is being tracked here now github/docs#12378 |
…e action Now that [composite actions support conditionals](actions/runner#834 (comment)) we can consolidate more of the logic into the composite action
GitHub Actions finally fixed the issue, see actions/runner#834 (comment). This reverts #202.
GitHub Actions finally fixed the issue, see actions/runner#834 (comment). This reverts #202.
Does the if conditional not work for outputs of previous steps? For example:
This doesn't appear to actually run a conditional statement against the previous step's output and thus always runs. |
@AlexDHoffer it does work, although I have also had problems with matching on boolean EDIT: I think it's this one #1483 |
I found the following works:
While the below does not:
Is this the expected behavior? |
yes. This should also work.
|
Describe the enhancement
Add possibility to use
if:
option for action steps of composite actions.Code Snippet
The text was updated successfully, but these errors were encountered: