|
| 1 | +name: Build then release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + branches: |
| 8 | + - "master" |
| 9 | + |
| 10 | +env: |
| 11 | + CARGO_TERM_COLOR: always |
| 12 | + |
| 13 | +jobs: |
| 14 | + gen_version: |
| 15 | + name: Generate version |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + version: ${{ steps.generated-tag.outputs.tag }} |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + - name: Get latest tag |
| 24 | + id: get-latest-tag |
| 25 | + run: | |
| 26 | + echo "tag=`gh release list -L 1 | cut -f 1`" >> $GITHUB_OUTPUT |
| 27 | + env: |
| 28 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + - name: Bump version |
| 30 | + id: generated-tag |
| 31 | + uses: actions/github-script@v6 |
| 32 | + with: |
| 33 | + script: | |
| 34 | + if (context.ref.startsWith("refs/tags/")) { |
| 35 | + let tag = context.ref.replace("refs/tags/", ""); |
| 36 | + core.setOutput('tag', tag); |
| 37 | + console.log(`This event pushed a tag ${tag}, return directly.`) |
| 38 | + return |
| 39 | + } |
| 40 | + console.log('Use default tag "prerelease".') |
| 41 | + core.setOutput('tag', 'prerelease'); |
| 42 | +
|
| 43 | + build: |
| 44 | + needs: gen_version |
| 45 | + name: Build |
| 46 | + runs-on: ${{ matrix.runner }} |
| 47 | + strategy: |
| 48 | + matrix: |
| 49 | + include: |
| 50 | + - target: x86_64-apple-darwin |
| 51 | + runner: macos-latest |
| 52 | + build_env: {} |
| 53 | + - target: aarch64-apple-darwin |
| 54 | + runner: macos-latest |
| 55 | + build_env: {} |
| 56 | + - target: x86_64-unknown-linux-musl |
| 57 | + runner: ubuntu-latest |
| 58 | + build_env: {} |
| 59 | + - target: aarch64-unknown-linux-musl |
| 60 | + runner: ubuntu-latest |
| 61 | + build_env: |
| 62 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-Clink-self-contained=yes -Clinker=rust-lld" |
| 63 | + CC_aarch64_unknown_linux_musl: clang |
| 64 | + AR_aarch64_unknown_linux_musl: llvm-ar |
| 65 | + |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + fetch-depth: 0 |
| 70 | + - name: Setup protoc |
| 71 | + uses: arduino/setup-protoc@v3.0.0 |
| 72 | + with: |
| 73 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + - name: Install musl-tools |
| 75 | + if: matrix.runner == 'ubuntu-latest' |
| 76 | + run: sudo apt update && sudo apt install -y musl-tools |
| 77 | + - name: Install cross build deps for aarch64-unknown-linux-musl |
| 78 | + if: matrix.target == 'aarch64-unknown-linux-musl' |
| 79 | + run: sudo apt update && sudo apt install -y clang llvm |
| 80 | + - name: Add target |
| 81 | + run: rustup target add ${{ matrix.target }} |
| 82 | + - name: Setup rust toolchain |
| 83 | + run: rustup show |
| 84 | + - uses: Swatinem/rust-cache@v2 |
| 85 | + with: |
| 86 | + shared-key: build-then-release-${{ matrix.target }}-v1 |
| 87 | + - name: Build |
| 88 | + env: ${{ matrix.build_env }} |
| 89 | + run: | |
| 90 | + cargo build --release --target ${{ matrix.target }} |
| 91 | + - name: Compress |
| 92 | + run: | |
| 93 | + zip -j pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip ./target/${{ matrix.target }}/release/pproxy |
| 94 | + - uses: actions/upload-artifact@v4 |
| 95 | + name: Upload artifacts |
| 96 | + with: |
| 97 | + name: pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }} |
| 98 | + path: pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip |
| 99 | + retention-days: 1 |
| 100 | + |
| 101 | + release: |
| 102 | + needs: [gen_version, build] |
| 103 | + runs-on: ubuntu-latest |
| 104 | + steps: |
| 105 | + - uses: actions/checkout@v3 |
| 106 | + with: |
| 107 | + fetch-depth: 0 |
| 108 | + - name: Generate changelog |
| 109 | + uses: orhun/git-cliff-action@v3 |
| 110 | + id: git-cliff |
| 111 | + with: |
| 112 | + config: cliff.toml |
| 113 | + args: "-vv --strip header ${{ needs.gen_version.outputs.version == 'prerelease' && '--unreleased' || '--latest' }}" |
| 114 | + - uses: actions/download-artifact@v3 |
| 115 | + - name: Display fetched artifacts |
| 116 | + run: ls -R |
| 117 | + - uses: softprops/action-gh-release@v2.0.4 |
| 118 | + name: Emit a Github Release |
| 119 | + with: |
| 120 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 121 | + body: "${{ steps.git-cliff.outputs.content }}" |
| 122 | + tag_name: ${{ needs.gen_version.outputs.version }} |
| 123 | + prerelease: ${{ needs.gen_version.outputs.version == 'prerelease' }} |
| 124 | + title: ${{ needs.gen_version.outputs.version }} |
| 125 | + files: | |
| 126 | + LICENSE |
| 127 | + pproxy-${{ needs.gen_version.outputs.version }}-x86_64-apple-darwin/*.zip |
| 128 | + pproxy-${{ needs.gen_version.outputs.version }}-aarch64-apple-darwin/*.zip |
| 129 | + pproxy-${{ needs.gen_version.outputs.version }}-x86_64-unknown-linux-musl/*.zip |
| 130 | + pproxy-${{ needs.gen_version.outputs.version }}-aarch64-unknown-linux-musl/*.zip |
0 commit comments