release.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. name: Release
  2. on:
  3. push:
  4. tags:
  5. - "*"
  6. workflow_dispatch:
  7. env:
  8. CARGO_TERM_COLOR: always
  9. jobs:
  10. release:
  11. name: Cross build for ${{ matrix.target }}
  12. runs-on: ${{ matrix.os }}
  13. strategy:
  14. matrix:
  15. include:
  16. - os: ubuntu-latest
  17. target: x86_64-unknown-linux-gnu
  18. exe: rathole
  19. cross: false
  20. - os: ubuntu-latest
  21. target: x86_64-unknown-linux-musl
  22. exe: rathole
  23. cross: false
  24. - os: ubuntu-latest
  25. target: aarch64-unknown-linux-musl
  26. exe: rathole
  27. cross: true
  28. - os: ubuntu-latest
  29. target: arm-unknown-linux-musleabi
  30. exe: rathole
  31. cross: true
  32. - os: ubuntu-latest
  33. target: arm-unknown-linux-musleabihf
  34. exe: rathole
  35. cross: true
  36. - os: ubuntu-latest
  37. target: armv7-unknown-linux-musleabihf
  38. exe: rathole
  39. cross: true
  40. - os: ubuntu-latest
  41. target: mips-unknown-linux-gnu
  42. exe: rathole
  43. cross: true
  44. - os: ubuntu-latest
  45. target: mips-unknown-linux-musl
  46. exe: rathole
  47. cross: true
  48. - os: ubuntu-latest
  49. target: mipsel-unknown-linux-gnu
  50. exe: rathole
  51. cross: true
  52. - os: ubuntu-latest
  53. target: mipsel-unknown-linux-musl
  54. exe: rathole
  55. cross: true
  56. - os: ubuntu-latest
  57. target: mips64-unknown-linux-gnuabi64
  58. exe: rathole
  59. cross: true
  60. - os: ubuntu-latest
  61. target: mips64el-unknown-linux-gnuabi64
  62. exe: rathole
  63. cross: true
  64. - os: macos-latest
  65. target: x86_64-apple-darwin
  66. exe: rathole
  67. cross: false
  68. - os: macos-latest
  69. target: aarch64-apple-darwin
  70. exe: rathole
  71. cross: false
  72. - os: windows-latest
  73. target: x86_64-pc-windows-msvc
  74. exe: rathole.exe
  75. cross: false
  76. steps:
  77. - uses: actions/checkout@v2
  78. - uses: actions-rs/toolchain@v1
  79. with:
  80. profile: minimal
  81. # Since rust 1.72, some platforms are tier 3
  82. toolchain: 1.71
  83. default: true
  84. - name: Install OpenSSL
  85. if: matrix.os == 'ubuntu-latest'
  86. run: sudo apt-get install pkg-config libssl-dev
  87. - name: Install OpenSSL
  88. if: matrix.os == 'macos-latest'
  89. run: brew install openssl@3
  90. # Native build
  91. - name: Install target
  92. if: matrix.cross == false
  93. run: rustup target add ${{ matrix.target }}
  94. - name: Run tests
  95. if: matrix.cross == false && matrix.target != 'aarch64-apple-darwin'
  96. run: cargo test --release --target ${{ matrix.target }} --verbose
  97. - name: Build release
  98. if: matrix.cross == false
  99. run: cargo build --release --target ${{ matrix.target }}
  100. # Cross build
  101. - name: Install cross
  102. if: matrix.cross
  103. run: cargo install --version 0.2.5 cross
  104. - name: Run tests
  105. if: matrix.cross
  106. run: cross test --release --target ${{ matrix.target }} --verbose --features embedded --no-default-features
  107. - name: Build release
  108. if: matrix.cross
  109. run: cross build --release --target ${{ matrix.target }} --features embedded --no-default-features
  110. - name: Run UPX
  111. # Upx may not support some platforms. Ignore the errors
  112. continue-on-error: true
  113. # Disable upx for mips. See https://github.com/upx/upx/issues/387
  114. if: matrix.os == 'ubuntu-latest' && !contains(matrix.target, 'mips')
  115. uses: crazy-max/ghaction-upx@v1
  116. with:
  117. version: v4.0.2
  118. files: target/${{ matrix.target }}/release/${{ matrix.exe }}
  119. args: -q --best --lzma
  120. - uses: actions/upload-artifact@v2
  121. with:
  122. name: rathole-${{ matrix.target }}
  123. path: target/${{ matrix.target }}/release/${{ matrix.exe }}
  124. - name: Zip Release
  125. uses: TheDoctor0/zip-release@0.6.1
  126. with:
  127. type: zip
  128. filename: rathole-${{ matrix.target }}.zip
  129. directory: target/${{ matrix.target }}/release/
  130. path: ${{ matrix.exe }}
  131. - name: Publish
  132. uses: softprops/action-gh-release@v1
  133. if: startsWith(github.ref, 'refs/tags/')
  134. with:
  135. files: target/${{ matrix.target }}/release/rathole-${{ matrix.target }}.zip
  136. generate_release_notes: true
  137. draft: true
  138. docker:
  139. name: Publish to Docker Hub
  140. if: startsWith(github.ref, 'refs/tags/')
  141. runs-on: ubuntu-latest
  142. needs: release
  143. steps:
  144. - name: Set up Docker Buildx
  145. uses: docker/setup-buildx-action@v1
  146. - name: Login to DockerHub
  147. uses: docker/login-action@v1
  148. with:
  149. username: ${{ secrets.DOCKERHUB_USERNAME }}
  150. password: ${{ secrets.DOCKERHUB_TOKEN }}
  151. - name: Build and push
  152. id: docker_build
  153. uses: docker/build-push-action@v2
  154. with:
  155. push: true
  156. tags: rapiz1/rathole:latest, rapiz1/rathole:${{ github.ref_name }}
  157. publish-crate:
  158. name: Publish to crates.io
  159. if: startsWith(github.ref, 'refs/tags/')
  160. runs-on: ubuntu-latest
  161. needs: release
  162. steps:
  163. - uses: actions/checkout@v2
  164. - uses: actions-rs/toolchain@v1
  165. with:
  166. profile: minimal
  167. toolchain: stable
  168. - name: Publish
  169. env:
  170. CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}
  171. run: cargo publish