|
8 | 8 |
|
9 | 9 | permissions: |
10 | 10 | contents: read |
| 11 | + id-token: write |
11 | 12 |
|
12 | 13 | jobs: |
13 | 14 | test: |
14 | | - |
15 | 15 | runs-on: ubuntu-latest |
16 | 16 |
|
17 | 17 | steps: |
|
47 | 47 | with: |
48 | 48 | name: test-report |
49 | 49 | path: test-reports/report.html |
| 50 | + |
| 51 | + deploy_lambda_fetch: |
| 52 | + needs: test |
| 53 | + if: ${{ needs.test.result == 'success' }} |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - name: Checkout |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Check for code changes |
| 60 | + id: changes_fetch |
| 61 | + run: | |
| 62 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 63 | + if git diff --name-only HEAD^ HEAD | grep -q '^lambda_fetch/'; then |
| 64 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Configure AWS credentials |
| 68 | + if: steps.changes_fetch.outputs.changed == 'true' |
| 69 | + uses: aws-actions/configure-aws-credentials@v3 |
| 70 | + with: |
| 71 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 72 | + aws-region: ${{ secrets.AWS_REGION }} |
| 73 | + |
| 74 | + - name: Log in to Amazon ECR |
| 75 | + if: steps.changes_fetch.outputs.changed == 'true' |
| 76 | + uses: aws-actions/amazon-ecr-login@v2 |
| 77 | + |
| 78 | + - name: Build, tag, and push Docker image to ECR |
| 79 | + if: steps.changes_fetch.outputs.changed == 'true' |
| 80 | + run: | |
| 81 | + IMAGE_TAG=latest |
| 82 | + ECR_REGISTRY=$(aws sts get-caller-identity --query "Account" --output text).dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com |
| 83 | + ECR_REPOSITORY=predictit-fetch |
| 84 | + docker buildx build --platform linux/amd64 --provenance=false \ |
| 85 | + -t $ECR_REPOSITORY:$IMAGE_TAG \ |
| 86 | + -f ./lambda_fetch/Dockerfile . |
| 87 | + docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 88 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 89 | +
|
| 90 | + - name: Update Lambda function |
| 91 | + if: steps.changes_fetch.outputs.changed == 'true' |
| 92 | + run: | |
| 93 | + FUNCTION_NAME=predictit-fetch |
| 94 | + IMAGE_TAG=latest |
| 95 | + ECR_REGISTRY=$(aws sts get-caller-identity --query "Account" --output text).dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com |
| 96 | + ECR_REPOSITORY=predictit-fetch |
| 97 | +
|
| 98 | + aws lambda update-function-code \ |
| 99 | + --function-name $FUNCTION_NAME \ |
| 100 | + --image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ |
| 101 | + --region ${{ secrets.AWS_REGION }} |
0 commit comments