|
| 1 | +name: Sync private features with upstream |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "17 */6 * * *" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + issues: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: sync-private-features-with-upstream |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +env: |
| 17 | + PRIVATE_BRANCH: agent/private-quick-chat-window-zoom |
| 18 | + UPSTREAM_REPOSITORY: ilysenko/codex-desktop-linux |
| 19 | + |
| 20 | +jobs: |
| 21 | + sync: |
| 22 | + name: Merge, validate, and publish upstream |
| 23 | + runs-on: ubuntu-latest |
| 24 | + timeout-minutes: 45 |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v7 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + persist-credentials: false |
| 30 | + ref: ${{ env.PRIVATE_BRANCH }} |
| 31 | + |
| 32 | + - name: Merge current upstream main |
| 33 | + id: merge |
| 34 | + env: |
| 35 | + UPSTREAM_URL: https://github.com/${{ env.UPSTREAM_REPOSITORY }}.git |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | +
|
| 39 | + git config user.name github-actions[bot] |
| 40 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 41 | + git remote add upstream "$UPSTREAM_URL" |
| 42 | + git fetch --no-tags upstream main |
| 43 | +
|
| 44 | + if git merge-base --is-ancestor upstream/main HEAD; then |
| 45 | + echo 'changed=false' >> "$GITHUB_OUTPUT" |
| 46 | + exit 0 |
| 47 | + fi |
| 48 | +
|
| 49 | + git merge --no-edit upstream/main |
| 50 | + echo 'changed=true' >> "$GITHUB_OUTPUT" |
| 51 | +
|
| 52 | + - name: Test private Quick Chat feature |
| 53 | + if: steps.merge.outputs.changed == 'true' |
| 54 | + run: node --test linux-features/local/quick-chat-window-zoom/test.js |
| 55 | + |
| 56 | + - name: Test the complete patch engine |
| 57 | + if: steps.merge.outputs.changed == 'true' |
| 58 | + run: node --test scripts/patch-linux-window-ui.test.js |
| 59 | + |
| 60 | + - name: Install Nix |
| 61 | + if: steps.merge.outputs.changed == 'true' |
| 62 | + uses: cachix/install-nix-action@v31 |
| 63 | + |
| 64 | + - name: Evaluate the merged Nix flake |
| 65 | + if: steps.merge.outputs.changed == 'true' |
| 66 | + run: nix flake check --no-build --print-build-logs |
| 67 | + |
| 68 | + - name: Publish the validated private branch |
| 69 | + if: steps.merge.outputs.changed == 'true' |
| 70 | + env: |
| 71 | + GH_TOKEN: ${{ github.token }} |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | + auth_header="$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)" |
| 75 | + git -c http.https://github.com/.extraheader="AUTHORIZATION: basic ${auth_header}" \ |
| 76 | + push origin "HEAD:${PRIVATE_BRANCH}" |
| 77 | +
|
| 78 | + - name: Record synchronization failure |
| 79 | + if: failure() |
| 80 | + uses: actions/github-script@v9 |
| 81 | + with: |
| 82 | + script: | |
| 83 | + const title = "Automated private-feature upstream sync failed"; |
| 84 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 85 | + const body = [ |
| 86 | + "The scheduled merge of `ilysenko/codex-desktop-linux:main` into the private feature branch failed.", |
| 87 | + "", |
| 88 | + `Workflow run: ${runUrl}`, |
| 89 | + "", |
| 90 | + "The private branch and deployed package were not advanced. Resolve the merge or patch drift locally, then rerun the workflow.", |
| 91 | + ].join("\n"); |
| 92 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 93 | + ...context.repo, |
| 94 | + state: "open", |
| 95 | + per_page: 100, |
| 96 | + }); |
| 97 | + const existing = issues.find((issue) => issue.title === title); |
| 98 | + if (existing) { |
| 99 | + await github.rest.issues.createComment({ |
| 100 | + ...context.repo, |
| 101 | + issue_number: existing.number, |
| 102 | + body, |
| 103 | + }); |
| 104 | + } else { |
| 105 | + await github.rest.issues.create({ ...context.repo, title, body }); |
| 106 | + } |
| 107 | +
|
| 108 | + - name: Close resolved synchronization failure |
| 109 | + if: success() |
| 110 | + uses: actions/github-script@v9 |
| 111 | + with: |
| 112 | + script: | |
| 113 | + const title = "Automated private-feature upstream sync failed"; |
| 114 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 115 | + ...context.repo, |
| 116 | + state: "open", |
| 117 | + per_page: 100, |
| 118 | + }); |
| 119 | + const existing = issues.find((issue) => issue.title === title); |
| 120 | + if (existing) { |
| 121 | + await github.rest.issues.update({ |
| 122 | + ...context.repo, |
| 123 | + issue_number: existing.number, |
| 124 | + state: "closed", |
| 125 | + state_reason: "completed", |
| 126 | + }); |
| 127 | + } |
0 commit comments