Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 47 additions & 41 deletions src/docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,11 @@ Additionally, _if_ you’re writing your [Eleventy Image output](/docs/plugins/i

### Deploy an Eleventy project to GitHub pages

Includes persisted cache across builds. Using [`peaceiris/actions-gh-pages`](https://github.com/peaceiris/actions-gh-pages).
Includes persisted cache across builds.

<ol>
<li>Go to your repository’s Settings on GitHub.</li>
<li>In the GitHub Pages section change:<ul><li>Source: <code>Deploy from a branch</code></li><li>Branch: <code>gh-pages/(root)</code></li></ul></li>
<li>Add "build-ghpages" command to your <details><summary><code>package.json</code> scripts section</summary>

```json
"scripts": {
"build-ghpages": "npx @11ty/eleventy --pathprefix=/your-repo-name/",
}
```

</details></li>
<li>In the GitHub Pages section change:<ul><li>Source: <code>GitHub Actions</code></li></ul></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to deploy for every update of the main branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only meant to be an example so I don't think the branch used here really matters that much. The build and deploy jobs are the important part. People can change when those jobs are ran to fit their requirements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach but this changes the what the tutorial was doing ( use a specific build-gh pages script and peaceiris/actions-gh-pages ) hence my remark.

Maybe you should rebase this branch since @zachleat merged a related PR to fix an issue.
#1771

I would support the update you propose because to me it look simpler.

<li>Create a new GitHub workflow file in <details><summary><code>.github/workflows/deploy-to-ghpages.yml</code></summary>

{% raw %}
Expand All @@ -205,44 +196,59 @@ on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
runs-on: ubuntu-22.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "18"

- name: Persist npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}

- name: Persist Eleventy .cache
uses: actions/cache@v3
node-version: "22"
cache: npm
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Install dependencies
run: npm ci
- name: Get current timestamp
id: timestamp
run: echo "now=$(date +%Y%m%d%H%M)" >> "$GITHUB_OUTPUT"
- name: Restore .cache
uses: actions/cache@v4
with:
path: ./.cache
key: ${{ runner.os }}-eleventy-fetch-cache

- run: npm install
- run: npm run build-ghpages
key: eleventy-fetch-cache-${{ steps.timestamp.outputs.now }}
restore-keys: eleventy-fetch-cache-
- name: Build site
run: npx --no @11ty/eleventy --pathprefix="${{ steps.pages.outputs.base_path }}"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
deploy:
name: Deploy
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy Pages
id: deployment
uses: actions/deploy-pages@v4
```

{% endraw %}
Expand Down