Skip to content

Allow if Blocks in steps #677

@fchorney

Description

@fchorney

Describe the enhancement
I'm finding that it is quite annoying to have to define an if condition for every single item in the steps section of a test matrix. It would be great if you could define a block per se

Code Snippet
For instance, let's say I have a setup like so

      # Linux
      - name: Wait / Sleep
        uses: jakejarvis/wait-action@v0.1.0
        if: ${{ runner.os == 'Linux' }}
        with:
          time: '1m'
      - name: Collect Docker Logs
        uses: jwalton/gh-docker-logs@v1.0.0
        if: ${{ runner.os == 'Linux' }}
      - name: Check running containers
        run: docker ps -a
        if: ${{ runner.os == 'Linux' }}
      - name: Set PGHOST on Linux
        run: echo "PGHOST=localhost" >> $GITHUB_ENV
        if: ${{ runner.os == 'Linux' }}
      # MacOS
      - name: Set PGUSER on macOS
        run: |
          echo "PGUSER=$USER" >> $GITHUB_ENV
          echo "LIBPQJL_DATABASE_USER=$USER" >> $GITHUB_ENV
        if: ${{ runner.os == 'macOS' }}
      - name: Start Homebrew PostgreSQL service
        run: pg_ctl -D /usr/local/var/postgres start
        if: ${{ runner.os == 'macOS' }}
      # Windows
      - name: Add PostgreSQL to Path
        run: |
          echo $env:PGBIN
          echo $env:PGBIN | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
        if: ${{ runner.os == 'Windows' }}
      - name: Start Windows PostgreSQL service
        run: |
          pg_ctl -D $env:PGDATA start
          pg_ctl -D $env:PGDATA status
        if: ${{ runner.os == 'Windows' }}

It would be awesome if it could be formatted like so:

      # Linux
      - if: ${{ runner.os == 'Linux' }}
        - name: Wait / Sleep
          uses: jakejarvis/wait-action@v0.1.0
          with:
            time: '1m'
        - name: Collect Docker Logs
          uses: jwalton/gh-docker-logs@v1.0.0
        - name: Check running containers
          run: docker ps -a
        - name: Set PGHOST on Linux
          run: echo "PGHOST=localhost" >> $GITHUB_ENV
      # MacOS
      - if: ${{ runner.os == 'macOS' }}
        - name: Set PGUSER on macOS
          run: |
            echo "PGUSER=$USER" >> $GITHUB_ENV
            echo "LIBPQJL_DATABASE_USER=$USER" >> $GITHUB_ENV
        - name: Start Homebrew PostgreSQL service
          run: pg_ctl -D /usr/local/var/postgres start
      # Windows
      - if: ${{ runner.os == 'Windows' }}
        - name: Add PostgreSQL to Path
          run: |
            echo $env:PGBIN
            echo $env:PGBIN | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
        - name: Start Windows PostgreSQL service
          run: |
            pg_ctl -D $env:PGDATA start
            pg_ctl -D $env:PGDATA status

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions