-
Notifications
You must be signed in to change notification settings - Fork 3
ci: block merge when PR is labeled 'do not merge'- #572 #754
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| name: ForgeRock Pull Request CI | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, labeled, unlabeled] | ||
|
|
||
| env: | ||
| NX_CLOUD_ENCRYPTION_KEY: ${{ secrets.NX_CLOUD_ENCRYPTION_KEY }} | ||
|
|
@@ -14,6 +15,18 @@ concurrency: | |
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| block-merge-label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
Comment on lines
+18
to
+20
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. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- .github/workflows/ci.yml ---'
cat -n .github/workflows/ci.yml
printf '%s\n' '--- workflow permission and trigger references ---'
rg -n -C 3 '(^|[[:space:]])(permissions|on:|types:|block-merge-label|GITHUB_TOKEN|github\.event)' .github/workflows/ci.yml
printf '%s\n' '--- repository workflow files ---'
git ls-files '.github/workflows/*'Repository: ForgeRock/ping-javascript-sdk Length of output: 12109 🌐 Web query:
💡 Result: In GitHub Actions, the Citations:
🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
path = Path(".github/workflows/ci.yml")
lines = path.read_text().splitlines()
def block(start, indent):
out = []
for line in lines[start + 1:]:
if line.strip() and len(line) - len(line.lstrip()) <= indent:
break
out.append(line)
return out
jobs = {}
for i, line in enumerate(lines):
if line.startswith(" ") and not line.startswith(" ") and line.rstrip().endswith(":"):
name = line.strip()[:-1]
if name in {"block-merge-label", "pr"}:
jobs[name] = block(i, 2)
for name, body in jobs.items():
keys = [line.strip().split(":", 1)[0] for line in body
if line.startswith(" ") and not line.startswith(" ")
and line.strip() and not line.lstrip().startswith("#")]
print(f"{name}: top-level job keys={keys}")
print(f"{name}: has permissions key={'permissions' in keys}")
root_env = []
in_env = False
for line in lines:
if line == "env:":
in_env = True
continue
if in_env:
if line and len(line) - len(line.lstrip()) <= 0:
break
if line.startswith(" ") and not line.startswith(" "):
root_env.append(line.strip().split(":", 1)[0])
print(f"workflow-level env keys={root_env}")
PYRepository: ForgeRock/ping-javascript-sdk Length of output: 484 Set This job only reads pull request labels and does not use 🧰 Tools🪛 zizmor (1.29.0)[warning] 18-28: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block (excessive-permissions) 🤖 Prompt for AI AgentsSources: MCP tools, Linters/SAST tools |
||
| - name: Fail if "Do not merge" label present | ||
| env: | ||
| LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} | ||
| run: | | ||
| if echo "$LABELS" | tr '[:upper:]' '[:lower:]' | grep -q '"do not merge"'; then | ||
| echo "::error::Merge blocked: PR is labeled 'do not merge'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| pr: | ||
| if: ${{github.event.pull_request.head.repo.full_name == github.repository}} | ||
| runs-on: ubuntu-latest | ||
|
|
||
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: ForgeRock/ping-javascript-sdk
Length of output: 9170
🏁 Script executed:
Repository: ForgeRock/ping-javascript-sdk
Length of output: 826
🌐 Web query:
GitHub Actions pull_request activity types workflow-level filtering and job-level if condition for labeled and unlabeled events💡 Result:
To manage GitHub Actions workflows based on pull request label events, you must configure the workflow-level trigger to include the labeled and unlabeled activity types, and then use job-level if conditions to inspect the specific labels. Workflow-Level Filtering The pull_request event, by default, only triggers on opened, synchronize, and reopened activity types [1][2]. To react to changes in pull request labels, you must explicitly include the labeled and unlabeled types in the workflow definition using the types keyword [1][2]: on: pull_request: types: [opened, synchronize, labeled, unlabeled] There is no native capability to filter for specific labels at the workflow trigger level (e.g., triggering only when a label named 'ready' is added) [3]. You must include these activity types, which causes the workflow to trigger whenever any label is added or removed from a pull request [3]. Job-Level Condition Filtering Because the workflow triggers on all label changes, you must use the jobs.<job_id>.if condition to restrict execution to your desired logic [4][3]. You can inspect the github.event payload within the if expression to check for the presence or absence of specific labels [4][3]. Example: jobs: run-if-labeled: if: contains(github.event.pull_request.labels.*.name, 'my-target-label') runs-on: ubuntu-latest steps: - run: echo "The label is present." In this example, the job will run only if the pull request has the label 'my-target-label' at the time of the event [3]. When a label is removed, the unlabeled event triggers the workflow, the if condition evaluates to false, and the job is skipped [3]. Skipped jobs are reported as successful, which is important to consider if the job is part of a required status check [4][5].
Citations:
Guard
pragainst label-only events.labeledandunlabeledtrigger the entire workflow. The existingprcondition only checks the repository, so same-repository label changes rerun builds, publishing, documentation deployment, and comment updates. Add angithub.event.actionguard topr, or moveblock-merge-labelto a separate workflow.🤖 Prompt for AI Agents
Source: MCP tools