From e67af28a4de29e64817f2cf1953d3b50d4afc3f2 Mon Sep 17 00:00:00 2001 From: Bernardo Simonassi Date: Sun, 13 Aug 2023 16:20:59 -0300 Subject: [PATCH] chore: ci/cd for multiple apps --- .github/workflows/deploy.yml | 29 ++++++++++++++------ .github/workflows/prepare.yml | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/prepare.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d7701bc..6d6d5b3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,9 +1,14 @@ -name: Deploy +name: Build and Deploy on: - push: - branches: - - main + workflow_call: + inputs: + APP_NAME: + required: true + type: string + BUCKET: + required: true + type: string permissions: id-token: write @@ -14,25 +19,33 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: 19 + - uses: pnpm/action-setup@v2 with: version: 8 - - name: Install dependencies + + - name: Install Dependencies run: pnpm install + - name: Build - run: pnpm generate --filter=app + run: pnpm generate --filter=${{ inputs.APP_NAME }} + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v2 with: aws-region: sa-east-1 role-to-assume: arn:aws:iam::928571631969:role/gh-actions-menthorlabs-menthor - - name: Install AWS Cli + + - name: Install AWS CLI id: install-aws-cli uses: unfor19/install-aws-cli-action@master + - name: Push to S3 - run: aws s3 cp apps/app/dist s3://menthor.io-app/app --recursive + run: aws s3 cp apps/${{ inputs.APP_NAME }}/dist ${{ inputs.BUCKET }} --recursive + - name: Invalidate CloudFront run: aws cloudfront create-invalidation --distribution-id E2B0K34D9WKXHA --paths "/*" \ No newline at end of file diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml new file mode 100644 index 0000000..ff2f01e --- /dev/null +++ b/.github/workflows/prepare.yml @@ -0,0 +1,51 @@ +name: Menthor Apps Deployment + +on: + push: + branches: + - main + +jobs: + changes: + name: Path filter + runs-on: ubuntu-latest + + outputs: + app: ${{ steps.filter.outputs.app }} + www: ${{ steps.filter.outputs.www }} + + steps: + - name: Checkout + uses: 'actions/checkout@v3' + + - uses: dorny/paths-filter@v2 + id: filter + with: + base: ${{ github.ref }} + filters: | + app: + - '.env.*' + - 'apps/app/**' + - 'packages/**' + www: + - '.env.*' + - 'apps/www/**' + - 'packages/**' + + app-deploy: + needs: changes + if: ${{ needs.changes.outputs.app == 'true' }} + secrets: inherit + uses: ./.github/workflows/deploy.yml + with: + APP_NAME: app + BUCKET: s3://menthor.io-app/app + + www-deploy: + needs: changes + if: ${{ needs.changes.outputs.www == 'true' }} + secrets: inherit + uses: ./.github/workflows/deploy.yml + with: + APP_NAME: www + BUCKET: s3://menthor.io \ No newline at end of file