@@ -122,6 +122,7 @@ jobs:
122122
123123 - name : Create sync branch
124124 if : steps.check.outputs.exists == 'false'
125+ id : sync
125126 run : |
126127 set -euo pipefail
127128
@@ -133,8 +134,60 @@ jobs:
133134
134135 if [[ "$dry_run" == "true" ]]; then
135136 echo "::notice::DRY RUN: Would create branch $sync_branch from $target_tag"
137+ echo "sanitized_files=" >> "$GITHUB_OUTPUT"
136138 else
137139 git checkout -b "$sync_branch" "$target_tag"
140+
141+ # Sanitize upstream workflow triggers to prevent unwanted runs
142+ sanitized_files=""
143+ for workflow in .github/workflows/*.yml .github/workflows/*.yaml; do
144+ [ -f "$workflow" ] || continue
145+
146+ # Skip our fork-specific workflows
147+ case "$(basename "$workflow")" in
148+ upstream-sync.yml|rust-ci.yml) continue ;;
149+ esac
150+
151+ echo "Sanitizing: $workflow"
152+
153+ # Replace on: block with workflow_dispatch only using awk
154+ awk '
155+ /^on:/ {
156+ in_on = 1
157+ print "on: workflow_dispatch"
158+ next
159+ }
160+ in_on && /^$/ {
161+ in_on = 0
162+ print
163+ next
164+ }
165+ in_on && /^[^ \t#]/ {
166+ in_on = 0
167+ }
168+ in_on && /^[ \t]/ {
169+ next
170+ }
171+ in_on && /^#/ {
172+ next
173+ }
174+ !in_on { print }
175+ ' "$workflow" > "${workflow}.tmp" && mv "${workflow}.tmp" "$workflow"
176+
177+ sanitized_files="$sanitized_files- \`$(basename "$workflow")\`\n"
178+ done
179+
180+ if [[ -n "$sanitized_files" ]]; then
181+ git add .github/workflows/
182+ git commit -m "chore: sanitize upstream workflow triggers for fork safety"
183+ echo "sanitized_files<<EOF" >> "$GITHUB_OUTPUT"
184+ echo -e "$sanitized_files" >> "$GITHUB_OUTPUT"
185+ echo "EOF" >> "$GITHUB_OUTPUT"
186+ else
187+ echo "::notice::No upstream workflows to sanitize"
188+ echo "sanitized_files=" >> "$GITHUB_OUTPUT"
189+ fi
190+
138191 git push origin "$sync_branch"
139192 fi
140193
@@ -144,6 +197,7 @@ jobs:
144197 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
145198 TARGET_TAG : ${{ steps.tag.outputs.target_tag }}
146199 SYNC_BRANCH : ${{ steps.tag.outputs.sync_branch }}
200+ SANITIZED_FILES : ${{ steps.sync.outputs.sanitized_files }}
147201 DRY_RUN : ${{ inputs.dry_run }}
148202 run : |
149203 set -euo pipefail
@@ -153,6 +207,16 @@ jobs:
153207
154208 pr_title="Sync upstream $TARGET_TAG"
155209
210+ # Build sanitized workflows section
211+ if [[ -n "$SANITIZED_FILES" ]]; then
212+ sanitized_section="### Workflow Sanitization
213+
214+ The following upstream workflows had their triggers replaced with \\\`workflow_dispatch\\\`:
215+ $SANITIZED_FILES"
216+ else
217+ sanitized_section=""
218+ fi
219+
156220 # Build PR body using heredoc
157221 pr_body=$(cat <<EOF
158222 ## Upstream Sync
@@ -165,6 +229,8 @@ jobs:
165229 - **Commits to merge:** ~$commit_count
166230 - **Release notes:** [GitHub Release](https://github.com/openai/codex/releases/tag/$TARGET_TAG)
167231
232+ $sanitized_section
233+
168234 ### Merge Instructions
169235
170236 1. Review the changes for conflicts with our ACP fork work
@@ -201,10 +267,17 @@ jobs:
201267 fi
202268
203269 - name : Summary
270+ env :
271+ SANITIZED_FILES : ${{ steps.sync.outputs.sanitized_files }}
204272 run : |
205273 echo "## Upstream Sync Summary" >> "$GITHUB_STEP_SUMMARY"
206274 echo "" >> "$GITHUB_STEP_SUMMARY"
207275 echo "- **Target tag:** ${{ steps.tag.outputs.target_tag }}" >> "$GITHUB_STEP_SUMMARY"
208276 echo "- **Sync branch:** ${{ steps.tag.outputs.sync_branch }}" >> "$GITHUB_STEP_SUMMARY"
209277 echo "- **Branch existed:** ${{ steps.check.outputs.exists }}" >> "$GITHUB_STEP_SUMMARY"
210278 echo "- **Dry run:** ${{ inputs.dry_run || 'false' }}" >> "$GITHUB_STEP_SUMMARY"
279+ if [[ -n "$SANITIZED_FILES" ]]; then
280+ echo "" >> "$GITHUB_STEP_SUMMARY"
281+ echo "### Sanitized Workflows" >> "$GITHUB_STEP_SUMMARY"
282+ echo "$SANITIZED_FILES" >> "$GITHUB_STEP_SUMMARY"
283+ fi
0 commit comments