Skip to content

Instantly share code, notes, and snippets.

@xiaomi7732
Created March 9, 2023 21:19
Show Gist options
  • Save xiaomi7732/f8fa6c0ea5528310c70fad5687aeeefd to your computer and use it in GitHub Desktop.
Save xiaomi7732/f8fa6c0ea5528310c70fad5687aeeefd to your computer and use it in GitHub Desktop.
Matrix + if condition in GitHub action

Shorthand:

if: matrix.project == 'src/OPI.WebAPI'

Full example:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        project: [
          'src/OPI.Client',
          'src/OPI.WebAPI',
          'src/OPI.WebUI'
        ]
    steps:
      - uses: actions/checkout@v3

      - name: Setup .NET Core SDK ${{ env.DOTNET_VERSION }}
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}

      - name: Restore NuGet packages
        run: dotnet restore ${{ matrix.project }}

      - name: Build
        run: dotnet build ${{ matrix.project }} --configuration Release --no-restore

      - name: Build docker image for the WebAPI
        uses: docker/build-push-action@v4
        if: matrix.project == 'src/OPI.WebAPI'
        with:
            push: false
            tags: pr/opiapi:latest
            context: src/
            file: src/dockerfile.webapi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment