Skip to content

Deploy to GitHub Pages #3075

Deploy to GitHub Pages

Deploy to GitHub Pages #3075

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches: [main]
schedule:
- cron: "0 */1 * * *"
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
env:
BUILD_PATH: "."
NOTION_API_SECRET: ${{ secrets.NOTION_API_SECRET }}
jobs:
build:
runs-on: ubuntu-latest
environment: github-pages
timeout-minutes: 45
steps:
- name: Checkout your repository using git
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 21
# Idea from https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/
- name: Cache node manually
id: npm-cache
uses: actions/cache@v4
with:
path: ./node_modules
key: modules-${{ hashFiles(format('{0}/package-lock.json', env.BUILD_PATH)) }}
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
working-directory: ${{ env.BUILD_PATH }}
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Restore cached tmp
if: steps.npm-cache.outputs.cache-hit == 'true'
id: cache-tmp-restore
uses: actions/cache/restore@v4
with:
path: ./tmp
key: ${{ runner.os }}-${{steps.pages.outputs.origin}}-${{steps.pages.outputs.base_path}}-tmp-blogtrotion-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: ${{ runner.os }}-${{steps.pages.outputs.origin}}-${{steps.pages.outputs.base_path}}-tmp-blogtrotion-
- name: Restore cached public
if: steps.npm-cache.outputs.cache-hit == 'true'
id: cache-public-restore
uses: actions/cache/restore@v4
with:
path: ./public
key: ${{ runner.os }}-${{steps.pages.outputs.origin}}-${{steps.pages.outputs.base_path}}-public-blogtrotion-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: ${{ runner.os }}-${{steps.pages.outputs.origin}}-${{steps.pages.outputs.base_path}}-public-blogtrotion-
- name: Set and log environment secrets and variables and then Build with Astro and postbuild for pagefind
env:
NOTION_API_SECRET: ${{ secrets.NOTION_API_SECRET }}
GITHUB_PAGES: true
SITE: ${{ steps.pages.outputs.origin }}
BASE: ${{ steps.pages.outputs.base_path }}
run: |
echo "NOTION_API_SECRET = $NOTION_API_SECRET"
echo "GITHUB_PAGES = $GITHUB_PAGES"
echo "SITE = $SITE"
echo "BASE = $BASE"
npx --no-install astro build
# or if you prefer yarn, use: yarn build
# --site and --base flags can be included if needed for Astro
# --site steps.pages.outputs.origin" \
# --base steps.pages.outputs.base_path"
npx --no-install pagefind --site dist
working-directory: ${{ env.BUILD_PATH }}
- name: Save new tmp cache
id: cache-tmp-save
uses: actions/cache/save@v4
with:
path: ./tmp
key: ${{ runner.os }}-${{steps.pages.outputs.origin}}-${{steps.pages.outputs.base_path}}-tmp-blogtrotion-${{ github.run_id }}-${{ github.run_attempt }}
- name: Save new public cache
id: cache-public-save
uses: actions/cache/save@v4
with:
path: ./public
key: ${{ runner.os }}-${{steps.pages.outputs.origin}}-${{steps.pages.outputs.base_path}}-public-blogtrotion-${{ github.run_id }}-${{ github.run_attempt }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ env.BUILD_PATH }}/dist
deploy:
needs: build
runs-on: ubuntu-latest
name: Deploy
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
workflow-keepalive:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: liskin/gh-workflow-keepalive@v1