summaryrefslogtreecommitdiff
path: root/.github/workflows/main.yml
blob: e76d80999664dad116b6dd23cb1f57e2295d25b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
# We run this workflow on pushes and also every night to pick up fresh nightly builds
on:
  push:
    branches:
      - main
      - production
      - amplify
  schedule:
    - cron: "0 3 * * *"
  workflow_dispatch:
  workflow_call:
    inputs:
      branch:
        required: true
        type: string
      aws_amplify_region:
        required: true
        type: string
      aws_amplify_app_id:
        required: true
        type: string
    secrets:
      AWS_AMPLIFY_ACCESS_KEY_ID:
        required: true
      AWS_AMPLIFY_SECRET_ACCESS_KEY:
        required: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  deploy:
    environment:
      name: ${{ github.ref_name }}

    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    - name: Set env variables if they were NOT specified as inputs
      if: ${{ inputs.aws_amplify_region == '' || inputs.aws_amplify_app_id == '' }}
      run: |
        echo "AWS_AMPLIFY_REGION=${{ vars.AWS_AMPLIFY_REGION }}" >> $GITHUB_ENV
        echo "AWS_AMPLIFY_APP_ID=${{ vars.AWS_AMPLIFY_APP_ID }}" >> $GITHUB_ENV
        echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV

    - name: Set env variables if they were specified as inputs
      if: ${{ inputs.aws_amplify_region != '' && inputs.aws_amplify_app_id != '' }}
      run: |
        echo "AWS_AMPLIFY_REGION=${{ inputs.aws_amplify_region }}" >> $GITHUB_ENV
        echo "AWS_AMPLIFY_APP_ID=${{ inputs.aws_amplify_app_id }}" >> $GITHUB_ENV
        echo "BRANCH=${{ inputs.branch }}" >> $GITHUB_ENV

    - name: Deploy to Amplify
      run: |
        curl --request POST \
          --url https://amplify.${{ env.AWS_AMPLIFY_REGION }}.amazonaws.com/apps/${{ env.AWS_AMPLIFY_APP_ID }}/branches/${{ env.BRANCH }}/jobs \
          --header 'Content-Type: application/json' \
          --data '{"jobType": "RELEASE"}' \
          --user "${{ secrets.AWS_AMPLIFY_ACCESS_KEY_ID }}:${{ secrets.AWS_AMPLIFY_SECRET_ACCESS_KEY }}" \
          --aws-sigv4 "aws:amz:${{ env.AWS_AMPLIFY_REGION }}:amplify"

    - name: Check Amplify build status
      uses: vyos/amplify-build-status@v2.2
      with:
        app-id: ${{ env.AWS_AMPLIFY_APP_ID }}
        branch-name: ${{ env.BRANCH }}
        commit-id: HEAD
        wait: true
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_AMPLIFY_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_AMPLIFY_SECRET_ACCESS_KEY }}
        AWS_REGION: ${{ env.AWS_AMPLIFY_REGION }}