release.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. name: Build and Release
  2. # NOTE: This Github Actions file depends on the Makefile.
  3. # Building the correct package requires the correct binaries generated by the Makefile. To
  4. # ensure the correct output, the Makefile must accept the appropriate input and compile the
  5. # correct file with the correct name. If you need to modify this file, please ensure it won't
  6. # disrupt the Makefile.
  7. on:
  8. workflow_dispatch:
  9. release:
  10. types: [published]
  11. push:
  12. branches:
  13. - main
  14. paths:
  15. - "**/*.go"
  16. - "go.mod"
  17. - "go.sum"
  18. - ".github/workflows/release.yml"
  19. pull_request:
  20. types: [opened, synchronize, reopened]
  21. paths:
  22. - "**/*.go"
  23. - "go.mod"
  24. - "go.sum"
  25. - ".github/workflows/release.yml"
  26. jobs:
  27. prepare:
  28. runs-on: ubuntu-latest
  29. steps:
  30. - name: Restore Cache
  31. uses: actions/cache/restore@v4
  32. with:
  33. path: resources
  34. key: xray-geodat-
  35. - name: Update Geodat
  36. id: update
  37. uses: nick-fields/retry@v3
  38. with:
  39. timeout_minutes: 60
  40. retry_wait_seconds: 60
  41. max_attempts: 60
  42. command: |
  43. [ -d 'resources' ] || mkdir resources
  44. LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
  45. for i in "${LIST[@]}"
  46. do
  47. INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
  48. FILE_NAME="${INFO[2]}.dat"
  49. echo -e "Verifying HASH key..."
  50. HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
  51. if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
  52. continue
  53. else
  54. echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..."
  55. curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME}
  56. echo -e "Verifying HASH key..."
  57. [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
  58. echo "unhit=true" >> $GITHUB_OUTPUT
  59. fi
  60. done
  61. - name: Save Cache
  62. uses: actions/cache/save@v4
  63. if: ${{ steps.update.outputs.unhit }}
  64. with:
  65. path: resources
  66. key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
  67. build:
  68. needs: prepare
  69. permissions:
  70. contents: write
  71. strategy:
  72. matrix:
  73. # Include amd64 on all platforms.
  74. goos: [windows, freebsd, openbsd, linux, darwin]
  75. goarch: [amd64, 386]
  76. gotoolchain: [""]
  77. patch-assetname: [""]
  78. exclude:
  79. # Exclude i386 on darwin
  80. - goarch: 386
  81. goos: darwin
  82. include:
  83. # BEGIN MacOS ARM64
  84. - goos: darwin
  85. goarch: arm64
  86. # END MacOS ARM64
  87. # BEGIN Linux ARM 5 6 7
  88. - goos: linux
  89. goarch: arm
  90. goarm: 7
  91. - goos: linux
  92. goarch: arm
  93. goarm: 6
  94. - goos: linux
  95. goarch: arm
  96. goarm: 5
  97. # END Linux ARM 5 6 7
  98. # BEGIN Android ARM 8
  99. - goos: android
  100. goarch: arm64
  101. # END Android ARM 8
  102. # Windows ARM
  103. - goos: windows
  104. goarch: arm64
  105. - goos: windows
  106. goarch: arm
  107. goarm: 7
  108. # BEGIN Other architectures
  109. # BEGIN riscv64 & ARM64 & LOONG64
  110. - goos: linux
  111. goarch: arm64
  112. - goos: linux
  113. goarch: riscv64
  114. - goos: linux
  115. goarch: loong64
  116. # END riscv64 & ARM64 & LOONG64
  117. # BEGIN MIPS
  118. - goos: linux
  119. goarch: mips64
  120. - goos: linux
  121. goarch: mips64le
  122. - goos: linux
  123. goarch: mipsle
  124. - goos: linux
  125. goarch: mips
  126. # END MIPS
  127. # BEGIN PPC
  128. - goos: linux
  129. goarch: ppc64
  130. - goos: linux
  131. goarch: ppc64le
  132. # END PPC
  133. # BEGIN FreeBSD ARM
  134. - goos: freebsd
  135. goarch: arm64
  136. - goos: freebsd
  137. goarch: arm
  138. goarm: 7
  139. # END FreeBSD ARM
  140. # BEGIN S390X
  141. - goos: linux
  142. goarch: s390x
  143. # END S390X
  144. # END Other architectures
  145. # BEGIN OPENBSD ARM
  146. - goos: openbsd
  147. goarch: arm64
  148. - goos: openbsd
  149. goarch: arm
  150. goarm: 7
  151. # END OPENBSD ARM
  152. # BEGIN Windows 7
  153. - goos: windows
  154. goarch: amd64
  155. gotoolchain: 1.21.4
  156. patch-assetname: win7-64
  157. - goos: windows
  158. goarch: 386
  159. gotoolchain: 1.21.4
  160. patch-assetname: win7-32
  161. # END Windows 7
  162. fail-fast: false
  163. runs-on: ubuntu-latest
  164. env:
  165. GOOS: ${{ matrix.goos }}
  166. GOARCH: ${{ matrix.goarch }}
  167. GOARM: ${{ matrix.goarm }}
  168. CGO_ENABLED: 0
  169. steps:
  170. - name: Checkout codebase
  171. uses: actions/checkout@v4
  172. - name: Show workflow information
  173. run: |
  174. _NAME=${{ matrix.patch-assetname }}
  175. [ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  176. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  177. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  178. - name: Set up Go
  179. uses: actions/setup-go@v5
  180. with:
  181. go-version: ${{ matrix.gotoolchain || '1.23' }}
  182. check-latest: true
  183. - name: Get project dependencies
  184. run: go mod download
  185. - name: Build Xray
  186. run: |
  187. mkdir -p build_assets
  188. make
  189. find . -maxdepth 1 -type f -regex './\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \;
  190. - name: Restore Cache
  191. uses: actions/cache/restore@v4
  192. with:
  193. path: resources
  194. key: xray-geodat-
  195. - name: Copy README.md & LICENSE
  196. run: |
  197. mv -f resources/* build_assets
  198. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  199. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  200. - name: Create ZIP archive
  201. if: github.event_name == 'release'
  202. shell: bash
  203. run: |
  204. pushd build_assets || exit 1
  205. touch -mt $(date +%Y01010000) *
  206. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  207. popd || exit 1
  208. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  209. DGST=$FILE.dgst
  210. for METHOD in {"md5","sha1","sha256","sha512"}
  211. do
  212. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  213. done
  214. - name: Change the name
  215. run: |
  216. mv build_assets Xray-${{ env.ASSET_NAME }}
  217. - name: Upload files to Artifacts
  218. uses: actions/upload-artifact@v4
  219. with:
  220. name: Xray-${{ env.ASSET_NAME }}
  221. path: |
  222. ./Xray-${{ env.ASSET_NAME }}/*
  223. - name: Upload binaries to release
  224. uses: svenstaro/upload-release-action@v2
  225. if: github.event_name == 'release'
  226. with:
  227. repo_token: ${{ secrets.GITHUB_TOKEN }}
  228. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  229. tag: ${{ github.ref }}
  230. file_glob: true