feat: deploying resources to AWS via GH actions #2
This file contains 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: example dir `deployment-with-github-actions` deployment | |
on: | |
push: | |
branches: | |
- main # run the workflow when a push is made to the main branch | |
paths: | |
- 'deployment-with-github-actions/**' | |
pull_request: | |
branches: | |
- main # run the workflow when the target branch of the PR is main | |
paths: | |
- 'deployment-with-github-actions/**' | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
env: | |
AWS_REGION : 'eu-west-2' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: ⬇️ Checkout repo | |
uses: actions/checkout@v4 | |
- name: ⎔ Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Install dependencies | |
working-directory: ./deployment-with-github-actions | |
run: npm ci | |
- name: Unit test | |
working-directory: ./deployment-with-github-actions | |
run: npm run test | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Git clone the repository | |
uses: actions/checkout@v4 | |
- name: ⎔ Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Install dependencies | |
working-directory: ./deployment-with-github-actions | |
run: npm ci | |
- name: configure aws credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::552686430014:role/github-actions-ci-cd-deployment-role | |
role-session-name: github-action-sls-examples | |
aws-region: ${{ env.AWS_REGION }} | |
- name: versions | |
working-directory: ./deployment-with-github-actions | |
run: | | |
pwd | |
node -v | |
aws --version | |
sls --version | |
- name: deploy | |
working-directory: ./deployment-with-github-actions | |
run: npm run deploy:dev |