release.yml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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@v5
  15. with:
  16. path: resources
  17. key: xray-geodat-
  18. - name: Restore Wintun Cache
  19. uses: actions/cache/restore@v5
  20. with:
  21. path: resources
  22. key: xray-wintun-
  23. - name: Check Assets Existence
  24. id: check-assets
  25. run: |
  26. [ -d 'resources' ] || mkdir resources
  27. LIST=('geoip.dat' 'geosite.dat')
  28. for FILE_NAME in "${LIST[@]}"
  29. do
  30. echo -e "Checking ${FILE_NAME}..."
  31. if [ -s "./resources/${FILE_NAME}" ]; then
  32. echo -e "${FILE_NAME} exists."
  33. else
  34. echo -e "${FILE_NAME} does not exist."
  35. echo "missing=true" >> $GITHUB_OUTPUT
  36. break
  37. fi
  38. done
  39. LIST=('amd64' 'x86' 'arm64' 'arm')
  40. for ARCHITECTURE in "${LIST[@]}"
  41. do
  42. echo -e "Checking wintun.dll for ${ARCHITECTURE}..."
  43. if [ -s "./resources/wintun/bin/${ARCHITECTURE}/wintun.dll" ]; then
  44. echo -e "wintun.dll for ${ARCHITECTURE} exists."
  45. else
  46. echo -e "wintun.dll for ${ARCHITECTURE} is missing."
  47. echo "missing=true" >> $GITHUB_OUTPUT
  48. break
  49. fi
  50. done
  51. - name: Trigger Asset Update Workflow if Assets Missing
  52. if: steps.check-assets.outputs.missing == 'true'
  53. uses: actions/github-script@v8
  54. with:
  55. github-token: ${{ secrets.GITHUB_TOKEN }}
  56. script: |
  57. const { owner, repo } = context.repo;
  58. await github.rest.actions.createWorkflowDispatch({
  59. owner,
  60. repo,
  61. workflow_id: 'scheduled-assets-update.yml',
  62. ref: context.ref
  63. });
  64. console.log('Triggered scheduled-assets-update.yml due to missing assets on branch:', context.ref);
  65. - name: Sleep for 90 seconds if Assets Missing
  66. if: steps.check-assets.outputs.missing == 'true'
  67. run: sleep 90
  68. build:
  69. needs: check-assets
  70. permissions:
  71. contents: write
  72. strategy:
  73. matrix:
  74. # Include amd64 on all platforms.
  75. goos: [windows, freebsd, openbsd, linux, darwin]
  76. goarch: [amd64, 386]
  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. # BEGIN Android AMD64
  103. - goos: android
  104. goarch: amd64
  105. patch-assetname: android-amd64
  106. # END Android AMD64
  107. # Windows ARM
  108. - goos: windows
  109. goarch: arm64
  110. - goos: windows
  111. goarch: arm
  112. goarm: 7
  113. # BEGIN Other architectures
  114. # BEGIN riscv64 & ARM64 & LOONG64
  115. - goos: linux
  116. goarch: arm64
  117. - goos: linux
  118. goarch: riscv64
  119. - goos: linux
  120. goarch: loong64
  121. # END riscv64 & ARM64 & LOONG64
  122. # BEGIN MIPS
  123. - goos: linux
  124. goarch: mips64
  125. - goos: linux
  126. goarch: mips64le
  127. - goos: linux
  128. goarch: mipsle
  129. - goos: linux
  130. goarch: mips
  131. # END MIPS
  132. # BEGIN PPC
  133. - goos: linux
  134. goarch: ppc64
  135. - goos: linux
  136. goarch: ppc64le
  137. # END PPC
  138. # BEGIN FreeBSD ARM
  139. - goos: freebsd
  140. goarch: arm64
  141. - goos: freebsd
  142. goarch: arm
  143. goarm: 7
  144. # END FreeBSD ARM
  145. # BEGIN S390X
  146. - goos: linux
  147. goarch: s390x
  148. # END S390X
  149. # END Other architectures
  150. # BEGIN OPENBSD ARM
  151. - goos: openbsd
  152. goarch: arm64
  153. - goos: openbsd
  154. goarch: arm
  155. goarm: 7
  156. # END OPENBSD ARM
  157. fail-fast: false
  158. runs-on: ubuntu-latest
  159. env:
  160. GOOS: ${{ matrix.goos }}
  161. GOARCH: ${{ matrix.goarch }}
  162. GOARM: ${{ matrix.goarm }}
  163. CGO_ENABLED: 0
  164. steps:
  165. - name: Checkout codebase
  166. uses: actions/checkout@v6
  167. - name: Set up NDK
  168. if: matrix.goos == 'android'
  169. run: |
  170. wget -qO android-ndk.zip https://dl.google.com/android/repository/android-ndk-r28b-linux.zip
  171. unzip android-ndk.zip
  172. rm android-ndk.zip
  173. declare -A arches=(
  174. ["amd64"]="x86_64-linux-android24-clang"
  175. ["arm64"]="aarch64-linux-android24-clang"
  176. )
  177. echo CC="$(realpath android-ndk-*/toolchains/llvm/prebuilt/linux-x86_64/bin)/${arches[${{ matrix.goarch }}]}" >> $GITHUB_ENV
  178. echo CGO_ENABLED=1 >> $GITHUB_ENV
  179. - name: Show workflow information
  180. run: |
  181. _NAME=${{ matrix.patch-assetname }}
  182. [ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  183. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  184. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  185. - name: Set up Go
  186. uses: actions/setup-go@v6
  187. with:
  188. go-version-file: go.mod
  189. check-latest: true
  190. - name: Get project dependencies
  191. run: go mod download
  192. - name: Build Xray
  193. run: |
  194. mkdir -p build_assets
  195. COMMID=$(git describe --always --dirty)
  196. if [[ ${GOOS} == 'windows' ]]; then
  197. echo 'Building Xray for Windows...'
  198. 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
  199. # The line below is for without running conhost.exe version. Commented for not being used. Provided for reference.
  200. # 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
  201. else
  202. echo 'Building Xray...'
  203. if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
  204. 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
  205. echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
  206. 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
  207. else
  208. 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
  209. fi
  210. fi
  211. - name: Restore Geodat Cache
  212. uses: actions/cache/restore@v5
  213. with:
  214. path: resources
  215. key: xray-geodat-
  216. - name: Restore Wintun Cache
  217. if: matrix.goos == 'windows'
  218. uses: actions/cache/restore@v5
  219. with:
  220. path: resources
  221. key: xray-wintun-
  222. - name: Add additional assets into package
  223. run: |
  224. mv -f resources/geo* build_assets/
  225. if [[ ${GOOS} == 'windows' ]]; then
  226. echo 'CreateObject("Wscript.Shell").Run "xray.exe -config config.json",0' > build_assets/xray_no_window.vbs
  227. echo 'Start-Process -FilePath ".\xray.exe" -ArgumentList "-config .\config.json" -WindowStyle Hidden' > build_assets/xray_no_window.ps1
  228. if [[ ${GOARCH} == 'amd64' ]]; then
  229. mv resources/wintun/bin/amd64/wintun.dll build_assets/
  230. fi
  231. if [[ ${GOARCH} == '386' ]]; then
  232. mv resources/wintun/bin/x86/wintun.dll build_assets/
  233. fi
  234. if [[ ${GOARCH} == 'arm64' ]]; then
  235. mv resources/wintun/bin/arm64/wintun.dll build_assets/
  236. fi
  237. if [[ ${GOARCH} == 'arm' ]]; then
  238. mv resources/wintun/bin/arm/wintun.dll build_assets/
  239. fi
  240. mv resources/wintun/LICENSE.txt build_assets/LICENSE-wintun.txt
  241. fi
  242. - name: Copy README.md & LICENSE
  243. run: |
  244. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  245. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  246. - name: Create ZIP archive
  247. if: github.event_name == 'release'
  248. shell: bash
  249. run: |
  250. pushd build_assets || exit 1
  251. touch -mt $(date +%Y01010000) *
  252. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  253. popd || exit 1
  254. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  255. DGST=$FILE.dgst
  256. for METHOD in {"md5","sha1","sha256","sha512"}
  257. do
  258. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  259. done
  260. - name: Upload binaries to release
  261. uses: svenstaro/upload-release-action@v2
  262. if: github.event_name == 'release'
  263. with:
  264. repo_token: ${{ secrets.GITHUB_TOKEN }}
  265. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  266. tag: ${{ github.ref }}
  267. file_glob: true
  268. - name: Upload files to Artifacts
  269. uses: actions/upload-artifact@v6
  270. with:
  271. name: Xray-${{ env.ASSET_NAME }}
  272. path: |
  273. ./build_assets/*