11# *******************************************************************************
2- # Copyright (c) 2024 Contributors to the Eclipse Foundation
2+ # Copyright (c) 2025 Contributors to the Eclipse Foundation
33#
44# See the NOTICE file(s) distributed with this work for additional
55# information regarding copyright ownership.
1313
1414name : Documentation
1515on :
16- pull_request :
17- types : [opened, reopened, synchronize]
16+ pull_request_target :
17+ types : [opened, reopened, synchronize] # Handles forked PRs
1818 push :
1919 merge_group :
2020 types : [checks_requested]
21+
2122jobs :
2223 docs-build :
2324 name : Build documentation
2425 runs-on : ubuntu-latest
2526 permissions :
2627 pull-requests : write
2728 steps :
28- - name : Checkout repository
29+ # ------------------------------------------------------------------------------
30+ # Checkout the correct branch safely in all scenarios (PRs, forks, merges)
31+ # ------------------------------------------------------------------------------
32+ # | Condition | Event Type | Checked Out Branch |
33+ # |----------------------------------------|--------------------|-----------------------|
34+ # | github.head_ref | pull_request_target | PR branch (source branch) |
35+ # | github.event.pull_request.head.ref | pull_request | PR branch (source branch) |
36+ # | github.ref | push, merge_group | The branch being pushed/merged |
37+ # ------------------------------------------------------------------------------
38+ # ------------------------------------------------------------------------------
39+ # Checkout the correct repository safely in all scenarios (PRs, forks, merges)
40+ # ------------------------------------------------------------------------------
41+ # | Condition | Event Type | Checked Out Repository |
42+ # |------------------------------------------------|--------------------|----------------------------------|
43+ # | github.event.pull_request.head.repo.full_name | pull_request | Forked repository (if PR is from a fork) |
44+ # | github.repository | push, merge_group | Default repository (same repo PRs, merges, pushes) |
45+ - name : Checkout repository (Handle all events)
2946 uses : actions/checkout@v4.2.2
47+ with :
48+ ref : ${{ github.head_ref || github.event.pull_request.head.ref || github.ref }}
49+ repository : ${{ github.event.pull_request.head.repo.full_name || github.repository }}
50+ - name : Ensure GitHub Token is Masked
51+ run : echo "::add-mask::$GITHUB_TOKEN"
3052 - name : Setup Bazel
3153 uses : bazel-contrib/setup-bazel@0.9.1
3254 - name : Build documentation
3355 run : |
3456 bazel build //docs:github-pages && cp bazel-bin/docs/github-pages.tar .
57+ # ------------------------------------------------------------------------------
58+ # Generate a unique artifact name to ensure proper tracking in all scenarios
59+ # ------------------------------------------------------------------------------
60+ # | Condition | Event Type | Artifact Name Value |
61+ # |-----------------------------------------------|------------------------|----------------------------------------------|
62+ # | github.event.pull_request.head.sha | pull_request | PR commit SHA (ensures uniqueness per PR) |
63+ # | github.event.pull_request.head.sha | pull_request_target | PR commit SHA (ensures uniqueness per PR) |
64+ # | github.sha | push, merge_group | Current commit SHA (used for main branch) |
65+ # ------------------------------------------------------------------------------
3566 - name : Upload artifact for job analysis
3667 uses : actions/upload-artifact@v4.4.0
3768 with :
38- name : github-pages-${{ github.sha }}
69+ name : github-pages-${{ github.event.pull_request.head.sha || github. sha }}
3970 path : github-pages.tar
4071 retention-days : 1
4172 if-no-files-found : error
73+
4274 docs-deploy :
4375 name : Deploy documentation to GitHub Pages
4476 permissions :
@@ -52,26 +84,35 @@ jobs:
5284 runs-on : ubuntu-latest
5385 needs : docs-build
5486 steps :
55- # Checkout is required to get the local actions.
87+ # ------------------------------------------------------------------------------
88+ # Always checks out the BASE repository since pull_request_target is used.
89+ # This ensures that the workflow runs with trusted code from the base repo,
90+ # even when triggered by a pull request from a fork.
91+ # ------------------------------------------------------------------------------
5692 - name : Checkout repository
5793 uses : actions/checkout@v4.2.2
94+
5895 - name : Download documentation artifact
5996 uses : actions/download-artifact@v4.1.8
97+ # ------------------------------------------------------------------------------
98+ # Generate a unique artifact name to ensure proper tracking in all scenarios
99+ # ------------------------------------------------------------------------------
100+ # | Condition | Event Type | Artifact Name Value |
101+ # |-----------------------------------------------|------------------------|----------------------------------------------|
102+ # | github.event.pull_request.head.sha | pull_request | PR commit SHA (ensures uniqueness per PR) |
103+ # | github.event.pull_request.head.sha | pull_request_target | PR commit SHA (ensures uniqueness per PR) |
104+ # | github.sha | push, merge_group | Current commit SHA (used for main branch) |
105+ # ------------------------------------------------------------------------------
60106 with :
61- name : github-pages-${{ github.sha }}
107+ name : github-pages-${{ github.event.pull_request.head.sha || github.sha }}
108+
62109 - name : Untar documentation artifact
63110 run : mkdir -p extracted_docs && tar -xf github-pages.tar -C extracted_docs
111+
64112 - name : Deploy 🚀
65113 id : pages-deployment
66114 continue-on-error : true
67115 uses : ./.github/actions/deploy-versioned-pages
68116 with :
69117 source_folder : extracted_docs
70- - name : Deploy (fallback) 🚀
71- id : deployment
72- # If the new deployment from gh-pages branch fails, at least deploy the current version.
73- # This is only a short-term solution, until we can change the repository settings.
74- if : ${{ steps.pages-deployment.outcome == 'failure' && github.event_name == 'push' && github.ref_name == 'main' }}
75- uses : actions/deploy-pages@v4.0.5
76- with :
77- artifact_name : github-pages-${{ github.sha }}
118+
0 commit comments