release.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. patch-assetname: [""]
  77. exclude:
  78. # Exclude i386 on darwin
  79. - goarch: 386
  80. goos: darwin
  81. include:
  82. # BEGIN MacOS ARM64
  83. - goos: darwin
  84. goarch: arm64
  85. # END MacOS ARM64
  86. # BEGIN Linux ARM 5 6 7
  87. - goos: linux
  88. goarch: arm
  89. goarm: 7
  90. - goos: linux
  91. goarch: arm
  92. goarm: 6
  93. - goos: linux
  94. goarch: arm
  95. goarm: 5
  96. # END Linux ARM 5 6 7
  97. # BEGIN Android ARM 8
  98. - goos: android
  99. goarch: arm64
  100. # END Android ARM 8
  101. # Windows ARM
  102. - goos: windows
  103. goarch: arm64
  104. - goos: windows
  105. goarch: arm
  106. goarm: 7
  107. # BEGIN Other architectures
  108. # BEGIN riscv64 & ARM64 & LOONG64
  109. - goos: linux
  110. goarch: arm64
  111. - goos: linux
  112. goarch: riscv64
  113. - goos: linux
  114. goarch: loong64
  115. # END riscv64 & ARM64 & LOONG64
  116. # BEGIN MIPS
  117. - goos: linux
  118. goarch: mips64
  119. - goos: linux
  120. goarch: mips64le
  121. - goos: linux
  122. goarch: mipsle
  123. - goos: linux
  124. goarch: mips
  125. # END MIPS
  126. # BEGIN PPC
  127. - goos: linux
  128. goarch: ppc64
  129. - goos: linux
  130. goarch: ppc64le
  131. # END PPC
  132. # BEGIN FreeBSD ARM
  133. - goos: freebsd
  134. goarch: arm64
  135. - goos: freebsd
  136. goarch: arm
  137. goarm: 7
  138. # END FreeBSD ARM
  139. # BEGIN S390X
  140. - goos: linux
  141. goarch: s390x
  142. # END S390X
  143. # END Other architectures
  144. # BEGIN OPENBSD ARM
  145. - goos: openbsd
  146. goarch: arm64
  147. - goos: openbsd
  148. goarch: arm
  149. goarm: 7
  150. # END OPENBSD ARM
  151. fail-fast: false
  152. runs-on: ubuntu-latest
  153. env:
  154. GOOS: ${{ matrix.goos }}
  155. GOARCH: ${{ matrix.goarch }}
  156. GOARM: ${{ matrix.goarm }}
  157. CGO_ENABLED: 0
  158. steps:
  159. - name: Checkout codebase
  160. uses: actions/checkout@v4
  161. - name: Show workflow information
  162. run: |
  163. _NAME=${{ matrix.patch-assetname }}
  164. [ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  165. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  166. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  167. - name: Set up Go
  168. uses: actions/setup-go@v5
  169. with:
  170. go-version-file: go.mod
  171. check-latest: true
  172. - name: Get project dependencies
  173. run: go mod download
  174. - name: Build Xray
  175. run: |
  176. mkdir -p build_assets
  177. make
  178. find . -maxdepth 1 -type f -regex './\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \;
  179. - name: Restore Cache
  180. uses: actions/cache/restore@v4
  181. with:
  182. path: resources
  183. key: xray-geodat-
  184. - name: Copy README.md & LICENSE
  185. run: |
  186. mv -f resources/* build_assets
  187. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  188. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  189. - name: Create ZIP archive
  190. if: github.event_name == 'release'
  191. shell: bash
  192. run: |
  193. pushd build_assets || exit 1
  194. touch -mt $(date +%Y01010000) *
  195. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  196. popd || exit 1
  197. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  198. DGST=$FILE.dgst
  199. for METHOD in {"md5","sha1","sha256","sha512"}
  200. do
  201. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  202. done
  203. - name: Change the name
  204. run: |
  205. mv build_assets Xray-${{ env.ASSET_NAME }}
  206. - name: Upload files to Artifacts
  207. uses: actions/upload-artifact@v4
  208. with:
  209. name: Xray-${{ env.ASSET_NAME }}
  210. path: |
  211. ./Xray-${{ env.ASSET_NAME }}/*
  212. - name: Upload binaries to release
  213. uses: svenstaro/upload-release-action@v2
  214. if: github.event_name == 'release'
  215. with:
  216. repo_token: ${{ secrets.GITHUB_TOKEN }}
  217. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  218. tag: ${{ github.ref }}
  219. file_glob: true