0
votes

Looking for suggestions on the best way to kick off a set of parallel Github actions for each lambda function in a folder. So folder structure is like:

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

....

and then pass them through to this matrix setup

  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 }}
1
It's not clear what you are asking. Does the workflow you posted using matrix not work? Are you just asking if there is a better way? Using matrix is a good way to kick off parallel jobs. - peterevans

1 Answers

1
votes

You can create job1 to read your folder and create your matrix array dynamically from that data. And then create a second job to gather the dynamic matrix and use it.

Here is the sample workflow for dynamic file matrix array per files in directory 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