【问题标题】:Run Github-Actions Step On Single Version在单个版本上运行 Github-Actions Step
【发布时间】:2021-05-09 04:01:27
【问题描述】:

我有一个 GA 工作流程来部署我的 React 应用 here。它在三个单独的 NodeJS 版本的矩阵上运行 checkout/install/build/test 步骤,然后运行部署。我担心的是,鉴于矩阵,这将尝试运行部署三次,这可能会导致问题。有没有好的方法来过滤最后一步,让它只运行一次?

我目前的最佳猜测是将第 30-32 行更改为以下内容,但我不确定它是否能正常工作。

- name: Deploy
        if: matrix.node-version == '10.x' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
        run: | ...

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    添加仅在 1 个节点版本上运行的单独部署作业和 needs 之前的矩阵作业(包含结帐/安装/测试)以成功。我还将您的第一份工作重命名为 test,因为这样更准确地说明了它的作用。

    jobs:
      test:
        runs-on: ubuntu-latest
    
        strategy:
          matrix:
            node-version: [10.x, 12.x, 14.x]
    
        steps:
          - uses: actions/checkout@v2
          - name: Use Node.js ${{ matrix.node-version }}
            uses: actions/setup-node@v1
            with:
              node-version: ${{ matrix.node-version }}
          - run: npm ci
          - run: npm run build --if-present
          - run: npm test
    
      deploy:
        runs-on: ubuntu-latest
        needs: test
        steps:
          - uses: actions/checkout@v2
          # might need build steps here, I'm not 100% certain on your npm config
          - name: Deploy
            if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
            run: |
              git config --global user.name $user_name
              git config --global user.email $user_email
              git remote set-url origin https://${github_token}@github.com/${repository}
              npm run deploy
            env:
              user_name: "github-actions[bot]"
              user_email: "github-actions[bot]@users.noreply.github.com"
              github_token: ${{ secrets.ACTIONS_DEPLOY_ACCESS_TOKEN }}
              repository: ${{ github.repository }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 2021-04-26
      • 2020-02-03
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多