Deploy Eleventy using Github Actions
Solution
Note: the first example uses yarn. For NPM, see below
# Based on https://github.com/actions/starter-workflows/blob/main/pages/static.yml
name: Build static & deploy to GitHub Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows this workflow to be called from other workflows
workflow_call:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Select latest ref instead of event trigger, in case this is triggered by another event
ref: ${{ github.ref }}
- uses: actions/setup-node@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Install pre-requirements
run: yarn install
- name: Build
run: yarn build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'dist/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
NPM version:
# Based on https://github.com/actions/starter-workflows/blob/main/pages/static.yml
name: Build static & deploy to GitHub Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows this workflow to be called from other workflows
workflow_call:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Select latest ref instead of event trigger, in case this is triggered by another event
ref: ${{ github.ref }}
- uses: actions/setup-node@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Install pre-requirements
run: npm ci
- name: Build
run: npm run build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'dist/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4