a welan release #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: a welan release | |
| # Fork patch author: only contiguous commits at the tip of origin/welan authored by this | |
| # name are cherry-picked onto the upstream release tag. | |
| # | |
| # 第 1,配置自己的上游仓库地址 https://github.com/anomalyco/opencode | |
| # 第 2,根据 CI 输入的 version 号,确保它是一个上游的 tag。如果输入的 version 号为空,那么自动从上游的 tag 里面获取最新的 tag 作为 version 号来工作。 | |
| # 第 3:检出上游分支的 tag 代码,再从当前仓库的 origin 缺省分支 的 顶端 commit 开始向下遍历,收集顶部连续的 作者 weizhoublue 的 commits , cherry-pick 到上游的 tag 分支 。 | |
| # 第 4,运行所有单元测试,确保 cherry-pick 后行为正确 。 | |
| # 第 5,我们分别构建 macOS、ARM 的 Linux、x86 的 Linux、ARM 的二进制。 | |
| # 第 6 ,我们将 origin 缺省分支推送到远端,并且新建一个 release/$version 的新 branch 推送到远端进行留存。 | |
| # 第 7 ,我们发布一个 version 对应的 release, 其中带上构建物 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Upstream release tag. Defaults to latest upstream tag." | |
| required: false | |
| type: string | |
| concurrency: | |
| group: ${{ github.workflow }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| GH_TOKEN: ${{ secrets.WELAN_PAT }} | |
| PATCH_AUTHOR: weizhoublue | |
| BRANCH_NAME: welan | |
| UPSTREAM_URL: https://github.com/anomalyco/opencode.git | |
| jobs: | |
| release: | |
| name: sync, validate, build, release | |
| runs-on: ubuntu-24.04 | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ env.GH_TOKEN }} | |
| - name: Configure git identity | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| #---------------------- rebase and cherry-pick ----------------------- | |
| - name: Resolve tag and sync fork branch | |
| run: | | |
| if git remote get-url upstream >/dev/null 2>&1; then | |
| git remote set-url upstream "$UPSTREAM_URL" | |
| else | |
| git remote add upstream "$UPSTREAM_URL" | |
| fi | |
| version="${{ inputs.version }}" | |
| if [ -z "$version" ]; then | |
| remote_tags="$(git ls-remote --tags --sort=-v:refname upstream 'refs/tags/v[0-9]*')" | |
| version="$(awk 'index($2, "^{}") == 0 { sub("refs/tags/", "", $2); print $2; exit }' <<< "$remote_tags")" | |
| fi | |
| if [ -z "$version" ]; then | |
| echo "No upstream tag found" | |
| exit 1 | |
| fi | |
| build_version="${version#v}" | |
| echo "Using upstream tag: $version" | |
| echo "Using build version: $build_version" | |
| echo "RELEASE_TAG=$version" >> "$GITHUB_ENV" | |
| echo "BUILD_VERSION=$build_version" >> "$GITHUB_ENV" | |
| # cherry-pick contiguous commits authored by $PATCH_AUTHOR from origin/$BRANCH_NAME onto upstream tag | |
| export UPSTREAM_URL="$UPSTREAM_URL" | |
| export PATCH_AUTHOR="$PATCH_AUTHOR" | |
| export BRANCH_NAME="$BRANCH_NAME" | |
| export UPSTREAM_RELEASE_TAG="$version" | |
| ./.github/fork-sync.sh | |
| #---------------------- test ----------------------- | |
| - name: Setup Bun | |
| uses: ./.github/actions/setup-bun | |
| - name: Run opencode tests | |
| working-directory: packages/opencode | |
| timeout-minutes: 20 | |
| run: | | |
| find test \( -name '*.test.ts' -o -name '*.test.tsx' \) ! -name 'run-process*.test.ts' -print0 \ | |
| | xargs -0 bun test --timeout 60000 | |
| bun test --timeout 60000 --max-concurrency=1 test/cli/run/run-process-limit.test.ts | |
| bun test --timeout 60000 --max-concurrency=1 test/cli/run/run-process.test.ts \ | |
| --test-name-pattern='exits 0 and writes|prints each|prints reasoning|unknown stream|format json|rejects requested|attach mode|SIGINT' | |
| env: | |
| GITHUB_ACTIONS: "false" | |
| #---------------------- build ----------------------- | |
| - name: Build CLI binaries | |
| run: OPENCODE_VERSION="$BUILD_VERSION" ./packages/opencode/script/build.ts | |
| - name: Stage release binaries | |
| run: | | |
| asset_dir="/tmp/$BRANCH_NAME-release-assets" | |
| rm -rf "$asset_dir" | |
| mkdir -p "$asset_dir" | |
| cp packages/opencode/dist/opencode-darwin-arm64/bin/opencode "$asset_dir/opencode-darwin-arm64" | |
| cp packages/opencode/dist/opencode-linux-arm64/bin/opencode "$asset_dir/opencode-linux-arm64" | |
| cp packages/opencode/dist/opencode-linux-x64/bin/opencode "$asset_dir/opencode-linux-x64" | |
| ls -lh "$asset_dir" | |
| #---------------------- push and release ----------------------- | |
| - name: Push rebased branch | |
| run: git push origin "HEAD:$BRANCH_NAME" --force-with-lease | |
| - name: Push release archive branch | |
| run: | | |
| release_branch="release-welan/$RELEASE_TAG" | |
| git checkout -B "$release_branch" | |
| git push origin "$release_branch" --force-with-lease | |
| - name: Replace GitHub release | |
| run: | | |
| tag="$RELEASE_TAG" | |
| target="$(git rev-parse HEAD)" | |
| asset_dir="/tmp/$BRANCH_NAME-release-assets" | |
| gh release delete "$tag" --repo "${{ github.repository }}" --yes 2>/dev/null || true | |
| git tag -f "$tag" "$target" | |
| git push origin "refs/tags/$tag" --force | |
| gh release create "$tag" \ | |
| "$asset_dir/opencode-darwin-arm64" \ | |
| "$asset_dir/opencode-linux-arm64" \ | |
| "$asset_dir/opencode-linux-x64" \ | |
| --repo "${{ github.repository }}" \ | |
| --target "$target" \ | |
| --title "$tag" \ | |
| --notes "Fork release: upstream ${RELEASE_TAG} plus tip commits authored by ${PATCH_AUTHOR} at ${target}." |