From d36bf5aa78916e7c4b61183e1a83e827158c98d5 Mon Sep 17 00:00:00 2001 From: Andy Autida Date: Sat, 28 Oct 2023 02:50:38 +0800 Subject: [PATCH] add github action for building and deployment --- .github/workflows/build-and-deploy.yml | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/build-and-deploy.yml diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..48572a1 --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,34 @@ +name: Build and Deploy +on: + push: + branches: + - main +env: + AWS_DEFAULT_REGION: 'ap-southeast-1' + BUILD_DIR: ./_site +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm install + - name: Build pages + run: npm build + - name: Upload to S3 + run: aws s3 sync $BUILD_DIR $WEBSITE_S3 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + WEBSITE_S3: ${{ secrets.WEBSITE_S3 }} + - name: Create Invalidation + run: aws cloudfront create-invalidation --distribution-id $WEBSITE_DISTRIBUTION_ID --paths '/*' + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + WEBSITE_DISTRIBUTION_ID: ${{ secrets.WEBSITE_DISTRIBUTION_ID }} \ No newline at end of file