runner icon indicating copy to clipboard operation
runner copied to clipboard

`Index was out of range` in local composite action poststeps

Open sethrylan opened this issue 2 years ago • 2 comments

Describe the bug

Invoke a local composite action like

    - uses: ./.github/actions/composite

The post steps fail with

Error: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

To Reproduce

Create a workflow

## file: .github/workflow/poststeps.yaml
on:
  workflow_dispatch:
    inputs:
      ref_one:
        type: string
        description: "The git ref to checkout"
        default: main
jobs:
  run:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: ./.github/actions/composite
      with:
        ref: ${{ inputs.ref_one }}
    - uses: ./.github/actions/composite

Create a composite action that invokes actions/checkout

## file: .github/actions/composite/action.yaml
name: 'Hello World'
inputs:
  ref:
    description: The git ref to checkout
    required: true
runs:
  using: "composite"
  steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ inputs.ref }}
    - run: echo Hello "${{ inputs.ref }}" >> $GITHUB_STEP_SUMMARY
      shell: bash

After creating the files, create the tag v1.

Then update the composite action to change the number of steps.

cat << EOF >> .github/actions/composite/action.yaml
    - run: echo Hello Again "${{ inputs.ref }}" >> $GITHUB_STEP_SUMMARY
      shell: bash
EOF

Run the workflow with input ref=v1

Expected behavior

Expect the poststeps to not fail.

Runner Version and Platform

Current runner version: '2.308.0'
Operating System
  Ubuntu
  22.04.3
  LTS
Runner Image
  Image: ubuntu-22.04
  Version: 20230821.1.0
  Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230821.1/images/linux/Ubuntu2204-Readme.md
  Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230821.1

What's not working?

Post steps fail, which causes workflow status to fail.

Job Log Output

##[debug]Evaluating condition for step: 'Post Run /./.github/actions/composite'
##[debug]Evaluating: always()
##[debug]Evaluating always:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Post Run /./.github/actions/composite
Error: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
##[debug]System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
##[debug]   at GitHub.Runner.Worker.ActionManager.LoadAction(IExecutionContext executionContext, ActionStep action)
##[debug]   at GitHub.Runner.Worker.ActionRunner.RunAsync()
##[debug]   at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
##[debug]Finishing: Post Run /./.github/actions/composite

Workarounds

This error is caused by a mismatch in the cached number of steps for the local composite action. Calling checkout causes the number of steps to change, which creates the error. To workaround...

  1. Avoid calling checkout in local composite actions, or ensure that checkout is always called with the same version.
  2. Call the action as a global composite action (e.g., uses: user/repo/.github/actions/composite@main)

sethrylan avatar Sep 01 '23 18:09 sethrylan

could be related to

  • #2009
  • #2800

Those are problems with the provided contextdata like inputs and steps in post steps of local composite actions. Althought I had no exception thrown by the runner so far.

I think it is good to make those problems of local composite actions more visible

ChristopherHX avatar Sep 01 '23 20:09 ChristopherHX

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 15 days.

github-actions[bot] avatar Sep 09 '24 00:09 github-actions[bot]

Ran into this issue today and it is horrible mostly because you do not understand what is wrong - you search for problems in your workflow and not for internal problems in actions.

We have a build where we compare screenshots from a PR branch to screenshots from the target branch to see what has changed. To avoid storing and updating screenshots, one job in the build creates screenshots from the PR branch and another job checks out the target branch and runs the same screenshots for that.

Now this all works fine until today when I wanted to remove one extra step from a global "setup" composite. Apparently the post action uses the cache from the target branch where it then has a different number of steps, and it fails with the cryptic C# "Index was out of range" error message.

After force merging the update to the "setup" composite, it all works properly again.

Artur- avatar Sep 26 '24 06:09 Artur-

Hi we are having an issue very similar to what Artur had above, but we cannot merge the changes to the setup composite yet, which makes this very tricky

Is there any other workaround here?

inoa-jboliveira avatar Oct 08 '25 19:10 inoa-jboliveira

Is there any other workaround here?

Do not modify the action.yml file of a executed composite action with any post step.

Do not use actions/checkout after using / inside a local composite action.

If this is not an option pass path: to actions/checkout and specify a different clone folder, then update all users to look for the path below your workspace.

you could also copy the composite actions folder via cp -R one folder up, so checkout would not override it. Then update to - uses: ./../.github/actions/test (idk about what level of long term support this feature, i.e. unchecked path in uses has


I think we cannot expect any movement in near future, e.g. cache the action.yml file instead of reading it from disk and failing when something is odd.

ChristopherHX avatar Oct 08 '25 20:10 ChristopherHX