From 543718fdcab7464a1af446264826fbd86cfed812 Mon Sep 17 00:00:00 2001 From: protonchang <2095341+protonchang@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:21:11 +0800 Subject: [PATCH] Add github action auto-deplyment --- .github/workflows/build.yml | 21 +++++++++++++++++ .github/workflows/prod_deploy.yml | 38 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/prod_deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..eeb2340 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,21 @@ +name: Add-in Build +on: push +jobs: + build: + runs-on: ubuntu-latest + environment: development + steps: + - uses: actions/checkout@v4 + - name: Use Node.JS 20 LTS + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Build Add-in + run: | + echo "${{ secrets.BUILD_DOTENV }}" | base64 --decode > .env + sed -i "/https:\/\/quire.io\/<\/AppDomain>/a\ ${{ secrets.APP_DOMAIN }}" manifest.xml + sed -i "s|const urlProd = \"https://add-in-hosting-cdn-url/\";|const urlProd = \"${{ secrets.URL_PROD }}\";|" webpack.config.js + npm install + npm run build + find ./dist -name "*.map" -type f | xargs rm -f + find ./dist -name "*.LICENSE.txt" -type f | xargs rm -f \ No newline at end of file diff --git a/.github/workflows/prod_deploy.yml b/.github/workflows/prod_deploy.yml new file mode 100644 index 0000000..c6560f6 --- /dev/null +++ b/.github/workflows/prod_deploy.yml @@ -0,0 +1,38 @@ +name: Add-in Build and Deploy +on: + push: + tags: + - "*-prod" +permissions: + id-token: write + contents: read +jobs: + build: + runs-on: ubuntu-latest + environment: production + steps: + - uses: actions/checkout@v4 + - name: Use Node.JS 20 LTS + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Build Add-in + run: | + echo "${{ secrets.BUILD_DOTENV }}" | base64 --decode > .env + sed -i "/https:\/\/quire.io\/<\/AppDomain>/a\ ${{ secrets.APP_DOMAIN }}" manifest.xml + sed -i "s|const urlProd = \"https://add-in-hosting-cdn-url/\";|const urlProd = \"${{ secrets.URL_PROD }}\";|" webpack.config.js + npm install + npm run build + find ./dist -name "*.map" -type f | xargs rm -f + find ./dist -name "*.LICENSE.txt" -type f | xargs rm -f + - name: Deploy to AWS + uses: aws-actions/configure-aws-credentials@v4.0.2 + with: + role-to-assume: ${{ secrets.ROLE_ARN }} + role-session-name: GitHub_to_AWS_via_FederatedOIDC + aws-region: us-west-2 + - name: Deploy dist file to prod + run: | + aws s3 rm --recursive s3://${{ secrets.BUCKET_NAME }} + aws s3 cp --recursive ./dist/ s3://${{ secrets.BUCKET_NAME }} + aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_ID }} --paths /*