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

3rd party tests conditional runs syntax #522

Open
Viicos opened this issue Dec 20, 2024 · 1 comment
Open

3rd party tests conditional runs syntax #522

Viicos opened this issue Dec 20, 2024 · 1 comment

Comments

@Viicos
Copy link
Contributor

Viicos commented Dec 20, 2024

Inspired by typing-extensions' third-party tests, we are doing something similar in Pydantic.

However, the conditional syntax we used (identical to yours) seems to not be working as expected with GHA. We ended up using the | syntax instead, fixed here: pydantic/pydantic#11162.

This might be why it was mentioned that the condition did not work as expected in ttps://github.com//pull/226. Happy to fix this.

@brianschubert
Copy link
Contributor

Nice catch!

I think using | might be a red herring. It seems the real culprit is/was the "comment" inside the if: condition, plus some differences in how GA evaluates conditions depending on whether the ${{ }} expression syntax is used or not.

From what I can tell, if you use ${{ }} in the condition expression, then any extra non-space characters (including newlines!) outside ${{ }} cause the condition to always evaluate to true.

In particular, all of the following conditions don't work and always evaluate to true:

# Bad: extra characters outside ${{ }}
if: |
  # I'm not actually a comment
  ${{ false }}

# Bad: extraneous blank lines outside ${{ }}
if: >-

  ${{ false }}

# Bad: trailing newline outside ${{ }}
if: |
  ${{ false }}

But these work:

# Good: no issues with single line
if: ${{ false }}

# Good: '-' need to strip trailing newline when using ${{ }}.
# Using `|-` also seems to work.
if: >-
  ${{ 
                 false   &&   'anything goes here!'
  }}

# Good: newlines don't matter when ${{ }} is omitted
if: |
   
  false

Here's a workflow run demonstrating all the variants I could think of: https://github.com/brianschubert/typing_extensions/actions/runs/12439837061

workflow file
on: [ push ]

permissions:
  contents: read

jobs:
  single-line:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: ${{ false }}

  pipe:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |
      ${{ false }}

  pipe-comment:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |
      # foo
      ${{ false }}

  pipe-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |

      ${{ false }}

  pipe-dash:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |-
      ${{ false }}

  pipe-dash-comment:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |-
      # foo
      ${{ false }}

  pipe-dash-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |-

      ${{ false }}

  bracket:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >
      ${{ false }}

  bracket-comment:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >
      # foo
      ${{ false }}

  bracket-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >

      ${{ false }}

  bracket-dash:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >-
      ${{ false }}

  bracket-dash-comment:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >-
      # foo
      ${{ false }}

  bracket-dash-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >-

      ${{ false }}

  omit-single-line:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: false

  omit-pipe:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |
      false

#  # Invalid workflow syntax.
#  omit-pipe-comment:
#    runs-on: ubuntu-latest
#    steps: [ run: true ]
#    if: |
#      # foo
#      false

  omit-pipe-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |

      false

  omit-pipe-dash:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |-
      false

#  # Invalid workflow syntax.
#  omit-pipe-dash-comment:
#    runs-on: ubuntu-latest
#    steps: [ run: true ]
#    if: |-
#      # foo
#      false

  omit-pipe-dash-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: |-

      false

  omit-bracket:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >
      false

#  # Invalid workflow syntax.
#  omit-bracket-comment:
#    runs-on: ubuntu-latest
#    steps: [ run: true ]
#    if: >
#      # foo
#      false

  omit-bracket-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >

      false

  omit-bracket-dash:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >-
      false

#  # Invalid workflow syntax.
#  omit-bracket-dash-comment:
#    runs-on: ubuntu-latest
#    steps: [ run: true ]
#    if: >-
#      # foo
#      false

  omit-bracket-dash-blank:
    runs-on: ubuntu-latest
    steps: [ run: true ]
    if: >-

      false

I think the right fix would be to move the "comment" to outside the if: condition and to omit the ${{ }} syntax. It looks like the expression should work without ${{ }}, and not using ${{ }} removes all issues with whitespace potentially making the expressions always true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants