Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从github中的矩阵触发单个部署挂钩?_Github_Github Actions - Fatal编程技术网

如何从github中的矩阵触发单个部署挂钩?

如何从github中的矩阵触发单个部署挂钩?,github,github-actions,Github,Github Actions,所以我有这个矩阵 name: test on: [create, push] jobs: build: strategy: matrix: context: [test, pgtest] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: docker compose run: | docker-c

所以我有这个矩阵

name: test

on: [create, push]

jobs:
  build:
    strategy:
      matrix:
        context: [test, pgtest]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: docker compose
        run: |
          docker-compose -f docker-compose.${{ matrix.context }}.yml up -d
          docker ps
      - name: install liquibase
        run: |
          wget --quiet https://github.com/liquibase/liquibase/releases/download/v3.8.4/liquibase-3.8.4.tar.gz
          wget --quiet https://jdbc.postgresql.org/download/postgresql-42.2.9.jar
          mkdir -p liquibase
          tar --extract --file liquibase-*.tar.gz --directory liquibase
      - name: wait for dbs
        run: |
          set -x
          wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
          chmod +x wait-for-it.sh
          ./wait-for-it.sh localhost:5432
          docker pull postgres:alpine
          isReady() {
            docker run --network host --rm postgres:alpine pg_isready \
              --host localhost --dbname test --username postgres --timeout 30
          }
          until isReady
          do
            sleep 1
          done
      - name: db migration
        run: |
          ./liquibase/liquibase --defaultsFile=liquibase-${{ matrix.context }}.properties update \
          || ( docker-compose logs && exit 1)
矩阵的唯一目的是测试不同的上下文是否存在液化。我实际上不想为每个矩阵或类似的东西创建不同的二进制文件。我把matrix看作是一种线程分叉,但我不知道如何在最后加入,这样我就可以启动一个部署事件

我认为继续跑应该允许我这样做,但是。。。似乎也不会触发


在整个矩阵运行之后,如何启动单个部署事件?

我看到了两种实现方法:

  • 将当前矩阵拆分为两个作业,并使部署挂钩依赖于
    test
    作业。这样,
    test
    pgtest
    并行运行,当
    test
    完成时,部署将开始。这种方法的问题在于代码的可读性和维护性,因为除非您将代码封装到一个动作本身中,否则代码将被完全复制,这是一种极端的过度杀伤力
  • 将部署挂钩作为
    测试的最后一个条件步骤运行。考虑到您提出的问题,这似乎是最好的选择,但在某些情况下,这本身并不是最佳选择
    解决方案(2)的最后一步如下所示

    - name: Deployment
      if: matrix.context == 'test'
      run: echo "Do something"
    

    希望这能有所帮助。

    如果我正确理解您的需求,您可以添加另一个作业,该作业取决于使用
    需求
    生成包含矩阵的
    作业。它将等待所有矩阵作业完成,然后再运行
    deploy

    on: push
    jobs:
      build:
        strategy:
          matrix:
            context: [test, pgtest]
        runs-on: ubuntu-latest
        steps:
          - name: Tests
            run: echo "Testing ${{ matrix.context }}"
    
      deploy:
        needs: build
        runs-on: ubuntu-latest
        steps:
          - name: Deploy
            run: echo "Deploying"
    

    也许可以为您完成解决方案?

    hmm。。。当您说部署钩子依赖于测试作业时,您的意思是什么?我认为这与在选项2中进行另一次串行运行有所不同。但这两种方法都不理想,因为我认为它们都不需要等待成功完成。github建议有一种方法可以做到这一点,但我看不到。您对问题进行了编辑,将问题从测试矩阵运行后的
    完全更改为整个矩阵运行后的
    。如果这是你想要的,那么@peterevans在这里发布的另一个答案就是正确的答案。