|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + dry_run: |
| 9 | + description: 'Dry run (skip publish)' |
| 10 | + type: boolean |
| 11 | + default: false |
| 12 | + |
| 13 | +env: |
| 14 | + CARGO_TERM_COLOR: always |
| 15 | + RUST_BACKTRACE: 1 |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-cli: |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - { target: x86_64-apple-darwin, os: macos-13 } |
| 24 | + - { target: aarch64-apple-darwin, os: macos-14 } |
| 25 | + - { target: x86_64-unknown-linux-gnu, os: ubuntu-latest } |
| 26 | + - { target: aarch64-unknown-linux-gnu, os: ubuntu-latest } |
| 27 | + - { target: x86_64-pc-windows-msvc, os: windows-latest } |
| 28 | + |
| 29 | + runs-on: ${{ matrix.os }} |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Setup Rust |
| 35 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 36 | + with: |
| 37 | + toolchain: stable |
| 38 | + target: ${{ matrix.target }} |
| 39 | + cache-workspaces: packages/nestjs-trpc/cli -> target |
| 40 | + |
| 41 | + - name: Install cross (Linux ARM64) |
| 42 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 43 | + run: cargo install cross --git https://github.com/cross-rs/cross |
| 44 | + |
| 45 | + - name: Build CLI |
| 46 | + shell: bash |
| 47 | + run: ./scripts/build-cli.sh --target ${{ matrix.target }} |
| 48 | + |
| 49 | + - name: Upload artifact |
| 50 | + uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: cli-${{ matrix.target }} |
| 53 | + path: packages/nestjs-trpc/native/${{ matrix.target }}/ |
| 54 | + retention-days: 1 |
| 55 | + |
| 56 | + publish: |
| 57 | + needs: build-cli |
| 58 | + runs-on: ubuntu-latest |
| 59 | + permissions: |
| 60 | + contents: write |
| 61 | + id-token: write |
| 62 | + steps: |
| 63 | + - name: Checkout |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + fetch-depth: 0 |
| 67 | + |
| 68 | + - name: Setup Bun |
| 69 | + uses: oven-sh/setup-bun@v2 |
| 70 | + |
| 71 | + - name: Setup Node.js |
| 72 | + uses: actions/setup-node@v4 |
| 73 | + with: |
| 74 | + node-version: '20' |
| 75 | + registry-url: 'https://registry.npmjs.org' |
| 76 | + |
| 77 | + - name: Install git-cliff |
| 78 | + uses: taiki-e/install-action@v2 |
| 79 | + with: |
| 80 | + tool: git-cliff |
| 81 | + |
| 82 | + - name: Install dependencies |
| 83 | + run: bun install --frozen-lockfile |
| 84 | + |
| 85 | + - name: Build TypeScript |
| 86 | + run: bun run build |
| 87 | + |
| 88 | + - name: Download all CLI binaries |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + path: packages/nestjs-trpc/native/ |
| 92 | + pattern: cli-* |
| 93 | + merge-multiple: true |
| 94 | + |
| 95 | + - name: Verify binaries |
| 96 | + run: | |
| 97 | + for target in x86_64-apple-darwin aarch64-apple-darwin x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu; do |
| 98 | + test -f "packages/nestjs-trpc/native/$target/nestjs-trpc" || { echo "Missing: $target"; exit 1; } |
| 99 | + done |
| 100 | + test -f "packages/nestjs-trpc/native/x86_64-pc-windows-msvc/nestjs-trpc.exe" || { echo "Missing: windows"; exit 1; } |
| 101 | + chmod +x packages/nestjs-trpc/native/x86_64-unknown-linux-gnu/nestjs-trpc |
| 102 | + packages/nestjs-trpc/native/x86_64-unknown-linux-gnu/nestjs-trpc --help |
| 103 | +
|
| 104 | + - name: Extract version from tag |
| 105 | + id: version |
| 106 | + run: | |
| 107 | + if [[ "$GITHUB_REF" == refs/tags/v* ]]; then |
| 108 | + VERSION="${GITHUB_REF#refs/tags/v}" |
| 109 | + else |
| 110 | + VERSION=$(jq -r '.version' packages/nestjs-trpc/package.json) |
| 111 | + fi |
| 112 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 113 | + echo "Version: $VERSION" |
| 114 | +
|
| 115 | + - name: Update package.json version |
| 116 | + working-directory: packages/nestjs-trpc |
| 117 | + run: npm version ${{ steps.version.outputs.version }} --no-git-tag-version |
| 118 | + |
| 119 | + - name: Update Cargo.toml version |
| 120 | + run: | |
| 121 | + sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.version }}"/' packages/nestjs-trpc/cli/Cargo.toml |
| 122 | +
|
| 123 | + - name: Generate changelog |
| 124 | + id: changelog |
| 125 | + run: | |
| 126 | + git-cliff --tag "v${{ steps.version.outputs.version }}" -o CHANGELOG.md |
| 127 | + git-cliff --unreleased --tag "v${{ steps.version.outputs.version }}" > RELEASE_NOTES.md |
| 128 | +
|
| 129 | + { |
| 130 | + echo 'changelog<<EOF' |
| 131 | + cat RELEASE_NOTES.md |
| 132 | + echo EOF |
| 133 | + } >> $GITHUB_OUTPUT |
| 134 | +
|
| 135 | + - name: Publish to npm |
| 136 | + if: ${{ github.event_name == 'push' || !inputs.dry_run }} |
| 137 | + working-directory: packages/nestjs-trpc |
| 138 | + run: npm publish --provenance --access public |
| 139 | + env: |
| 140 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 141 | + |
| 142 | + - name: Publish to npm (dry run) |
| 143 | + if: ${{ github.event_name != 'push' && inputs.dry_run }} |
| 144 | + working-directory: packages/nestjs-trpc |
| 145 | + run: | |
| 146 | + echo "DRY RUN: Would publish to npm" |
| 147 | + npm pack |
| 148 | +
|
| 149 | + - name: Prepare release assets |
| 150 | + run: | |
| 151 | + mkdir -p release-assets |
| 152 | + cp packages/nestjs-trpc/native/x86_64-apple-darwin/nestjs-trpc release-assets/nestjs-trpc-macos-x64 |
| 153 | + cp packages/nestjs-trpc/native/aarch64-apple-darwin/nestjs-trpc release-assets/nestjs-trpc-macos-arm64 |
| 154 | + cp packages/nestjs-trpc/native/x86_64-unknown-linux-gnu/nestjs-trpc release-assets/nestjs-trpc-linux-x64 |
| 155 | + cp packages/nestjs-trpc/native/aarch64-unknown-linux-gnu/nestjs-trpc release-assets/nestjs-trpc-linux-arm64 |
| 156 | + cp packages/nestjs-trpc/native/x86_64-pc-windows-msvc/nestjs-trpc.exe release-assets/nestjs-trpc-windows-x64.exe |
| 157 | +
|
| 158 | + cd release-assets && sha256sum * > checksums.txt |
| 159 | + cat checksums.txt |
| 160 | +
|
| 161 | + - name: Create GitHub Release |
| 162 | + if: ${{ github.event_name == 'push' || !inputs.dry_run }} |
| 163 | + uses: softprops/action-gh-release@v2 |
| 164 | + with: |
| 165 | + tag_name: v${{ steps.version.outputs.version }} |
| 166 | + name: v${{ steps.version.outputs.version }} |
| 167 | + body: ${{ steps.changelog.outputs.changelog }} |
| 168 | + draft: false |
| 169 | + prerelease: ${{ contains(steps.version.outputs.version, '-') }} |
| 170 | + files: | |
| 171 | + release-assets/nestjs-trpc-macos-x64 |
| 172 | + release-assets/nestjs-trpc-macos-arm64 |
| 173 | + release-assets/nestjs-trpc-linux-x64 |
| 174 | + release-assets/nestjs-trpc-linux-arm64 |
| 175 | + release-assets/nestjs-trpc-windows-x64.exe |
| 176 | + release-assets/checksums.txt |
| 177 | +
|
0 commit comments