Skip to content
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

Explain how to unset failure code in composite actions #31356

Closed
1 task done
Tracked by #285
jsoref opened this issue Jan 30, 2024 · 5 comments
Closed
1 task done
Tracked by #285

Explain how to unset failure code in composite actions #31356

jsoref opened this issue Jan 30, 2024 · 5 comments
Labels
actions This issue or pull request should be reviewed by the docs actions team content This issue or pull request belongs to the Docs Content team help wanted Anyone is welcome to open a pull request to fix this issue stale There is no recent activity on this issue or pull request

Comments

@jsoref
Copy link
Contributor

jsoref commented Jan 30, 2024

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/actions/creating-actions/setting-exit-codes-for-actions

What part(s) of the article would you like to see updated?

In this article
About exit codes
Setting a failure exit code in a JavaScript action
Setting a failure exit code in a Docker container action

Add a section about composite actions -- specifically how to set a 0 exit code for cases where an intermediate step (actions/download-artifact being my canonical example) fail

Additional information

Here's a sample run: https://github.com/check-spelling-sandbox/composite-failures-0/actions/runs/7717700123/job/21037354247

workflow:

name: CI

on:
  push:
  pull_request:
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run action
        uses: ./

action

name: 'Hello World'
description: 'Greet someone'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  random-number:
    description: "Random number"
    value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
      shell: bash
    - run: echo "${{ github.action_path }}" >> $GITHUB_PATH
      shell: bash
    - run: goodbye.sh
      shell: bash
image

https://github.com/check-spelling-sandbox/composite-failures-0/actions/runs/7717700123/job/21037354247
image

@jsoref jsoref added the content This issue or pull request belongs to the Docs Content team label Jan 30, 2024
@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Jan 30, 2024
@nguyenalex836 nguyenalex836 added actions This issue or pull request should be reviewed by the docs actions team waiting for review Issue/PR is waiting for a writer's review and removed triage Do not begin working on this issue until triaged by the team labels Jan 31, 2024
@nguyenalex836
Copy link
Contributor

@jsoref Thanks for opening this issue! I'll get this triaged for review ✨

@ChristopherHX
Copy link

I know that you cannot unset an failure code, however composite action support continue-on-error for all run + uses steps (has been added way after uses support)

Then you can query the outcome yourself

SRC

https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context

name: 'Hello World'
description: 'Greet someone'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  random-number:
    description: "Random number"
    value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
      shell: bash
    - run: echo "${{ github.action_path }}" >> $GITHUB_PATH
      shell: bash
    - run: goodbye.sh
      shell: bash
      continue-on-error: true
      id: may-fail
    - run: echo ${{ steps.may-fail.outcome }}
      shell: bash
Prepare all required actions
##[group]Run ./
with:
  who-to-greet: World
##[endgroup]
##[group]Run echo Hello World.
echo Hello World.
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
Hello World.
##[group]Run echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
##[group]Run echo "/home/ubuntu/actions-runner-v2.283.4/_work/composite-action-with-continue-on-error/composite-action-with-continue-on-error/./" >> $GITHUB_PATH
echo "/home/ubuntu/actions-runner-v2.283.4/_work/composite-action-with-continue-on-error/composite-action-with-continue-on-error/./" >> $GITHUB_PATH
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
##[group]Run goodbye.sh
goodbye.sh
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
/home/ubuntu/actions-runner-v2.283.4/_work/_temp/31e0fff1-f95b-41a1-be92-bf1be82162fd.sh: line 1: goodbye.sh: command not found
##[error]Process completed with exit code 127.
##[group]Run echo failure
echo failure
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
failure

This step has conclusion success unless you decide to make another step let it fail

For me it looks like that composite action have almost no good documentation

@SiaraMist
Copy link
Contributor

Thanks for calling this out @jsoref!

I agree that it makes sense to add an example for how to set exit codes in composite actions to the end of this article. You or anyone is welcome to open a pull request to make that change!

@SiaraMist SiaraMist added help wanted Anyone is welcome to open a pull request to fix this issue and removed waiting for review Issue/PR is waiting for a writer's review labels Mar 5, 2024
@docs-bot docs-bot added this to Help wanted in Docs open source board Mar 5, 2024
@jsoref
Copy link
Contributor Author

jsoref commented Mar 6, 2024

Ok, here's the best I've managed:
https://github.com/check-spelling-sandbox/composite-failures-0/actions/runs/8173963274

image

https://github.com/check-spelling-sandbox/composite-failures-0/actions/runs/8173963274/job/22347615235

Prepare all required actions
Run ./
Run echo Hello World.
Hello World.
Run exit $(( $RANDOM % 2 ))
Error: Process completed with exit code 1.
Run echo step maybe-die outcome: $out
step maybe-die outcome: failure
Run echo goodbye
goodbye

Prepare all required actions
Run ./
Run echo Hello World.
Hello World.
Run exit $(( $RANDOM % 2 ))
Error: Process completed with exit code 1.
Run echo step maybe-die outcome: $out
step maybe-die outcome: failure
Run echo goodbye
goodbye

Prepare all required actions
Run ./
Run echo Hello World.
Hello World.
Run exit $(( $RANDOM % 2 ))
Run echo step maybe-die outcome: $out
step maybe-die outcome: success
Run echo goodbye
goodbye

Prepare all required actions
Run ./
Run echo Hello World.
Hello World.
Run exit $(( $RANDOM % 2 ))
Run echo step maybe-die outcome: $out
step maybe-die outcome: success
Run echo goodbye
goodbye

workflow:

name: CI

on:
  push:
  pull_request:
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Debug action
        run: grep -n . ./action.yml

      - name: Run action
        uses: ./
      - name: Run action
        uses: ./
      - name: Run action
        uses: ./
      - name: Run action
        uses: ./
      - name: Run action
        uses: ./
      - name: Run action
        uses: ./

action

name: 'Hello World'
description: 'Greet someone'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  random-number:
    description: "Random number"
    value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: maybe-die
      run: exit $(( $RANDOM % 2 ))
      shell: bash
      continue-on-error: true
    - run: echo true
      if: failure()
      shell: bash
    - if: failure() || success()
      shell: bash
      run: |
        echo step maybe-die outcome: $out
      env:
        out: ${{ steps.maybe-die.outcome }}
    - run: echo goodbye
      shell: bash

Note that as an action author, I do not want my random subprocesses' exit codes to appear in Annotations:

Annotations
3 errors
build
Process completed with exit code 1.
build
Process completed with exit code 1.
build
Process completed with exit code 1.

And I have no idea how to suppress that.

Or rather, I'm 99% confident that I just plain can't, which sucks:
https://github.com/actions/runner/blob/2c8c9416224ad5e9926626d1360311568eefefd1/src/Runner.Worker/Handlers/ScriptHandler.cs#L409

I think an extra flag for steps to suppress this output would go a long way. My action consumers would definitely appreciate that.

@jsoref
Copy link
Contributor Author

jsoref commented Mar 6, 2024

Here's the version of things I'm going to use as the basis of my documentation https://github.com/check-spelling-sandbox/composite-failures-0/actions/runs/8174941452

@github-actions github-actions bot added the stale There is no recent activity on this issue or pull request label May 6, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
Docs open source board automation moved this from Help wanted to Done May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions This issue or pull request should be reviewed by the docs actions team content This issue or pull request belongs to the Docs Content team help wanted Anyone is welcome to open a pull request to fix this issue stale There is no recent activity on this issue or pull request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants
@jsoref @ChristopherHX @SiaraMist @nguyenalex836 and others