release.yml 6.7 KB

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