首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单一版本上运行Github-Actions步骤

在单一版本上运行Github-Actions步骤
EN

Stack Overflow用户
提问于 2021-02-05 03:36:27
回答 1查看 169关注 0票数 2

我有一个GA工作流程来部署我的React应用here。它在由三个独立的NodeJS版本组成的矩阵上运行签出/安装/构建/测试步骤,然后运行部署。我担心的是,根据矩阵,这将尝试运行部署三次,这可能会导致问题。有没有好的方法来过滤最后一步,让它只运行一次?

我目前最好的猜测是将30-32行更改为下面的行,但我不确定它是否能正确工作。

代码语言:javascript
复制
- name: Deploy
        if: matrix.node-version == '10.x' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
        run: | ...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-05 03:52:49

添加一个仅在1个节点版本上运行的单独部署作业,并对上一个矩阵作业(包含needs /install/Test.)进行测试以使其成功。我还将您的第一个工作重命名为test,因为这更准确地描述了它所做的事情。

代码语言:javascript
复制
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 }}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66052643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档