From ae235f715589216ed9747d46d0b1894482353e12 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 1 Mar 2026 20:13:24 -0800 Subject: [PATCH] feat(ci): add release workflow_dispatch version tagging Co-authored-by: codex --- .github/workflows/release.yml | 99 ++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dcf2933f68cfd0eb2a8ff21399f69a96bc924472..fc65b22da5a2e34f42b514686364d8b77bc57450 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,12 @@ on: push: tags: - "v*.*.*" + workflow_dispatch: + inputs: + version: + description: "Release version (for example 1.2.3 or v1.2.3)" + required: true + type: string permissions: contents: write @@ -14,10 +20,33 @@ jobs: name: Preflight runs-on: ubuntu-24.04 outputs: - version: ${{ steps.version.outputs.value }} + version: ${{ steps.release_meta.outputs.version }} + tag: ${{ steps.release_meta.outputs.tag }} + ref: ${{ steps.release_ref.outputs.value }} steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - id: release_meta + name: Resolve release version + shell: bash + run: | + if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then + raw="${{ github.event.inputs.version }}" + else + raw="${GITHUB_REF_NAME}" + fi + + version="${raw#v}" + if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then + echo "Invalid release version: $raw" >&2 + exit 1 + fi + + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "tag=v$version" >> "$GITHUB_OUTPUT" - name: Setup Bun uses: oven-sh/setup-bun@v2 @@ -29,6 +58,65 @@ jobs: with: node-version-file: package.json + - name: Update version strings + if: github.event_name == 'workflow_dispatch' + env: + RELEASE_VERSION: ${{ steps.release_meta.outputs.version }} + run: | + node --input-type=module -e ' + import { readFileSync, writeFileSync } from "node:fs"; + + const files = [ + "apps/server/package.json", + "apps/desktop/package.json", + "apps/web/package.json", + "packages/contracts/package.json", + ]; + + for (const file of files) { + const packageJson = JSON.parse(readFileSync(file, "utf8")); + packageJson.version = process.env.RELEASE_VERSION; + writeFileSync(file, `${JSON.stringify(packageJson, null, 2)}\n`); + } + ' + + - name: Refresh lockfile + if: github.event_name == 'workflow_dispatch' + run: bun install + + - name: Commit and push release version + tag + if: github.event_name == 'workflow_dispatch' + shell: bash + env: + RELEASE_TAG: ${{ steps.release_meta.outputs.tag }} + run: | + if git ls-remote --exit-code --tags origin "$RELEASE_TAG" >/dev/null 2>&1; then + echo "Tag $RELEASE_TAG already exists on origin." >&2 + exit 1 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + if ! git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock; then + git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock + git commit -m "chore(release): prepare $RELEASE_TAG" -m "Co-authored-by: codex " + fi + + git tag "$RELEASE_TAG" + git push origin "HEAD:${GITHUB_REF_NAME}" + git push origin "refs/tags/$RELEASE_TAG" + + - id: release_ref + name: Resolve source ref + shell: bash + run: | + if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then + echo "value=refs/tags/${{ steps.release_meta.outputs.tag }}" >> "$GITHUB_OUTPUT" + else + echo "value=${GITHUB_SHA}" >> "$GITHUB_OUTPUT" + fi + - name: Install dependencies run: bun install --frozen-lockfile @@ -41,10 +129,6 @@ jobs: - name: Test run: bun run test - - id: version - name: Resolve release version - run: echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" - build: name: Build ${{ matrix.label }} needs: preflight @@ -76,6 +160,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: ${{ needs.preflight.outputs.ref }} + fetch-depth: 0 - name: Setup Bun uses: oven-sh/setup-bun@v2 @@ -215,7 +302,7 @@ jobs: - name: Publish release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref_name }} + tag_name: ${{ needs.preflight.outputs.tag }} name: T3 Code v${{ needs.preflight.outputs.version }} generate_release_notes: true files: release-assets/* -- 2.54.0