diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 0cb9c1b..5330e33 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -6,6 +6,11 @@ on: paths: - "docs/**" - ".github/workflows/pages.yml" + pull_request: + branches: [main] + paths: + - "docs/**" + - ".github/workflows/pages.yml" permissions: contents: read @@ -19,13 +24,34 @@ concurrency: jobs: build: runs-on: ubuntu-latest + outputs: + pages_configured: ${{ steps.pages_site.outputs.configured }} steps: - uses: actions/checkout@v6 + - name: Detect Pages site + id: pages_site + env: + GH_TOKEN: ${{ github.token }} + run: | + if [ "${{ github.event_name }}" != "push" ]; then + echo "configured=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if curl -fsSL \ + -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${GITHUB_REPOSITORY}/pages" >/dev/null; then + echo "configured=true" >> "$GITHUB_OUTPUT" + else + echo "configured=false" >> "$GITHUB_OUTPUT" + echo "::notice::GitHub Pages is not configured for this repository; skipping artifact upload and deploy." + fi + - name: Setup Pages + if: github.event_name == 'push' && steps.pages_site.outputs.configured == 'true' uses: actions/configure-pages@v6 - with: - enablement: true - name: Build with Jekyll uses: actions/jekyll-build-pages@v1 @@ -34,9 +60,11 @@ jobs: destination: ./_site - name: Upload artifact + if: github.event_name == 'push' && steps.pages_site.outputs.configured == 'true' uses: actions/upload-pages-artifact@v4 deploy: + if: github.event_name == 'push' && needs.build.outputs.pages_configured == 'true' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }}