在 Github 操作管道上使用超时语法中的变量

Use variables in Timeout syntax on Github action pipeline

我想在 GitHub 个操作步骤中使用一些变量来设置值。

Environment variables 告诉我们可以在您的工作流程文件中设置自定义环境变量。

By default, Linux runners use the bash shell, so you must use the syntax $NAME.

所以我试试

name: Workflow

on:
  push:
    branches:
    - main
  pull_request:

env:
  General_Timeout_Minutes: 15

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    env:
      Setup_Timeout_Minutes: 10
      Lint_Timeout_Minutes: $General_Timeout_Minutes
      Unit_Test_Timeout_Minutes: $General_Timeout_Minutes
      E2E_Timeout_Minutes: $General_Timeout_Minutes
    steps:
      - uses: actions/checkout@v2

      - name: Setup
        timeout-minutes: $Setup_Timeout_Minutes
        run: npm install

      - name: Lint JavaScript
        timeout-minutes: $Lint_Timeout_Minutes
        run: npm run lint

      - name: Run JavaScript tests
        timeout-minutes: $Unit_Test_Timeout_Minutes
        run: npm run unit-test

      - name: Run end-to-end browser tests
        timeout-minutes: $E2E_Timeout_Minutes
        run: npm run e2e-test

  deploy:
    ...

但是,GitHub 操作开始失败

The workflow is not valid. .github/workflows/test.yml: Unexpected value '$Setup_Timeout_Minutes' .github/workflows/test.yml: Unexpected value '$Lint_Timeout_Minutes'

如何在timeout-minutes语法中使用变量?

在GitHub社区询问并做了一些测试后,我得到了最终答案。

这里是 discussion link.

name: Workflow

on:
  push:
    branches:
    - main
  pull_request:

env:
  General_Timeout_Minutes: 15

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    env:
      Setup_Timeout_Minutes: 10
    steps:
      - uses: actions/checkout@v2

      # Set job level environment variables from global ones
      - name: "Set job env from global env"
        run: |
          echo "Lint_Timeout_Minutes=$General_Timeout_Minutes" >> $GITHUB_ENV
          echo "Unit_Test_Timeout_Minutes=$General_Timeout_Minutes" >> $GITHUB_ENV
          echo "E2E_Timeout_Minutes=$General_Timeout_Minutes" >> $GITHUB_ENV

      - name: Setup
        timeout-minutes: ${{ fromJSON(env.Setup_Timeout_Minutes) }}
        run: npm install

      - name: Lint JavaScript
        timeout-minutes: ${{ fromJSON(env.Lint_Timeout_Minutes) }}
        run: npm run lint

      - name: Run JavaScript tests
        timeout-minutes: ${{ fromJSON(env.Unit_Test_Timeout_Minutes) }}
        run: npm run unit-test

      - name: Run end-to-end browser tests
        timeout-minutes: ${{ fromJSON(env.E2E_Timeout_Minutes) }}
        run: npm run e2e-test

  deploy:
    ...