From 5a9d1d7c28c4147b12803d845a570964174ffce7 Mon Sep 17 00:00:00 2001 From: KW Kwan Date: Wed, 20 Dec 2023 10:14:23 +0800 Subject: [PATCH] Migrate site to Github Pages --- .github/workflows/build_deploy.yml | 58 ++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 37 ------------------- 2 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/build_deploy.yml delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml new file mode 100644 index 0000000..497ba07 --- /dev/null +++ b/.github/workflows/build_deploy.yml @@ -0,0 +1,58 @@ +name: build_deploy + +on: + push: + branches: + - main + pull_request: + repository_dispatch: + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# 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: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + environment: + name: production + url: https://www.geolexica.org + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Pages + id: pages + uses: actions/configure-pages@v3 + + - name: Build site + run: | + mkdir -p _site + cp index.html _site + + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: _site + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 375c50f..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: deploy - -on: - push: - branches: - - main - - staging - repository_dispatch: - -jobs: - build: - name: Build site - runs-on: ubuntu-latest - environment: - name: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} - url: ${{ github.ref == 'refs/heads/main' && 'https://www.geolexica.org' || 'https://www-staging.geolexica.org' }} - - steps: - - uses: actions/checkout@v2 - - - name: Build site - run: | - mkdir -p _site - cp index.html _site - - - name: Deploy to geolexica.org - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_REGION: ${{ secrets.AWS_REGION }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} - S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} - run: | - aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.html" --content-type "text/html; charset=utf-8" - aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.json" --content-type "text/json; charset=utf-8" - aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*.html,*.json" --include "*" - aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"