Wandalen / wretry.action

Retry action for Github CI
MIT License
93 stars 20 forks source link

Getting "Error: Expects non-primitive" when using multiple multiline fields #122

Closed darkxeno closed 6 months ago

darkxeno commented 10 months ago

Example inputs used, gathered from github action logs:

Wandalen/wretry.action@v1.0.36
  with:
    action: docker/build-push-action@v3
    attempt_limit: 2
    attempt_delay: 2000
    with: file: ./Dockerfile
  tags: ***.dkr.ecr.us-east-1.amazonaws.com/IMAGE_NAME:8771665,***.dkr.ecr.us-east-1.amazonaws.com/IMAGE_NAME:latest
  context: ./.
  load: true
  push: false
  cache-from: type=registry,ref=***.dkr.ecr.us-east-1.amazonaws.com/IMAGE_NAME:latest
  cache-to: type=inline
  ssh: |

  build-args: |
    ***

  env:
    AWS_DEFAULT_REGION: us-east-1
    AWS_REGION: us-east-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
    AWS_SESSION_TOKEN: ***

Error: Error: Expects non-primitive

The same error happens on the post run step.

Post job cleanup.
Post job cleanup.
Post job cleanup.
Error: Expects non-primitive
Post job cleanup.
Logging out of registry ***.dkr.ecr.us-east-1.amazonaws.com
Post job cleanup.
Post job cleanup.
Removing builder
Cleaning up certificates

Using the same action docker/build-push-action@v3 without "Wandalen/wretry.action@v1.0.36" works as expected.

Any idea about what could be wrong? somehow seem to only be happening with multiline fields.

dmvict commented 10 months ago

Hello @darkxeno

The action is sensible to indentations in with input. I believe that the problem is in indentations. Please, replace first part with:

- uses: Wandalen/wretry.action@v1.0.36
  with:
    action: docker/build-push-action@v3
    attempt_limit: 2
    attempt_delay: 2000
    with: |
      file: ./Dockerfile
      tags: ***.dkr.ecr.us-east-1.amazonaws.com/IMAGE_NAME:8771665,***.dkr.ecr.us-east-1.amazonaws.com/IMAGE_NAME:latest
      context: ./.
      load: true
      push: false
      cache-from: type=registry,ref=***.dkr.ecr.us-east-1.amazonaws.com/IMAGE_NAME:latest
      cache-to: type=inline
      ssh: |

      build-args: |
        ***

Take care about indentations in field ssh and build-args. Use example from the documentation, please.

Also, I fixed line with: file: ./Dockerfile. Now the line looks like

      with: | 
        file: ./Dockerfile`
darkxeno commented 10 months ago

Thanks for the fast response @dmvict

What i pasted above was obtained from the github action logs.

This is what i was using on the pipelines yaml, i think this is correctly indented.

    - name: Build image ${{ inputs.image_name }}
      uses: Wandalen/wretry.action@v1.0.36
      with:
        action: docker/build-push-action@v3
        attempt_limit: 2
        attempt_delay: 2000
        with: |
          file: ${{ inputs.repo_path }}/${{ inputs.dockerfile }}
          tags: ${{ steps.set-variables.outputs.IMAGE_URL_WITH_TAG }},${{ steps.set-variables.outputs.IMAGE_URL_WITH_LATEST }}
          context: ${{ inputs.repo_path }}/${{ inputs.context }}
          load: ${{ inputs.push != 'true' }}
          push: ${{ inputs.push }}
          cache-from: type=registry,ref=${{ steps.set-variables.outputs.IMAGE_URL_WITH_LATEST }}
          cache-to: type=inline
          ssh: |
            ${{ inputs.ssh_private_key != '' && format('default={0}', env.SSH_AUTH_SOCK) || '' }}
          build-args: |
            ${{ inputs.build_args }}

Thanks for the support.

dmvict commented 10 months ago

Hello @darkxeno

Yes, the inputs seems to be correct. Please, check that all inputs are singleline or update indentations for multiline inputs. For example, if your build-args input is

--arg1 arg
-- arg2 arg

Then the input will be formatted as

build-args: | 
  --arg1 arg
--arg2 arg

but the actions expects that the second line has same indentation as the first one (or bigger).

darkxeno commented 10 months ago

i think i get your point, as we are using | as part of a string, its probably not indenting multiline strings automatically?

the values of build-args is original constructed like this on the input of the custom action:

build_args: |
  ENV_VAR1=value1
  ENV_VAR2=value2

and after that provided as the variable ${{ inputs.build_args }} to this action

So you mean if i some force the correct indentation to all lines should be working properly?

Thanks again @dmvict

dmvict commented 10 months ago

Hello @darkxeno

I think it should work. The best way is to create experimental workflow with public data and hardcoded values.

mycarrysun commented 7 months ago

I'm getting the same issue - here is what I'm using in the workflow:

    - name: Build image
      uses: Wandalen/wretry.action@v1.3.0
      with:
        action: docker/build-push-action@v3
        with: |
          context: .
          target: ${{ inputs.build-target }}
          file: ${{ inputs.dockerfile }}

And here's what shows in the github actions log output as what is being passed to the Wandalen/wretry.action action:

Run Wandalen/wretry.action@v1.3.0_js_action
  with:
    action: docker/build-push-action@v3
    with: context: .
    target: release
    file: docker/Dockerfile.backend

So somehow there is a problem with indentation. I have also tried an extra set of indentation after the first line in the with multiline string but got the same result:

    - name: Build image
      uses: Wandalen/wretry.action@v1.3.0
      with:
        action: docker/build-push-action@v3
        with: |
          context: .
            target: ${{ inputs.build-target }}
            file: ${{ inputs.dockerfile }}

I think there is a bug in the action code somewhere.

dmvict commented 7 months ago

Hello @mycarrysun

I hope I'll find a time to check and fix the issue.

dylanmtaylor commented 7 months ago

Hello @dmvict. I am trying to use this action and am getting the same error. I tried to make a PR to add this action to universal blue's build process at https://github.com/ublue-os/main/pull/503 and I am seeing this "Error: Expects non-primitive" issue.

dylanmtaylor commented 6 months ago

This seems related to the amount of left indenting on a multi-line string.

dmvict commented 6 months ago

Hello @dylanmtaylor

Yes, the indentations are important. I'm improving the logic for commands and I hope it will be published soon.

dmvict commented 6 months ago

Hello @dylanmtaylor @mycarrysun @darkxeno

Can you try new version of the action? I improved a parser a time ago.

mycarrysun commented 6 months ago

I have a different error now, seems like it won't work for private repo github actions.

Screen Shot 2024-03-06 at 11 11 43 AM
dmvict commented 6 months ago

Hello @mycarrysun

Thank you for report. Please, open new issue for the error. I'll try to find a time to solve it.