Created
March 21, 2023 08:49
-
-
Save wyozi/e20ff80e9d09c28b0a0daead7055c9a2 to your computer and use it in GitHub Desktop.
Github action to deploy all serverless functions in a folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy serverless functions | |
on: | |
push: | |
paths: | |
- "functions/**" | |
branches: | |
- "main" | |
jobs: | |
list-functions: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v3 | |
- id: set-matrix | |
run: echo "matrix=$(ls functions | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
deploy: | |
needs: list-functions | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
function: ${{ fromJson(needs.list-functions.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18" | |
- name: Install yq | |
run: | | |
sudo snap install yq | |
- name: Setup serverless | |
run: | | |
npm i -g serverless | |
- name: Install plugins | |
working-directory: functions/${{ matrix.function }} | |
run: | | |
yq '.plugins[]' serverless.yml | xargs -L1 serverless plugin install -n | |
- name: Deploy | |
run: serverless deploy -s prod | |
working-directory: functions/${{ matrix.function }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment