|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + |
| 8 | +env: |
| 9 | + CARGO_TERM_COLOR: always |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build Release (${{ matrix.target }}) |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + timeout-minutes: 45 |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - os: ubuntu-latest |
| 21 | + target: x86_64-unknown-linux-gnu |
| 22 | + artifact_name: mcp-cli |
| 23 | + asset_name: mcp-cli-linux-amd64 |
| 24 | + - os: ubuntu-latest |
| 25 | + target: aarch64-unknown-linux-gnu |
| 26 | + artifact_name: mcp-cli |
| 27 | + asset_name: mcp-cli-linux-arm64 |
| 28 | + - os: macos-latest |
| 29 | + target: x86_64-apple-darwin |
| 30 | + artifact_name: mcp-cli |
| 31 | + asset_name: mcp-cli-macos-amd64 |
| 32 | + - os: macos-latest |
| 33 | + target: aarch64-apple-darwin |
| 34 | + artifact_name: mcp-cli |
| 35 | + asset_name: mcp-cli-macos-arm64 |
| 36 | + - os: windows-latest |
| 37 | + target: x86_64-pc-windows-msvc |
| 38 | + artifact_name: mcp-cli.exe |
| 39 | + asset_name: mcp-cli-windows-amd64.exe |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v5 |
| 43 | + |
| 44 | + - name: Install Rust |
| 45 | + uses: dtolnay/rust-toolchain@stable |
| 46 | + with: |
| 47 | + targets: ${{ matrix.target }} |
| 48 | + |
| 49 | + # Install cross-compilation tools for ARM Linux |
| 50 | + - name: Install cross-compilation tools (ARM Linux) |
| 51 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 52 | + run: | |
| 53 | + sudo apt-get update |
| 54 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 55 | +
|
| 56 | + - name: Setup sccache |
| 57 | + uses: mozilla-actions/[email protected] |
| 58 | + |
| 59 | + - name: Configure sccache |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV |
| 63 | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV |
| 64 | +
|
| 65 | + - name: Cache Cargo |
| 66 | + uses: Swatinem/rust-cache@v2 |
| 67 | + with: |
| 68 | + shared-key: "release-${{ matrix.target }}" |
| 69 | + |
| 70 | + - name: Build release |
| 71 | + run: cargo build --release --target ${{ matrix.target }} --package mcp-cli |
| 72 | + env: |
| 73 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 74 | + |
| 75 | + - name: Strip binary (Unix) |
| 76 | + if: matrix.os != 'windows-latest' |
| 77 | + run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} |
| 78 | + |
| 79 | + - name: Package binaries (Unix) |
| 80 | + if: matrix.os != 'windows-latest' |
| 81 | + run: | |
| 82 | + cd target/${{ matrix.target }}/release |
| 83 | + tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }} |
| 84 | +
|
| 85 | + - name: Package binaries (Windows) |
| 86 | + if: matrix.os == 'windows-latest' |
| 87 | + run: | |
| 88 | + cd target/${{ matrix.target }}/release |
| 89 | + 7z a ../../../${{ matrix.asset_name }}.zip ${{ matrix.artifact_name }} |
| 90 | +
|
| 91 | + - name: Upload artifacts |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: ${{ matrix.asset_name }} |
| 95 | + path: | |
| 96 | + ${{ matrix.asset_name }}.tar.gz |
| 97 | + ${{ matrix.asset_name }}.zip |
| 98 | + retention-days: 7 |
| 99 | + |
| 100 | + release: |
| 101 | + name: Create Release |
| 102 | + needs: build |
| 103 | + runs-on: ubuntu-latest |
| 104 | + permissions: |
| 105 | + contents: write |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v5 |
| 108 | + with: |
| 109 | + fetch-depth: 0 |
| 110 | + |
| 111 | + - name: Download artifacts |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + path: artifacts |
| 115 | + |
| 116 | + - name: Generate changelog |
| 117 | + id: changelog |
| 118 | + run: | |
| 119 | + echo "## Changes in this Release" > CHANGELOG.md |
| 120 | + echo "" >> CHANGELOG.md |
| 121 | + git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md || echo "- Initial release" >> CHANGELOG.md |
| 122 | +
|
| 123 | + - name: Create Release |
| 124 | + uses: softprops/action-gh-release@v2 |
| 125 | + with: |
| 126 | + files: artifacts/**/* |
| 127 | + body_path: CHANGELOG.md |
| 128 | + draft: false |
| 129 | + prerelease: false |
| 130 | + generate_release_notes: true |
| 131 | + env: |
| 132 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments