@@ -132,6 +132,21 @@ jobs:
132132 isDirty=true
133133 fi
134134
135+ # Remove any workflow files that still use pull_request_target.
136+ # Those are legacy/stale and should not remain in pkg-repos.
137+ if [[ -d ".github/workflows" ]]; then
138+ pr_target_workflows=$(grep -R -l --include='*.yml' --include='*.yaml' 'pull_request_target' .github/workflows 2>/dev/null || true)
139+ if [[ -n "$pr_target_workflows" ]]; then
140+ echo " 🗑️ Removing workflows containing pull_request_target"
141+ while IFS= read -r workflow_file; do
142+ [[ -z "$workflow_file" ]] && continue
143+ echo " - $workflow_file"
144+ rm -f "$workflow_file"
145+ done <<< "$pr_target_workflows"
146+ isDirty=true
147+ fi
148+ fi
149+
135150 # Remove legacy default-branch caller workflow names. New names are
136151 # synced from .github/pkg-workflows/qli-ci/*.yml below.
137152 for legacy_main_workflow in build-debian-package.yml promote-prebuilt.yml promote-upstream.yml release.yml; do
@@ -194,6 +209,70 @@ jobs:
194209 echo " ✨ No default branch changes needed for $repo"
195210 fi
196211
212+ # Cleanup-only pass for non-packaging branches:
213+ # delete stale workflows that still contain pull_request_target.
214+ other_branches=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin \
215+ | sed 's|^origin/||' \
216+ | grep -Ev '^HEAD$' \
217+ | grep -Ev '(^|/)pr/' \
218+ | grep -Ev '^sync/' \
219+ | grep -v "^${default_branch}$" \
220+ | grep -Ev '^(debian/|ubuntu/|qcom/debian/|qcom/ubuntu/)' \
221+ | sort -u)
222+
223+ for other_branch in $other_branches; do
224+ echo " 🌿 Checking stale pull_request_target workflows on branch: $other_branch"
225+ safe_branch_name="${other_branch//\//-}"
226+ cleanup_sync_branch="sync/qcom-build-utils-pr-target-cleanup-${safe_branch_name}"
227+
228+ git checkout "$other_branch" 2>&1 | sed 's/^/ /'
229+ isCleanupDirty=false
230+
231+ if [[ -d ".github/workflows" ]]; then
232+ pr_target_workflows=$(grep -R -l --include='*.yml' --include='*.yaml' 'pull_request_target' .github/workflows 2>/dev/null || true)
233+ if [[ -n "$pr_target_workflows" ]]; then
234+ echo " 🗑️ Removing workflows containing pull_request_target on $other_branch"
235+ while IFS= read -r workflow_file; do
236+ [[ -z "$workflow_file" ]] && continue
237+ echo " - $workflow_file"
238+ rm -f "$workflow_file"
239+ done <<< "$pr_target_workflows"
240+ isCleanupDirty=true
241+ fi
242+ fi
243+
244+ if [[ "$isCleanupDirty" == "true" ]]; then
245+ if git ls-remote --exit-code --heads origin "$cleanup_sync_branch" > /dev/null 2>&1; then
246+ echo " 🧹 Deleting existing $cleanup_sync_branch"
247+ git push origin --delete "$cleanup_sync_branch" 2>&1 | sed 's/^/ /'
248+ fi
249+
250+ git checkout -b "$cleanup_sync_branch" 2>&1 | sed 's/^/ /'
251+ git add -A .github/
252+ git commit -s -m "chore: remove pull_request_target workflows" 2>&1 | sed 's/^/ /'
253+
254+ if [[ "$CONFIRMATION_INPUT" == "true" ]]; then
255+ echo " 🚀 Pushing changes and creating PR for $other_branch"
256+ git push origin "$cleanup_sync_branch" 2>&1 | sed 's/^/ /'
257+
258+ pr_url=$(gh pr create --repo "$ORG/$repo" \
259+ --title "chore: remove pull_request_target workflows" \
260+ --body "This PR removes stale workflow files that still contain \`pull_request_target\`." \
261+ --head "$cleanup_sync_branch" \
262+ --base "$other_branch")
263+
264+ PR_URLS+=("$pr_url")
265+ echo " ✅ PR created for $other_branch: $pr_url"
266+ else
267+ echo " 👀 Dry-run mode - No PR will be created for $other_branch"
268+ fi
269+ else
270+ echo " ✨ No pull_request_target workflow cleanup needed on $other_branch"
271+ fi
272+
273+ git checkout "$default_branch" 2>&1 | sed 's/^/ /'
274+ done
275+
197276 # Sync pkg-pr-hook.yml to every managed packaging branch family.
198277 # Supported families:
199278 # - debian/*
@@ -234,6 +313,19 @@ jobs:
234313 isDebianDirty=true
235314 fi
236315
316+ if [[ -d ".github/workflows" ]]; then
317+ pr_target_workflows=$(grep -R -l --include='*.yml' --include='*.yaml' 'pull_request_target' .github/workflows 2>/dev/null || true)
318+ if [[ -n "$pr_target_workflows" ]]; then
319+ echo " 🗑️ Removing workflows containing pull_request_target on $packaging_branch"
320+ while IFS= read -r workflow_file; do
321+ [[ -z "$workflow_file" ]] && continue
322+ echo " - $workflow_file"
323+ rm -f "$workflow_file"
324+ done <<< "$pr_target_workflows"
325+ isDebianDirty=true
326+ fi
327+ fi
328+
237329 if [[ -f "$DEBIAN_TARGET_WORKFLOW_FILE" ]]; then
238330 if diff -q "$DEBIAN_LATEST_WORKFLOW_FILE" "$DEBIAN_TARGET_WORKFLOW_FILE" > /dev/null; then
239331 echo " ✅ pkg-pr-hook.yml is up to date on $packaging_branch"
0 commit comments