-
Notifications
You must be signed in to change notification settings - Fork 392
fix(CI): split documentation workflow to avoid pull_request_target checkout block #12625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dlabaj
wants to merge
2
commits into
main
Choose a base branch
from
fix/documentation-workflow-split
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: Documentation deploy | ||
| on: | ||
| workflow_run: | ||
| workflows: [Documentation] | ||
| types: [completed] | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| pull-requests: read | ||
| jobs: | ||
| deploy: | ||
| name: Deploy | ||
| runs-on: ubuntu-latest | ||
| if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' | ||
| env: | ||
| SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} | ||
| SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} | ||
| GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }} | ||
| steps: | ||
| - name: Check out project | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up project | ||
| uses: ./.github/actions/setup-project | ||
| with: | ||
| skip-build: true | ||
|
|
||
| - name: Resolve PR number | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| PR_NUM="${{ github.event.workflow_run.pull_requests[0].number }}" | ||
| if [ -z "$PR_NUM" ] || [ "$PR_NUM" = "null" ]; then | ||
| PR_NUM=$(gh api "repos/${{ github.repository }}/commits/${{ github.event.workflow_run.head_sha }}/pulls" --jq '.[0].number') | ||
| fi | ||
| if ! [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then | ||
| echo "Failed to resolve a valid PR number" | ||
| exit 1 | ||
| fi | ||
| echo "GH_PR_NUM=$PR_NUM" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Download documentation | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: documentation | ||
| path: packages/react-docs/public | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Download a11y coverage | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: a11y-coverage | ||
| path: packages/react-docs/coverage | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Upload documentation | ||
| run: node .github/upload-preview.mjs packages/react-docs/public | ||
|
|
||
| - name: Upload accessibility results | ||
| if: always() && !cancelled() | ||
| run: node .github/upload-preview.mjs packages/react-docs/coverage | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| name: Documentation | ||
| on: | ||
| pull_request_target: | ||
| pull_request: | ||
| issue_comment: | ||
| types: [created] | ||
| workflow_call: | ||
|
|
@@ -19,6 +19,7 @@ on: | |
| required: true | ||
| jobs: | ||
| check-permissions: | ||
| if: github.event_name == 'issue_comment' | ||
| uses: patternfly/.github/.github/workflows/check-team-membership.yml@fdb52a63a2220ec8a3b6c2d43f312cda708ffa06 | ||
| secrets: inherit | ||
|
|
||
|
|
@@ -29,37 +30,50 @@ jobs: | |
| if: >- | ||
| always() && | ||
| !cancelled() && | ||
| (inputs.is-release || needs.check-permissions.outputs.allowed == 'true') | ||
| (inputs.is-release || github.event_name != 'issue_comment' || needs.check-permissions.outputs.allowed == 'true') | ||
| env: | ||
| SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} | ||
| SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} | ||
| GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }} | ||
| GH_PR_NUM: ${{ needs.check-permissions.outputs.pr-number }} | ||
| steps: | ||
| - name: Check out project from PR branch | ||
| if: github.event_name == 'pull_request_target' || github.event_name == 'issue_comment' | ||
| if: github.event_name == 'issue_comment' | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Checkout the merge commit so that we can access the PR's changes. | ||
| # This is nessesary because `pull_request_target` checks out the base branch (e.g. `main`) by default. | ||
| ref: refs/pull/${{ env.GH_PR_NUM }}/head | ||
|
|
||
| - name: Check out project | ||
| if: inputs.is-release || github.event_name == 'workflow_call' | ||
| if: github.event_name != 'issue_comment' | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up and build project | ||
| uses: ./.github/actions/setup-project | ||
|
|
||
| - name: Build documentation | ||
| run: yarn build:docs | ||
|
|
||
| - name: Upload documentation | ||
| if: always() | ||
| - name: Upload documentation preview | ||
| if: always() && !cancelled() && github.event_name != 'pull_request' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need both the always() and !cancelled() calls? I am not an expert on this, but it sounds like maybe we don't: https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#always |
||
| run: node .github/upload-preview.mjs packages/react-docs/public | ||
|
|
||
| - name: Run accessibility tests | ||
| run: yarn serve:docs & yarn test:a11y | ||
|
|
||
| - name: Upload accessibility results | ||
| if: always() | ||
| if: always() && !cancelled() && github.event_name != 'pull_request' | ||
| run: node .github/upload-preview.mjs packages/react-docs/coverage | ||
|
|
||
| - name: Upload docs artifact | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: documentation | ||
| path: packages/react-docs/public | ||
|
|
||
| - name: Upload a11y artifact | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: a11y-coverage | ||
| path: packages/react-docs/coverage | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 233
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 205
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 9504
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 3437
🌐 Web query:
GitHub REST API list pull requests associated with a commit can return multiple pull requests endpoint documentation💡 Result:
Yes, the GitHub REST API endpoint
GET /repos/{owner}/{repo}/commits/{commit_sha}/pullscan return multiple pull requests [1][2]. According to the official GitHub documentation, the behavior of this endpoint is as follows: 1. It lists the merged pull request that introduced the commit to the repository [1][2]. 2. If the commit is not present in the default branch, the endpoint will return both merged and open pull requests associated with the commit [1][2]. Because it returns an array of pull request objects, it is possible for the response to contain multiple items depending on the state of the commit and the associated pull requests [1][3]. Additionally, you can pass a branch name as thecommit_shaparameter to list open or merged pull requests associated with that branch [1][2].Citations:
Reject ambiguous pull-request lookups.
When workflow metadata has no pull request, line 34 selects the first result from an endpoint that can return multiple pull requests for one commit. Resolve the fallback only when exactly one pull request matches the source run; otherwise fail the deployment. This prevents publishing artifacts under another pull request's preview URL or comment.
🧰 Tools
🪛 zizmor (1.29.0)
[error] 34-34: code injection via template expansion (template-injection): may expand into attacker-controllable code
(template-injection)
🤖 Prompt for AI Agents