|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Tag to release (e.g., v0.1.0)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: release-${{ github.ref }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +env: |
| 19 | + CARGO_TERM_COLOR: always |
| 20 | + RUSTFLAGS: "-C strip=symbols" |
| 21 | + |
| 22 | +jobs: |
| 23 | + release-build: |
| 24 | + name: Build Release Binaries |
| 25 | + runs-on: ${{ matrix.os }} |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + include: |
| 30 | + - os: ubuntu-latest |
| 31 | + target: x86_64-unknown-linux-gnu |
| 32 | + artifact: tiny-proxy-linux-amd64 |
| 33 | + use-cross: false |
| 34 | + |
| 35 | + - os: ubuntu-latest |
| 36 | + target: aarch64-unknown-linux-gnu |
| 37 | + artifact: tiny-proxy-linux-arm64 |
| 38 | + use-cross: true |
| 39 | + |
| 40 | + - os: macos-13 |
| 41 | + target: x86_64-apple-darwin |
| 42 | + artifact: tiny-proxy-macos-amd64 |
| 43 | + use-cross: false |
| 44 | + |
| 45 | + - os: macos-14 |
| 46 | + target: aarch64-apple-darwin |
| 47 | + artifact: tiny-proxy-macos-arm64 |
| 48 | + use-cross: false |
| 49 | + |
| 50 | + - os: windows-latest |
| 51 | + target: x86_64-pc-windows-msvc |
| 52 | + artifact: tiny-proxy-windows-amd64.exe |
| 53 | + use-cross: false |
| 54 | + |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Install Rust toolchain |
| 59 | + uses: dtolnay/rust-toolchain@stable |
| 60 | + with: |
| 61 | + targets: ${{ matrix.target }} |
| 62 | + |
| 63 | + - name: Cache |
| 64 | + uses: Swatinem/rust-cache@v2 |
| 65 | + |
| 66 | + - name: Install cross |
| 67 | + if: matrix.use-cross |
| 68 | + uses: taiki-e/install-action@cross |
| 69 | + |
| 70 | + - name: Build |
| 71 | + run: | |
| 72 | + if [ "${{ matrix.use-cross }}" = "true" ]; then |
| 73 | + cross build --release --target ${{ matrix.target }} --all-features --locked |
| 74 | + else |
| 75 | + cargo build --release --target ${{ matrix.target }} --all-features --locked |
| 76 | + fi |
| 77 | + shell: bash |
| 78 | + |
| 79 | + - name: Prepare artifact |
| 80 | + run: | |
| 81 | + mkdir -p dist |
| 82 | +
|
| 83 | + BIN_PATH=target/${{ matrix.target }}/release/tiny-proxy |
| 84 | +
|
| 85 | + if [ "${{ runner.os }}" = "Windows" ]; then |
| 86 | + BIN_PATH="${BIN_PATH}.exe" |
| 87 | + fi |
| 88 | +
|
| 89 | + cp "$BIN_PATH" dist/${{ matrix.artifact }} |
| 90 | +
|
| 91 | + cd dist |
| 92 | + shasum -a 256 ${{ matrix.artifact }} > ${{ matrix.artifact }}.sha256 |
| 93 | + shell: bash |
| 94 | + |
| 95 | + - name: Upload artifact |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: ${{ matrix.artifact }} |
| 99 | + path: dist/ |
| 100 | + |
| 101 | + publish-crate: |
| 102 | + name: Publish to crates.io |
| 103 | + runs-on: ubuntu-latest |
| 104 | + needs: release-build |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v4 |
| 107 | + |
| 108 | + - name: Install Rust toolchain |
| 109 | + uses: dtolnay/rust-toolchain@stable |
| 110 | + |
| 111 | + - name: Cache |
| 112 | + uses: Swatinem/rust-cache@v2 |
| 113 | + |
| 114 | + - name: Publish |
| 115 | + run: cargo publish --locked || echo "Already published" |
| 116 | + env: |
| 117 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} |
| 118 | + |
| 119 | + create-release: |
| 120 | + name: Create GitHub Release |
| 121 | + runs-on: ubuntu-latest |
| 122 | + needs: [release-build, publish-crate] |
| 123 | + |
| 124 | + steps: |
| 125 | + - uses: actions/checkout@v4 |
| 126 | + |
| 127 | + - name: Download artifacts |
| 128 | + uses: actions/download-artifact@v4 |
| 129 | + with: |
| 130 | + path: dist |
| 131 | + |
| 132 | + - name: Get tag |
| 133 | + id: tag |
| 134 | + run: | |
| 135 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 136 | + echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT |
| 137 | + else |
| 138 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 139 | + fi |
| 140 | +
|
| 141 | + - name: Create release notes |
| 142 | + run: | |
| 143 | + cat > release_notes.md << EOF |
| 144 | + # tiny-proxy ${{ steps.tag.outputs.tag }} |
| 145 | +
|
| 146 | + ## Installation |
| 147 | +
|
| 148 | + ### Linux/macOS |
| 149 | + \`\`\`bash |
| 150 | + curl -L https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/tiny-proxy-linux-amd64 -o tiny-proxy |
| 151 | + chmod +x tiny-proxy |
| 152 | + ./tiny-proxy --help |
| 153 | + \`\`\` |
| 154 | +
|
| 155 | + ### Windows |
| 156 | + Download and run: |
| 157 | + tiny-proxy-windows-amd64.exe |
| 158 | +
|
| 159 | + ### Cargo |
| 160 | + \`\`\`bash |
| 161 | + cargo install tiny-proxy |
| 162 | + \`\`\` |
| 163 | + EOF |
| 164 | +
|
| 165 | + - name: Create GitHub Release |
| 166 | + uses: softprops/action-gh-release@v1 |
| 167 | + with: |
| 168 | + tag_name: ${{ steps.tag.outputs.tag }} |
| 169 | + name: tiny-proxy ${{ steps.tag.outputs.tag }} |
| 170 | + body_path: release_notes.md |
| 171 | + files: dist/**/* |
| 172 | + draft: false |
| 173 | + prerelease: ${{ contains(steps.tag.outputs.tag, '-') }} |
| 174 | + env: |
| 175 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments