|
| 1 | +name: LemonCode host |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "23 * * * *" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: lemoncode-host |
| 13 | + cancel-in-progress: false |
| 14 | + |
| 15 | +defaults: |
| 16 | + run: |
| 17 | + shell: bash |
| 18 | + |
| 19 | +jobs: |
| 20 | + sync: |
| 21 | + name: Sync and validate upstream |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + changed: ${{ steps.merge.outputs.changed }} |
| 25 | + sha: ${{ steps.meta.outputs.sha }} |
| 26 | + version: ${{ steps.meta.outputs.version }} |
| 27 | + steps: |
| 28 | + - name: Check out controlled fork |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + ref: dev |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Merge upstream |
| 35 | + id: merge |
| 36 | + run: | |
| 37 | + git remote add upstream https://github.com/anomalyco/opencode.git |
| 38 | + git fetch upstream dev |
| 39 | + if git merge-base --is-ancestor upstream/dev HEAD; then |
| 40 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + git config user.name "lemoncrow-sync[bot]" |
| 44 | + git config user.email "lemoncrow-sync@users.noreply.github.com" |
| 45 | + git merge --no-edit upstream/dev |
| 46 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 47 | +
|
| 48 | + - name: Set up Bun |
| 49 | + if: steps.merge.outputs.changed == 'true' |
| 50 | + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 |
| 51 | + with: |
| 52 | + bun-version-file: package.json |
| 53 | + |
| 54 | + - name: Install dependencies |
| 55 | + if: steps.merge.outputs.changed == 'true' |
| 56 | + run: bun install --frozen-lockfile |
| 57 | + |
| 58 | + - name: Validate downstream controls |
| 59 | + if: steps.merge.outputs.changed == 'true' |
| 60 | + run: | |
| 61 | + bun test packages/core/test/product.test.ts |
| 62 | + bun --cwd packages/core typecheck |
| 63 | + bun --cwd packages/tui typecheck |
| 64 | + bun --cwd packages/opencode typecheck |
| 65 | +
|
| 66 | + - name: Push validated merge |
| 67 | + if: steps.merge.outputs.changed == 'true' |
| 68 | + run: git push origin HEAD:dev |
| 69 | + |
| 70 | + - name: Resolve build revision |
| 71 | + id: meta |
| 72 | + run: | |
| 73 | + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
| 74 | + echo "version=$(python3 -c 'import json; print(json.load(open("packages/opencode/package.json"))["version"])')" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + build: |
| 77 | + name: Build ${{ matrix.asset }} |
| 78 | + needs: sync |
| 79 | + if: needs.sync.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 80 | + strategy: |
| 81 | + fail-fast: false |
| 82 | + matrix: |
| 83 | + include: |
| 84 | + - runner: ubuntu-latest |
| 85 | + asset: linux-x64 |
| 86 | + - runner: ubuntu-24.04-arm |
| 87 | + asset: linux-arm64 |
| 88 | + - runner: macos-latest |
| 89 | + asset: darwin-arm64 |
| 90 | + - runner: macos-13 |
| 91 | + asset: darwin-x64 |
| 92 | + runs-on: ${{ matrix.runner }} |
| 93 | + steps: |
| 94 | + - name: Check out controlled fork revision |
| 95 | + uses: actions/checkout@v4 |
| 96 | + with: |
| 97 | + ref: ${{ needs.sync.outputs.sha }} |
| 98 | + |
| 99 | + - name: Set up Bun |
| 100 | + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 |
| 101 | + with: |
| 102 | + bun-version-file: package.json |
| 103 | + |
| 104 | + - name: Install dependencies |
| 105 | + run: bun install --frozen-lockfile |
| 106 | + |
| 107 | + - name: Build LemonCode |
| 108 | + working-directory: packages/opencode |
| 109 | + run: bun run script/build.ts --single --skip-embed-web-ui |
| 110 | + |
| 111 | + - name: Upload binary |
| 112 | + uses: actions/upload-artifact@v4 |
| 113 | + with: |
| 114 | + name: lemoncode-${{ matrix.asset }} |
| 115 | + path: packages/opencode/dist/lemoncode-${{ matrix.asset }}/bin/lemoncode |
| 116 | + if-no-files-found: error |
| 117 | + |
| 118 | + release: |
| 119 | + name: Publish verified host release |
| 120 | + needs: [sync, build] |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - name: Download binaries |
| 124 | + uses: actions/download-artifact@v4 |
| 125 | + with: |
| 126 | + pattern: lemoncode-* |
| 127 | + path: artifacts |
| 128 | + |
| 129 | + - name: Package binaries and checksums |
| 130 | + run: | |
| 131 | + mkdir -p release |
| 132 | + for directory in artifacts/lemoncode-*; do |
| 133 | + asset="$(basename "$directory")" |
| 134 | + tar -C "$directory" -czf "release/${asset}.tar.gz" lemoncode |
| 135 | + sha256sum "release/${asset}.tar.gz" > "release/${asset}.tar.gz.sha256" |
| 136 | + done |
| 137 | +
|
| 138 | + - name: Publish release |
| 139 | + env: |
| 140 | + GH_TOKEN: ${{ github.token }} |
| 141 | + FORK_REPO: ${{ github.repository }} |
| 142 | + HOST_SHA: ${{ needs.sync.outputs.sha }} |
| 143 | + HOST_VERSION: ${{ needs.sync.outputs.version }} |
| 144 | + run: | |
| 145 | + short="${HOST_SHA:0:12}" |
| 146 | + tag="v${HOST_VERSION}-lemoncode.${short}" |
| 147 | + if gh release view "$tag" --repo "$FORK_REPO" >/dev/null 2>&1; then |
| 148 | + gh release upload "$tag" release/* --clobber --repo "$FORK_REPO" |
| 149 | + exit 0 |
| 150 | + fi |
| 151 | + gh release create "$tag" release/* --repo "$FORK_REPO" --target "$HOST_SHA" --latest --title "LemonCode ${HOST_VERSION} (${short})" --notes "Controlled LemonCode host built from upstream OpenCode ${HOST_VERSION}; downstream source and attribution remain in the fork." |
0 commit comments