GitHub动作:如何有条件地切换运行命令?

问题描述 投票:0回答:1

我创建了包含这2个工作的工作流程:

  build-and-test-with-Java-8-and-later:
    name: Build -> Test (JVM ${{ matrix.java }}, ${{ matrix.architecture }}, ${{ matrix.os }})
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
        java: [8, 9, 10, 11, 12, 13, 14]
        architecture: [x32, x64]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java }}
          architecture: ${{ matrix.architecture }}  
      - name: Build and test
        run: mvn -B clean test -Dproject_jdk_version=${{ matrix.java }} -DskipTests=false --file pom.xml

  build-and-test-with-Java-15-ea:
    name: Build -> Test (JVM ${{ matrix.java }}, ${{ matrix.architecture }}, ${{ matrix.os }})
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
        java: [15-ea]
        architecture: [x32, x64]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java }}
          architecture: ${{ matrix.architecture }}  
      - name: Build and test
        run: mvn -B clean test -Dproject_jdk_version=15 -DskipTests=false --file pom.xml

...而且我想将这两个作业合并到一个唯一的作业中,该作业在迭代$ {{matrix.java}}变量包含后缀-ea时切换运行元素。特别是我想创建这样的东西:

  build-and-test-with-Java-8-and-later:
    name: Build -> Test (JVM ${{ matrix.java }}, ${{ matrix.architecture }}, ${{ matrix.os }})
    strategy:
      fail-fast: true
      max-parallel: 10
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
        java: [8, 9, 10, 11, 12, 13, 14, 15-ea]
        architecture: [x32, x64]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v1
        with:
          java-version: if${{ matrix.java }}
          architecture: ${{ matrix.architecture }}  
      - name: Build and test
        if: ${{ matrix.java }} != '15-ea'
        run: mvn -B clean test -Dproject_jdk_version=${{ matrix.java }} -DskipTests=false --file pom.xml
      - name: Build and test
        if: ${{ matrix.java }} == '15-ea'
        run: mvn -B clean test -Dproject_jdk_version=15 -DskipTests=false --file pom.xml
workflow jobs github-actions step
1个回答
0
投票

您可以使用Githu Actions中可用的function之一。

在您的情况下,它将起作用:

- name: Build and test
   if: contains(matrix.java, '15-ea')
   run: mvn -B clean test -Dproject_jdk_version=${{ matrix.java }} -DskipTests=false --file pom.xml
© www.soinside.com 2019 - 2024. All rights reserved.