|
| 1 | +name: Build and Deploy |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + env: |
| 6 | + required: true |
| 7 | + description: Environment name |
| 8 | + type: string |
| 9 | + version: |
| 10 | + required: false |
| 11 | + description: Version |
| 12 | + type: string |
| 13 | + default: latest |
| 14 | + |
| 15 | +concurrency: |
| 16 | + cancel-in-progress: false |
| 17 | + group: build-deploy-${{ inputs.env }} |
| 18 | + |
| 19 | +env: |
| 20 | + NODE_VERSION: 22.15.0 |
| 21 | + VITE_BUILD_VERSION: ${{ inputs.version }} |
| 22 | + VITE_DD_VERSION: ${{ inputs.version }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + setup-vars: |
| 26 | + uses: ./.github/workflows/_setup.yaml |
| 27 | + with: |
| 28 | + env-name: ${{ inputs.env-name }} |
| 29 | + |
| 30 | + build: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + name: Node Build and Deploy |
| 33 | + needs: setup-vars |
| 34 | + permissions: |
| 35 | + contents: read |
| 36 | + id-token: write |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + name: Checkout |
| 40 | + |
| 41 | + - name: Configure aws credentials for secrets |
| 42 | + uses: aws-actions/configure-aws-credentials@v4 |
| 43 | + with: |
| 44 | + role-to-assume: arn:aws:iam::917902836630:role/cmiml-devops-oidc-github-role |
| 45 | + role-session-name: OIDC-GHA-Build-Secrets |
| 46 | + aws-region: us-east-1 |
| 47 | + |
| 48 | + - name: Load build config |
| 49 | + uses: aws-actions/aws-secretsmanager-get-secrets@v2 |
| 50 | + with: |
| 51 | + secret-ids: /CodeBuild/admin-panel/${{ inputs.env }} |
| 52 | + parse-json-secrets: true |
| 53 | + |
| 54 | + - uses: actions/setup-node@v4 |
| 55 | + name: Setup Node |
| 56 | + with: |
| 57 | + node-version: ${{ env.NODE_VERSION }} |
| 58 | + |
| 59 | + - name: Install dependencies |
| 60 | + run: npm ci |
| 61 | + |
| 62 | + - uses: wearerequired/lint-action@v2 |
| 63 | + name: Lint |
| 64 | + with: |
| 65 | + eslint: true |
| 66 | + eslint_extensions: js,jsx,ts,tsx |
| 67 | + prettier: true |
| 68 | + prettier_extensions: js,jsx,ts,tsx |
| 69 | + continue_on_error: false |
| 70 | + |
| 71 | + - name: Tests |
| 72 | + run: npm run test |
| 73 | + |
| 74 | + - name: Build admin app |
| 75 | + run: npm run build |
| 76 | + |
| 77 | + - name: Configure AWS credentials for deploy |
| 78 | + uses: aws-actions/configure-aws-credentials@v4 |
| 79 | + with: |
| 80 | + role-to-assume: ${{ needs.setup-vars.outputs.role }} |
| 81 | + role-session-name: OIDC-GHA-session-deploy |
| 82 | + aws-region: ${{ needs.setup-vars.outputs.region }} |
| 83 | + |
| 84 | + - name: Deploy |
| 85 | + run: | |
| 86 | + aws s3 sync ./build s3://cmiml-${{ inputs.env }}-admin-panel |
| 87 | +
|
| 88 | + - name: Invalidate Cloudfront caches |
| 89 | + run: |
| 90 | + for id in $(aws cloudfront list-distributions --output json | jq -r '.DistributionList.Items[] | select(.Comment | test("admin"; "i")) | .Id'); do |
| 91 | + aws cloudfront create-invalidation --distribution-id ${id} --paths "/*" |
| 92 | + done |
0 commit comments