release.yml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. name: Build and Release
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [published]
  6. push:
  7. pull_request:
  8. types: [opened, synchronize, reopened]
  9. jobs:
  10. check-assets:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Restore Geodat Cache
  14. uses: actions/cache/restore@v4
  15. with:
  16. path: resources
  17. key: xray-geodat-
  18. - name: Check Assets Existence
  19. id: check-assets
  20. run: |
  21. [ -d 'resources' ] || mkdir resources
  22. LIST=('geoip.dat' 'geosite.dat')
  23. for FILE_NAME in "${LIST[@]}"
  24. do
  25. echo -e "Checking ${FILE_NAME}..."
  26. if [ -s "./resources/${FILE_NAME}" ]; then
  27. echo -e "${FILE_NAME} exists."
  28. else
  29. echo -e "${FILE_NAME} does not exist."
  30. echo "missing=true" >> $GITHUB_OUTPUT
  31. break
  32. fi
  33. done
  34. - name: Trigger Asset Update Workflow if Assets Missing
  35. if: steps.check-assets.outputs.missing == 'true'
  36. uses: actions/github-script@v7
  37. with:
  38. github-token: ${{ secrets.GITHUB_TOKEN }}
  39. script: |
  40. const { owner, repo } = context.repo;
  41. await github.rest.actions.createWorkflowDispatch({
  42. owner,
  43. repo,
  44. workflow_id: 'scheduled-assets-update.yml',
  45. ref: context.ref
  46. });
  47. console.log('Triggered scheduled-assets-update.yml due to missing assets on branch:', context.ref);
  48. - name: Sleep for 90 seconds if Assets Missing
  49. if: steps.check-assets.outputs.missing == 'true'
  50. run: sleep 90
  51. build:
  52. needs: check-assets
  53. permissions:
  54. contents: write
  55. strategy:
  56. matrix:
  57. # Include amd64 on all platforms.
  58. goos: [windows, freebsd, openbsd, linux, darwin]
  59. goarch: [amd64, 386]
  60. patch-assetname: [""]
  61. exclude:
  62. # Exclude i386 on darwin
  63. - goarch: 386
  64. goos: darwin
  65. include:
  66. # BEGIN MacOS ARM64
  67. - goos: darwin
  68. goarch: arm64
  69. # END MacOS ARM64
  70. # BEGIN Linux ARM 5 6 7
  71. - goos: linux
  72. goarch: arm
  73. goarm: 7
  74. - goos: linux
  75. goarch: arm
  76. goarm: 6
  77. - goos: linux
  78. goarch: arm
  79. goarm: 5
  80. # END Linux ARM 5 6 7
  81. # BEGIN Android ARM 8
  82. - goos: android
  83. goarch: arm64
  84. # END Android ARM 8
  85. # BEGIN Android AMD64
  86. - goos: android
  87. goarch: amd64
  88. patch-assetname: android-amd64
  89. # END Android AMD64
  90. # Windows ARM
  91. - goos: windows
  92. goarch: arm64
  93. - goos: windows
  94. goarch: arm
  95. goarm: 7
  96. # BEGIN Other architectures
  97. # BEGIN riscv64 & ARM64 & LOONG64
  98. - goos: linux
  99. goarch: arm64
  100. - goos: linux
  101. goarch: riscv64
  102. - goos: linux
  103. goarch: loong64
  104. # END riscv64 & ARM64 & LOONG64
  105. # BEGIN MIPS
  106. - goos: linux
  107. goarch: mips64
  108. - goos: linux
  109. goarch: mips64le
  110. - goos: linux
  111. goarch: mipsle
  112. - goos: linux
  113. goarch: mips
  114. # END MIPS
  115. # BEGIN PPC
  116. - goos: linux
  117. goarch: ppc64
  118. - goos: linux
  119. goarch: ppc64le
  120. # END PPC
  121. # BEGIN FreeBSD ARM
  122. - goos: freebsd
  123. goarch: arm64
  124. - goos: freebsd
  125. goarch: arm
  126. goarm: 7
  127. # END FreeBSD ARM
  128. # BEGIN S390X
  129. - goos: linux
  130. goarch: s390x
  131. # END S390X
  132. # END Other architectures
  133. # BEGIN OPENBSD ARM
  134. - goos: openbsd
  135. goarch: arm64
  136. - goos: openbsd
  137. goarch: arm
  138. goarm: 7
  139. # END OPENBSD ARM
  140. fail-fast: false
  141. runs-on: ubuntu-latest
  142. env:
  143. GOOS: ${{ matrix.goos }}
  144. GOARCH: ${{ matrix.goarch }}
  145. GOARM: ${{ matrix.goarm }}
  146. CGO_ENABLED: 0
  147. steps:
  148. - name: Checkout codebase
  149. uses: actions/checkout@v5
  150. - name: Set up NDK
  151. if: matrix.goos == 'android'
  152. run: |
  153. wget -qO android-ndk.zip https://dl.google.com/android/repository/android-ndk-r28b-linux.zip
  154. unzip android-ndk.zip
  155. rm android-ndk.zip
  156. declare -A arches=(
  157. ["amd64"]="x86_64-linux-android24-clang"
  158. ["arm64"]="aarch64-linux-android24-clang"
  159. )
  160. echo CC="$(realpath android-ndk-*/toolchains/llvm/prebuilt/linux-x86_64/bin)/${arches[${{ matrix.goarch }}]}" >> $GITHUB_ENV
  161. echo CGO_ENABLED=1 >> $GITHUB_ENV
  162. - name: Show workflow information
  163. run: |
  164. _NAME=${{ matrix.patch-assetname }}
  165. [ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  166. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  167. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  168. - name: Set up Go
  169. uses: actions/setup-go@v5
  170. with:
  171. go-version-file: go.mod
  172. check-latest: true
  173. - name: Get project dependencies
  174. run: go mod download
  175. - name: Build Xray
  176. run: |
  177. mkdir -p build_assets
  178. COMMID=$(git describe --always --dirty)
  179. if [[ ${GOOS} == 'windows' ]]; then
  180. echo 'Building Xray for Windows...'
  181. go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  182. echo 'CreateObject("Wscript.Shell").Run "xray.exe -config config.json",0' > build_assets/xray_no_window.vbs
  183. echo 'Start-Process -FilePath ".\xray.exe" -ArgumentList "-config .\config.json" -WindowStyle Hidden' > build_assets/xray_no_window.ps1
  184. # The line below is for without running conhost.exe version. Commented for not being used. Provided for reference.
  185. # go build -o build_assets/wxray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  186. else
  187. echo 'Building Xray...'
  188. if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
  189. go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  190. echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
  191. GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  192. else
  193. go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  194. fi
  195. fi
  196. - name: Restore Geodat Cache
  197. uses: actions/cache/restore@v4
  198. with:
  199. path: resources
  200. key: xray-geodat-
  201. - name: Copy README.md & LICENSE
  202. run: |
  203. mv -f resources/* build_assets
  204. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  205. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  206. - name: Create ZIP archive
  207. if: github.event_name == 'release'
  208. shell: bash
  209. run: |
  210. pushd build_assets || exit 1
  211. touch -mt $(date +%Y01010000) *
  212. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  213. popd || exit 1
  214. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  215. DGST=$FILE.dgst
  216. for METHOD in {"md5","sha1","sha256","sha512"}
  217. do
  218. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  219. done
  220. - name: Change the name
  221. run: |
  222. mv build_assets Xray-${{ env.ASSET_NAME }}
  223. - name: Upload files to Artifacts
  224. uses: actions/upload-artifact@v4
  225. with:
  226. name: Xray-${{ env.ASSET_NAME }}
  227. path: |
  228. ./Xray-${{ env.ASSET_NAME }}/*
  229. - name: Upload binaries to release
  230. uses: svenstaro/upload-release-action@v2
  231. if: github.event_name == 'release'
  232. with:
  233. repo_token: ${{ secrets.GITHUB_TOKEN }}
  234. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  235. tag: ${{ github.ref }}
  236. file_glob: true