diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e70b95d7..b70de420 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,18 +1,32 @@ +# Build and deploy a Gatsby site to GitHub Pages name: Gatsby Build & Deploy + on: - pull_request: - workflow_dispatch: + workflow_dispatch: push: - branches: - - main + branches: [$default-branch] + +# 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: pages + cancel-in-progress: false + +defaults: + run: + shell: bash jobs: - deploy: + build: runs-on: ubuntu-latest - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - name: Setup Node.js @@ -21,18 +35,44 @@ jobs: node-version: 22 cache: yarn + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 + with: + # Automatically inject pathPrefix in your Gatsby configuration file. + static_site_generator: gatsby + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + public + .cache + key: ${{ runner.os }}-gatsby-build-${{ hashFiles('public') }} + restore-keys: | + ${{ runner.os }}-gatsby-build- + - name: Install dependencies run: yarn install --immutable - name: Build with Gatsby env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} + PREFIX_PATHS: 'true' + GH_TOKEN: ${{ secrets.GH_TOKEN }} run: yarn build - - name: Deploy to gh-pages branch - uses: peaceiris/actions-gh-pages@v4 - if: ${{ github.ref == 'refs/heads/main' }} + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./public - cname: johng.io + path: ./public + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 2a58558f..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,36 +0,0 @@ -# name: Gatsby Build & Deploy -# on: -# push: -# branches: -# - v3 -# pull_request: -# workflow_dispatch: - -# jobs: -# deploy: -# runs-on: ubuntu-latest -# concurrency: -# group: ${{ github.workflow }}-${{ github.ref }} -# steps: -# - name: Checkout repository -# uses: actions/checkout@v3 - -# - name: Setup Node.js -# uses: actions/setup-node@v3 -# with: -# node-version: '16' -# cache: 'yarn' - -# - name: Install dependencies -# run: yarn install --immutable - -# - name: Build with Gatsby -# run: DOTENV_CONFIG_GH_TOKEN=${{ secrets.JOHNGIO_DEPLOY_PAT }} yarn build - -# - name: Deploy to gh-pages branch -# uses: peaceiris/actions-gh-pages@v3 -# if: ${{ github.ref == 'refs/heads/main' }} -# with: -# personal_token: ${{ secrets.JOHNGIO_DEPLOY_PAT }} -# publish_dir: ./public -# cname: johng.io diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b