Skip to content

Commit 9191003

Browse files
committed
Update GitHub Pages workflow example
1 parent ab7c6c0 commit 9191003

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

src/docs/deployment.md

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ Additionally, _if_ you’re writing your [Eleventy Image output](/docs/plugins/i
189189

190190
### Deploy an Eleventy project to GitHub pages
191191

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

194194
<ol>
195195
<li>Go to your repository’s Settings on GitHub.</li>
196-
<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>
196+
<li>In the GitHub Pages section change:<ul><li>Source: <code>GitHub Actions</code></li></ul></li>
197197
<li>Create a new GitHub workflow file in <details><summary><code>.github/workflows/deploy-to-ghpages.yml</code></summary>
198198

199199
{% raw %}
@@ -205,44 +205,59 @@ on:
205205
push:
206206
branches:
207207
- main
208-
pull_request:
208+
workflow_dispatch:
209+
210+
permissions:
211+
contents: read
212+
pages: write
213+
id-token: write
214+
215+
concurrency:
216+
group: "pages"
217+
cancel-in-progress: false
209218

210219
jobs:
211-
deploy:
212-
runs-on: ubuntu-22.04
213-
permissions:
214-
contents: write
215-
concurrency:
216-
group: ${{ github.workflow }}-${{ github.ref }}
220+
build:
221+
name: Build
222+
runs-on: ubuntu-latest
217223
steps:
218-
- uses: actions/checkout@v3
219-
224+
- name: Checkout
225+
uses: actions/checkout@v4
220226
- name: Setup Node
221-
uses: actions/setup-node@v3
227+
uses: actions/setup-node@v4
222228
with:
223-
node-version: "18"
224-
225-
- name: Persist npm cache
226-
uses: actions/cache@v3
227-
with:
228-
path: ~/.npm
229-
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
230-
231-
- name: Persist Eleventy .cache
232-
uses: actions/cache@v3
229+
node-version: "20"
230+
cache: npm
231+
- name: Setup Pages
232+
id: pages
233+
uses: actions/configure-pages@v5
234+
- name: Install dependencies
235+
run: npm ci
236+
- name: Get current timestamp
237+
id: timestamp
238+
run: echo "now=$(date +%Y%m%d%H%M)" >> "$GITHUB_OUTPUT"
239+
- name: Restore .cache
240+
uses: actions/cache@v4
233241
with:
234242
path: ./.cache
235-
key: ${{ runner.os }}-eleventy-fetch-cache
236-
237-
- run: npm install
238-
- run: npm run build-ghpages
243+
key: eleventy-fetch-cache-${{ steps.timestamp.outputs.now }}
244+
restore-keys: eleventy-fetch-cache-
245+
- name: Build site
246+
run: npx --no @11ty/eleventy --pathprefix="${{ steps.pages.outputs.base_path }}"
247+
- name: Upload artifact
248+
uses: actions/upload-pages-artifact@v3
239249

240-
- name: Deploy
241-
uses: peaceiris/actions-gh-pages@v3
242-
if: github.ref == 'refs/heads/main'
243-
with:
244-
github_token: ${{ secrets.GITHUB_TOKEN }}
245-
publish_dir: ./_site
250+
deploy:
251+
name: Deploy
252+
environment:
253+
name: github-pages
254+
url: ${{ steps.deployment.outputs.page_url }}
255+
needs: build
256+
runs-on: ubuntu-latest
257+
steps:
258+
- name: Deploy Pages
259+
id: deployment
260+
uses: actions/deploy-pages@v4
246261
```
247262
248263
{% endraw %}

0 commit comments

Comments
 (0)