Skip to content

Commit 2f4f343

Browse files
committed
ci: skip deploy when GitHub Pages is disabled
1 parent 15acd66 commit 2f4f343

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

.github/workflows/build-and-deploy.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ env:
1212
MDBOOK_LINKCHECK_VER: 0.7.7
1313

1414
jobs:
15+
# Fork may have GitHub Pages disabled, so deploying would result in 404
16+
# errors. This job checks whether Pages is enabled so the deploy job can be
17+
# skipped on repositories where it isn't configured.
18+
check-pages:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
pages: read
22+
outputs:
23+
pages_enabled: ${{ steps.check_pages.outputs.is_enabled }}
24+
steps:
25+
- name: Check if GitHub Pages is enabled
26+
id: check_pages
27+
uses: AlexAegis/check-github-pages@v1
28+
1529
build:
1630
runs-on: ubuntu-latest
1731
steps:
@@ -69,13 +83,13 @@ jobs:
6983

7084
deploy:
7185
name: Deploy to GitHub pages
72-
# Do not run this unless *pushing* to `master`.
73-
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
86+
# Do not run this unless *pushing* to `master` and GitHub Pages is enabled.
87+
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.check-pages.outputs.pages_enabled == 'true'
7488
environment:
7589
name: github-pages
7690
url: ${{ steps.deployment.outputs.page_url }}
7791
runs-on: ubuntu-latest
78-
needs: build
92+
needs: [build, check-pages]
7993
steps:
8094
- name: Deploy to GitHub Pages
8195
id: deployment

0 commit comments

Comments
 (0)