diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml new file mode 100644 index 0000000..2bc3846 --- /dev/null +++ b/.github/workflows/build-deploy.yml @@ -0,0 +1,43 @@ +on: + workflow_call: + +jobs: + # Build job + build-and-deploy: + runs-on: ubuntu-latest + env: + NEXT_PUBLIC_API_URL: ${{ secrets.API_URL }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: "18" + cache: "npm" + - name: Restore cache + uses: actions/cache@v3 + with: + path: | + .next/cache + # Generate a new cache whenever packages or source files change. + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} + # If source files changed but packages didn't, rebuild from a prior cache. + restore-keys: | + ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- + - name: Install Modules + run: npm ci + - name: Build Application + run: npm run build + + # Deploy to AWS + - name: Configure AWS + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Deploy to S3 + run: aws s3 sync ./out s3://${{ secrets.BUCKET_NAME }} --delete + - name: Create Cloudfront Invalidation + run: aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/*" diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..eae8372 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,20 @@ +on: + # Runs on pushes targeting the default branch + push: + branches: ["dev"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "frontend-dev" + cancel-in-progress: false + +jobs: + build-deploy-dev: + uses: ./.github/workflows/dev.yml + environment: dev + secrets: inherit +