Github 动作矩阵问题

Github Actions matrix questions

我只想在 INT、STG 环境的 Matrix 中 运行,对于每个环境,我都需要更长的名称(集成、分期)。

这件事在 github 行动中可能吗?我在 sytanx 中遗漏了什么吗? 我试着四处寻找它,但找不到它..

Test:
 name: Deploy Test
 runs-on: ${{matrix.env}}
 strategy:
 matrix:
 env: [int, stg]
 needs: 
      - 'jobA'
      - 'jobB'

 steps:
    - name: Create test things.
 env: 
 ENVIRONMENT: 'if github.runs-on == int; then $ENVIRONMENT=integration else $ENVIRONMENT=staging' 
    - name: Test
 run: |
           some command using ${{env.ENVIRONMENT}} 
          - Desired output is integration

           some command using ${{env.ENVIRONMENT}}
          - Desired output is staging

感谢任何愿意提供帮助的人!

runs-on 用于指定机器名称 - 您不应在此处放置任何自定义字符串。

正确的格式如下:

Test:
 name: Deploy Test
 runs-on: ubuntu-latest
 strategy:
     matrix:
         env: [int, stg]
 needs: 
      - 'jobA'
      - 'jobB'
 steps:
    - name: Create test things.
    - uses: haya14busa/action-cond@v1
      id: env_name
      with:
        cond: ${{ matrix.env == 'int' }}
        if_true: "integration"
        if_false: "staging"
    - name: Test environment name
      run: |
           some command using ${{ matrix.env }} #int / stg will be passed
           echo ${{ steps.env_name.outputs.value }} # will output integration for int, staging for stg
     - name: Test Staging Only
      if: matrix.env == 'stg'
      run: |
           some command using ${{ matrix.env }} #stg only, skipped for int
           # This only executes for staging