【问题标题】:Github Actions Build Matrix For Lambda FunctionsGithub Actions 为 Lambda 函数构建矩阵
【发布时间】:2020-12-10 12:54:01
【问题描述】:

寻找有关为文件夹中的每个 lambda 函数启动一组并行 Github 操作的最佳方式的建议。所以文件夹结构是这样的:

lambdas/example1/index.js
lambdas/example2/index.js

....

然后将它们传递给这个矩阵设置

  deploy_source:
name: Deploy Lambda From Source
runs-on: ubuntu-latest
strategy:
  matrix:
    lambdafile:['example1/index.js','example12/index.js',....]
steps:
  - name: checkout source code
    uses: actions/checkout@v1
  - name: default deploy
    uses: appleboy/lambda-action@master
    with:
      aws_access_key_id: '123123123123'
      aws_secret_access_key: '123123123123'
      aws_region: '123123123123'
      function_name: gorush
      source: ${{ matrix.lambdafile }}

【问题讨论】:

  • 不清楚你在问什么。您使用matrix 发布的工作流程不起作用吗?你只是问有没有更好的方法?使用matrix 是启动并行作业的好方法。

标签: github-actions


【解决方案1】:

您可以创建 job1 来读取您的文件夹并根据该数据动态创建矩阵数组。然后创建第二个作业来收集动态矩阵并使用它。

这是 lambda 目录中每个文件的动态文件矩阵数组的示例工作流程

 name: build
 on: push
 jobs:
   job1:
     runs-on: ubuntu-latest
     outputs:
        matrix: ${{ steps.setmatrix.outputs.matrix }}
     steps:
     - name: checkout source code
       uses: actions/checkout@v1
     - id: setmatrix
       run: |
         matrixArray=$(find ./lambdas -name '*.js') # Creates array of all files .js withing lambdas
         # Start Generate Json String
         echo "$matrixArray" | \
         jq --slurp --raw-input 'split("\n")[:-1]' | \
         jq  "{\"filepath\": .[] }" | \
         jq -sc "{ \"include\": . }" > tmp
         cat ./tmp
         # End Generate Json String
         matrixStringifiedObject=$(cat ./tmp) # Use this as jq @sh wasn't cooperating
         echo "::set-output name=matrix::$matrixStringifiedObject"
   job2:
     needs: job1
     runs-on: ubuntu-latest
     strategy:
       matrix: ${{fromJson(needs.job1.outputs.matrix)}}
     steps:
      - name: checkout source code
        uses: actions/checkout@v1
      - run: echo ${{ matrix.filepath }}

Sample workflow run

Pipeline code repo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-19
    • 2021-04-29
    • 1970-01-01
    • 2021-12-29
    • 2022-11-25
    • 2020-05-15
    • 2020-04-26
    • 2019-12-24
    相关资源
    最近更新 更多