|
| 1 | +# Automatically sync stable upstream releases into dev branch. |
| 2 | +# Creates a sync branch and draft PR for each new stable release. |
| 3 | +# |
| 4 | +# Manual trigger: gh workflow run upstream-sync.yml |
| 5 | +# With specific tag: gh workflow run upstream-sync.yml -f tag=rust-v0.63.0 |
| 6 | +# Dry run: gh workflow run upstream-sync.yml -f dry_run=true |
| 7 | + |
| 8 | +name: upstream-sync |
| 9 | + |
| 10 | +on: |
| 11 | + schedule: |
| 12 | + # Daily at 9 AM UTC (reasonable time for review in US timezones) |
| 13 | + - cron: '0 9 * * *' |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + tag: |
| 17 | + description: 'Specific tag to sync (optional, defaults to latest stable)' |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + dry_run: |
| 21 | + description: 'Dry run mode (log actions without creating branches/PRs)' |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + default: false |
| 25 | + |
| 26 | +env: |
| 27 | + UPSTREAM_REMOTE: https://github.com/openai/codex.git |
| 28 | + |
| 29 | +jobs: |
| 30 | + sync: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: write |
| 34 | + pull-requests: write |
| 35 | + steps: |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Configure git |
| 43 | + run: | |
| 44 | + git config user.name "github-actions[bot]" |
| 45 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 46 | +
|
| 47 | + - name: Add upstream remote and fetch tags |
| 48 | + run: | |
| 49 | + git remote add upstream "$UPSTREAM_REMOTE" || git remote set-url upstream "$UPSTREAM_REMOTE" |
| 50 | + git fetch upstream --tags --force |
| 51 | +
|
| 52 | + - name: Determine target tag |
| 53 | + id: tag |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | +
|
| 57 | + if [[ -n "${{ inputs.tag }}" ]]; then |
| 58 | + target_tag="${{ inputs.tag }}" |
| 59 | + echo "Using manually specified tag: $target_tag" |
| 60 | + else |
| 61 | + # Find latest stable tag (X.Y.Z only, no alpha/beta/rc) |
| 62 | + # Pattern: rust-v followed by semver without prerelease suffix |
| 63 | + target_tag=$(git tag -l 'rust-v*' \ |
| 64 | + | grep -E '^rust-v[0-9]+\.[0-9]+\.[0-9]+$' \ |
| 65 | + | sort -V \ |
| 66 | + | tail -1) |
| 67 | + echo "Detected latest stable tag: $target_tag" |
| 68 | + fi |
| 69 | +
|
| 70 | + if [[ -z "$target_tag" ]]; then |
| 71 | + echo "::error::No stable upstream tag found" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + # Validate tag exists |
| 76 | + if ! git rev-parse "$target_tag" >/dev/null 2>&1; then |
| 77 | + echo "::error::Tag $target_tag does not exist" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | +
|
| 81 | + # Extract version for branch naming (rust-v0.63.0 -> v0.63.0) |
| 82 | + version="${target_tag#rust-}" |
| 83 | + sync_branch="sync/upstream-${version}" |
| 84 | +
|
| 85 | + echo "target_tag=$target_tag" >> "$GITHUB_OUTPUT" |
| 86 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 87 | + echo "sync_branch=$sync_branch" >> "$GITHUB_OUTPUT" |
| 88 | +
|
| 89 | + - name: Check if sync branch already exists |
| 90 | + id: check |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | +
|
| 94 | + sync_branch="${{ steps.tag.outputs.sync_branch }}" |
| 95 | +
|
| 96 | + # Check if branch exists on origin |
| 97 | + if git ls-remote --heads origin "$sync_branch" | grep -q "$sync_branch"; then |
| 98 | + echo "::notice::Sync branch $sync_branch already exists, skipping" |
| 99 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 100 | + else |
| 101 | + echo "Sync branch $sync_branch does not exist, will create" |
| 102 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 103 | + fi |
| 104 | +
|
| 105 | + - name: Update fork/upstream-sync tracking branch |
| 106 | + if: steps.check.outputs.exists == 'false' |
| 107 | + run: | |
| 108 | + set -euo pipefail |
| 109 | +
|
| 110 | + target_tag="${{ steps.tag.outputs.target_tag }}" |
| 111 | + dry_run="${{ inputs.dry_run }}" |
| 112 | +
|
| 113 | + echo "Updating fork/upstream-sync to point to $target_tag" |
| 114 | +
|
| 115 | + if [[ "$dry_run" == "true" ]]; then |
| 116 | + echo "::notice::DRY RUN: Would update fork/upstream-sync to $target_tag" |
| 117 | + else |
| 118 | + # Create or update the tracking branch |
| 119 | + git branch -f fork/upstream-sync "$target_tag" |
| 120 | + git push origin fork/upstream-sync --force |
| 121 | + fi |
| 122 | +
|
| 123 | + - name: Create sync branch |
| 124 | + if: steps.check.outputs.exists == 'false' |
| 125 | + run: | |
| 126 | + set -euo pipefail |
| 127 | +
|
| 128 | + target_tag="${{ steps.tag.outputs.target_tag }}" |
| 129 | + sync_branch="${{ steps.tag.outputs.sync_branch }}" |
| 130 | + dry_run="${{ inputs.dry_run }}" |
| 131 | +
|
| 132 | + echo "Creating sync branch $sync_branch from $target_tag" |
| 133 | +
|
| 134 | + if [[ "$dry_run" == "true" ]]; then |
| 135 | + echo "::notice::DRY RUN: Would create branch $sync_branch from $target_tag" |
| 136 | + else |
| 137 | + git checkout -b "$sync_branch" "$target_tag" |
| 138 | + git push origin "$sync_branch" |
| 139 | + fi |
| 140 | +
|
| 141 | + - name: Create draft PR |
| 142 | + if: steps.check.outputs.exists == 'false' |
| 143 | + env: |
| 144 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + TARGET_TAG: ${{ steps.tag.outputs.target_tag }} |
| 146 | + SYNC_BRANCH: ${{ steps.tag.outputs.sync_branch }} |
| 147 | + DRY_RUN: ${{ inputs.dry_run }} |
| 148 | + run: | |
| 149 | + set -euo pipefail |
| 150 | +
|
| 151 | + # Count commits between dev and the tag for context |
| 152 | + commit_count=$(git rev-list --count origin/dev.."$TARGET_TAG" 2>/dev/null || echo "unknown") |
| 153 | +
|
| 154 | + pr_title="Sync upstream $TARGET_TAG" |
| 155 | +
|
| 156 | + # Build PR body using heredoc |
| 157 | + pr_body=$(cat <<EOF |
| 158 | + ## Upstream Sync |
| 159 | +
|
| 160 | + This PR syncs changes from upstream release \`$TARGET_TAG\`. |
| 161 | +
|
| 162 | + ### Summary |
| 163 | +
|
| 164 | + - **Upstream tag:** \`$TARGET_TAG\` |
| 165 | + - **Commits to merge:** ~$commit_count |
| 166 | + - **Release notes:** [GitHub Release](https://github.com/openai/codex/releases/tag/$TARGET_TAG) |
| 167 | +
|
| 168 | + ### Merge Instructions |
| 169 | +
|
| 170 | + 1. Review the changes for conflicts with our ACP fork work |
| 171 | + 2. Resolve any merge conflicts: |
| 172 | + \`\`\`bash |
| 173 | + git checkout dev |
| 174 | + git merge $SYNC_BRANCH --no-ff |
| 175 | + # Resolve conflicts if any |
| 176 | + \`\`\` |
| 177 | + 3. Run tests: \`cd codex-rs && cargo test\` |
| 178 | + 4. Update snapshot tests if needed: \`cargo insta review\` |
| 179 | + 5. Mark as ready for review when satisfied |
| 180 | +
|
| 181 | + ### After Merge |
| 182 | +
|
| 183 | + - Delete the \`$SYNC_BRANCH\` branch |
| 184 | + - Consider tagging a new nori release if significant changes |
| 185 | + EOF |
| 186 | + ) |
| 187 | +
|
| 188 | + if [[ "$DRY_RUN" == "true" ]]; then |
| 189 | + echo "::notice::DRY RUN: Would create PR with title: $pr_title" |
| 190 | + echo "PR body would be:" |
| 191 | + echo "$pr_body" |
| 192 | + else |
| 193 | + gh pr create \ |
| 194 | + --base dev \ |
| 195 | + --head "$SYNC_BRANCH" \ |
| 196 | + --title "$pr_title" \ |
| 197 | + --body "$pr_body" \ |
| 198 | + --draft |
| 199 | +
|
| 200 | + echo "::notice::Created draft PR for $TARGET_TAG" |
| 201 | + fi |
| 202 | +
|
| 203 | + - name: Summary |
| 204 | + run: | |
| 205 | + echo "## Upstream Sync Summary" >> "$GITHUB_STEP_SUMMARY" |
| 206 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 207 | + echo "- **Target tag:** ${{ steps.tag.outputs.target_tag }}" >> "$GITHUB_STEP_SUMMARY" |
| 208 | + echo "- **Sync branch:** ${{ steps.tag.outputs.sync_branch }}" >> "$GITHUB_STEP_SUMMARY" |
| 209 | + echo "- **Branch existed:** ${{ steps.check.outputs.exists }}" >> "$GITHUB_STEP_SUMMARY" |
| 210 | + echo "- **Dry run:** ${{ inputs.dry_run || 'false' }}" >> "$GITHUB_STEP_SUMMARY" |
0 commit comments