release.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. name: Release 3X-UI
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - "**"
  7. tags:
  8. - "v*.*.*"
  9. paths:
  10. - "**.go"
  11. - "go.mod"
  12. - "go.sum"
  13. - "**.sh"
  14. - "frontend/**"
  15. - "x-ui.service.debian"
  16. - "x-ui.service.arch"
  17. - "x-ui.service.rhel"
  18. pull_request:
  19. paths:
  20. - "**.go"
  21. - "go.mod"
  22. - "go.sum"
  23. - "**.sh"
  24. - "frontend/**"
  25. - "x-ui.service.debian"
  26. - "x-ui.service.arch"
  27. - "x-ui.service.rhel"
  28. jobs:
  29. build:
  30. permissions:
  31. contents: write
  32. strategy:
  33. matrix:
  34. platform:
  35. - amd64
  36. - arm64
  37. - armv7
  38. - armv6
  39. - 386
  40. - armv5
  41. - s390x
  42. runs-on: ubuntu-latest
  43. steps:
  44. - name: Checkout repository
  45. uses: actions/checkout@v7
  46. - name: Setup Go
  47. uses: actions/setup-go@v6
  48. with:
  49. go-version-file: go.mod
  50. check-latest: true
  51. # Frontend dist must be built BEFORE go build — Go's //go:embed
  52. # all:dist directive in internal/web/web.go requires internal/web/dist/ to exist
  53. # at compile time. internal/web/dist/ is .gitignored, so on a fresh CI
  54. # checkout it doesn't exist until vite emits it.
  55. - name: Setup Node.js
  56. uses: actions/setup-node@v6
  57. with:
  58. node-version-file: .nvmrc
  59. cache: 'npm'
  60. cache-dependency-path: frontend/package-lock.json
  61. - name: Build frontend bundle
  62. run: |
  63. npm ci
  64. npm run build
  65. working-directory: frontend
  66. - name: Build 3X-UI
  67. run: |
  68. export CGO_ENABLED=1
  69. export GOOS=linux
  70. export GOARCH=${{ matrix.platform }}
  71. # Use Bootlin prebuilt cross-toolchains (musl 1.2.5 in stable series)
  72. case "${{ matrix.platform }}" in
  73. amd64) BOOTLIN_ARCH="x86-64" ;;
  74. arm64) BOOTLIN_ARCH="aarch64" ;;
  75. armv7) BOOTLIN_ARCH="armv7-eabihf"; export GOARCH=arm GOARM=7 ;;
  76. armv6) BOOTLIN_ARCH="armv6-eabihf"; export GOARCH=arm GOARM=6 ;;
  77. armv5) BOOTLIN_ARCH="armv5-eabi"; export GOARCH=arm GOARM=5 ;;
  78. 386) BOOTLIN_ARCH="x86-i686" ;;
  79. s390x) BOOTLIN_ARCH="s390x-z13" ;;
  80. esac
  81. echo "Resolving Bootlin musl toolchain for arch=$BOOTLIN_ARCH (platform=${{ matrix.platform }})"
  82. TARBALL_BASE="https://toolchains.bootlin.com/downloads/releases/toolchains/$BOOTLIN_ARCH/tarballs/"
  83. TARBALL_URL=$(curl -fsSL "$TARBALL_BASE" | grep -oE "${BOOTLIN_ARCH}--musl--stable-[^\"]+\\.tar\\.xz" | sort -r | head -n1)
  84. [ -z "$TARBALL_URL" ] && { echo "Failed to locate Bootlin musl toolchain for arch=$BOOTLIN_ARCH" >&2; exit 1; }
  85. echo "Downloading: $TARBALL_URL"
  86. cd /tmp
  87. curl -fL -sS -o "$(basename "$TARBALL_URL")" "$TARBALL_BASE/$TARBALL_URL"
  88. tar -xf "$(basename "$TARBALL_URL")"
  89. TOOLCHAIN_DIR=$(find . -maxdepth 1 -type d -name "${BOOTLIN_ARCH}--musl--stable-*" | head -n1)
  90. export PATH="$(realpath "$TOOLCHAIN_DIR")/bin:$PATH"
  91. export CC=$(realpath "$(find "$TOOLCHAIN_DIR/bin" -name '*-gcc.br_real' -type f -executable | head -n1)")
  92. [ -z "$CC" ] && { echo "No gcc.br_real found in $TOOLCHAIN_DIR/bin" >&2; exit 1; }
  93. cd -
  94. # Stamp the commit into per-commit (dev channel) builds only; tagged
  95. # stable releases stay unstamped so config.IsDevBuild() returns false.
  96. LDFLAGS="-w -s -linkmode external -extldflags '-static'"
  97. if [[ "$GITHUB_REF" != refs/tags/* ]]; then
  98. LDFLAGS="$LDFLAGS -X github.com/mhsanaei/3x-ui/v3/internal/config.buildCommit=${GITHUB_SHA::8} -X github.com/mhsanaei/3x-ui/v3/internal/config.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
  99. fi
  100. go build -ldflags "$LDFLAGS" -o xui-release -v main.go
  101. file xui-release
  102. ldd xui-release || echo "Static binary confirmed"
  103. mkdir x-ui
  104. cp xui-release x-ui/
  105. cp x-ui.service.debian x-ui/
  106. cp x-ui.service.arch x-ui/
  107. cp x-ui.service.rhel x-ui/
  108. cp x-ui.sh x-ui/
  109. mv x-ui/xui-release x-ui/x-ui
  110. mkdir x-ui/bin
  111. cd x-ui/bin
  112. # Download dependencies
  113. Xray_URL="https://github.com/XTLS/Xray-core/releases/download/v26.6.27/"
  114. if [ "${{ matrix.platform }}" == "amd64" ]; then
  115. wget -q ${Xray_URL}Xray-linux-64.zip
  116. unzip Xray-linux-64.zip
  117. rm -f Xray-linux-64.zip
  118. elif [ "${{ matrix.platform }}" == "arm64" ]; then
  119. wget -q ${Xray_URL}Xray-linux-arm64-v8a.zip
  120. unzip Xray-linux-arm64-v8a.zip
  121. rm -f Xray-linux-arm64-v8a.zip
  122. elif [ "${{ matrix.platform }}" == "armv7" ]; then
  123. wget -q ${Xray_URL}Xray-linux-arm32-v7a.zip
  124. unzip Xray-linux-arm32-v7a.zip
  125. rm -f Xray-linux-arm32-v7a.zip
  126. elif [ "${{ matrix.platform }}" == "armv6" ]; then
  127. wget -q ${Xray_URL}Xray-linux-arm32-v6.zip
  128. unzip Xray-linux-arm32-v6.zip
  129. rm -f Xray-linux-arm32-v6.zip
  130. elif [ "${{ matrix.platform }}" == "386" ]; then
  131. wget -q ${Xray_URL}Xray-linux-32.zip
  132. unzip Xray-linux-32.zip
  133. rm -f Xray-linux-32.zip
  134. elif [ "${{ matrix.platform }}" == "armv5" ]; then
  135. wget -q ${Xray_URL}Xray-linux-arm32-v5.zip
  136. unzip Xray-linux-arm32-v5.zip
  137. rm -f Xray-linux-arm32-v5.zip
  138. elif [ "${{ matrix.platform }}" == "s390x" ]; then
  139. wget -q ${Xray_URL}Xray-linux-s390x.zip
  140. unzip Xray-linux-s390x.zip
  141. rm -f Xray-linux-s390x.zip
  142. fi
  143. rm -f geoip.dat geosite.dat
  144. wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
  145. wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
  146. wget -q -O geoip_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
  147. wget -q -O geosite_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
  148. wget -q -O geoip_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat
  149. wget -q -O geosite_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat
  150. mv xray xray-linux-${{ matrix.platform }}
  151. # mtg-multi (MTProto sidecar) ships prebuilt release binaries whose
  152. # platform labels match our matrix, so download and unpack the matching
  153. # archive. Only the platforms the fork publishes are packaged.
  154. MTG_MULTI_VER="v1.14.0"
  155. case "${{ matrix.platform }}" in
  156. amd64|arm64|armv7|armv6|386)
  157. MTG_PKG="mtg-multi-${MTG_MULTI_VER#v}-linux-${{ matrix.platform }}"
  158. curl -sfLRO "https://github.com/mhsanaei/mtg-multi/releases/download/${MTG_MULTI_VER}/${MTG_PKG}.tar.gz"
  159. tar -xzf "${MTG_PKG}.tar.gz"
  160. mv "${MTG_PKG}/mtg-multi" "mtg-linux-${{ matrix.platform }}"
  161. rm -rf "${MTG_PKG}" "${MTG_PKG}.tar.gz"
  162. ;;
  163. esac
  164. cd ../..
  165. - name: Package
  166. run: tar -zcvf x-ui-linux-${{ matrix.platform }}.tar.gz x-ui
  167. - name: Upload files to Artifacts
  168. uses: actions/upload-artifact@v7
  169. with:
  170. name: x-ui-linux-${{ matrix.platform }}
  171. path: ./x-ui-linux-${{ matrix.platform }}.tar.gz
  172. - name: Upload files to GH release
  173. uses: svenstaro/upload-release-action@v2
  174. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
  175. with:
  176. repo_token: ${{ secrets.GITHUB_TOKEN }}
  177. tag: ${{ github.ref_name }}
  178. file: x-ui-linux-${{ matrix.platform }}.tar.gz
  179. asset_name: x-ui-linux-${{ matrix.platform }}.tar.gz
  180. overwrite: true
  181. prerelease: true
  182. # =================================
  183. # Windows Build
  184. # =================================
  185. build-windows:
  186. name: Build for Windows
  187. permissions:
  188. contents: write
  189. strategy:
  190. matrix:
  191. platform:
  192. - amd64
  193. runs-on: windows-latest
  194. steps:
  195. - name: Checkout repository
  196. uses: actions/checkout@v7
  197. - name: Setup Go
  198. uses: actions/setup-go@v6
  199. with:
  200. go-version-file: go.mod
  201. check-latest: true
  202. # Frontend dist must be built BEFORE go build — see comment on the
  203. # Linux job above. This step is identical except npm runs on the
  204. # Windows runner here.
  205. - name: Setup Node.js
  206. uses: actions/setup-node@v6
  207. with:
  208. node-version-file: .nvmrc
  209. cache: 'npm'
  210. cache-dependency-path: frontend/package-lock.json
  211. - name: Build frontend bundle
  212. shell: pwsh
  213. run: |
  214. npm ci
  215. npm run build
  216. working-directory: frontend
  217. - name: Install MSYS2
  218. uses: msys2/setup-msys2@v2
  219. with:
  220. msystem: MINGW64
  221. update: true
  222. install: >-
  223. mingw-w64-x86_64-gcc
  224. mingw-w64-x86_64-sqlite3
  225. mingw-w64-x86_64-pkg-config
  226. - name: Build 3X-UI for Windows (CGO)
  227. shell: msys2 {0}
  228. run: |
  229. export PATH="/c/hostedtoolcache/windows/go/$(ls /c/hostedtoolcache/windows/go | sort -V | tail -n1)/x64/bin:$PATH"
  230. export CGO_ENABLED=1
  231. export GOOS=windows
  232. export GOARCH=amd64
  233. export CC=x86_64-w64-mingw32-gcc
  234. which go
  235. go version
  236. gcc --version
  237. # Stamp the commit into per-commit (dev channel) builds only.
  238. LDFLAGS="-w -s"
  239. if [[ "$GITHUB_REF" != refs/tags/* ]]; then
  240. LDFLAGS="$LDFLAGS -X github.com/mhsanaei/3x-ui/v3/internal/config.buildCommit=${GITHUB_SHA:0:8} -X github.com/mhsanaei/3x-ui/v3/internal/config.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
  241. fi
  242. go build -ldflags "$LDFLAGS" -o xui-release.exe -v main.go
  243. - name: Copy and download resources
  244. shell: pwsh
  245. run: |
  246. mkdir x-ui
  247. Copy-Item xui-release.exe x-ui\x-ui.exe
  248. mkdir x-ui\bin
  249. cd x-ui\bin
  250. # Download Xray for Windows
  251. $Xray_URL = "https://github.com/XTLS/Xray-core/releases/download/v26.6.27/"
  252. Invoke-WebRequest -Uri "${Xray_URL}Xray-windows-64.zip" -OutFile "Xray-windows-64.zip"
  253. Expand-Archive -Path "Xray-windows-64.zip" -DestinationPath .
  254. Remove-Item "Xray-windows-64.zip"
  255. Remove-Item geoip.dat, geosite.dat -ErrorAction SilentlyContinue
  256. Invoke-WebRequest -Uri "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" -OutFile "geoip.dat"
  257. Invoke-WebRequest -Uri "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" -OutFile "geosite.dat"
  258. Invoke-WebRequest -Uri "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat" -OutFile "geoip_IR.dat"
  259. Invoke-WebRequest -Uri "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat" -OutFile "geosite_IR.dat"
  260. Invoke-WebRequest -Uri "https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat" -OutFile "geoip_RU.dat"
  261. Invoke-WebRequest -Uri "https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat" -OutFile "geosite_RU.dat"
  262. Rename-Item xray.exe xray-windows-amd64.exe
  263. # mtg-multi (MTProto sidecar) publishes a prebuilt Windows binary, so
  264. # download and unpack it instead of compiling.
  265. $MTG_MULTI_VER = "v1.14.0"
  266. $MTG_PKG = "mtg-multi-$($MTG_MULTI_VER.TrimStart('v'))-windows-amd64"
  267. curl.exe -sfLRO "https://github.com/mhsanaei/mtg-multi/releases/download/$MTG_MULTI_VER/$MTG_PKG.zip"
  268. Expand-Archive -Path "$MTG_PKG.zip" -DestinationPath "mtg-tmp" -Force
  269. Move-Item "mtg-tmp/$MTG_PKG/mtg-multi.exe" "mtg-windows-amd64.exe"
  270. Remove-Item -Recurse -Force "mtg-tmp", "$MTG_PKG.zip"
  271. cd ..
  272. Copy-Item -Path ..\windows_files\* -Destination . -Recurse
  273. cd ..
  274. - name: Package to Zip
  275. shell: pwsh
  276. run: |
  277. Compress-Archive -Path .\x-ui -DestinationPath "x-ui-windows-amd64.zip"
  278. - name: Upload files to Artifacts
  279. uses: actions/upload-artifact@v7
  280. with:
  281. name: x-ui-windows-amd64
  282. path: ./x-ui-windows-amd64.zip
  283. - name: Upload files to GH release
  284. uses: svenstaro/upload-release-action@v2
  285. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
  286. with:
  287. repo_token: ${{ secrets.GITHUB_TOKEN }}
  288. tag: ${{ github.ref_name }}
  289. file: x-ui-windows-amd64.zip
  290. asset_name: x-ui-windows-amd64.zip
  291. overwrite: true
  292. prerelease: true
  293. # =================================
  294. # Rolling dev channel (per-commit)
  295. # =================================
  296. # Publishes/overwrites the build artifacts to a single fixed-tag pre-release
  297. # `dev-latest`, force-moved to the new commit on every push to main. The panel's
  298. # "Dev" update channel installs from this tag. `--latest=false` is load-bearing:
  299. # it keeps releases/latest pointing at the real stable tag, so the stable
  300. # channel is unaffected.
  301. publish-dev:
  302. name: Publish rolling dev release
  303. needs: [build, build-windows]
  304. if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  305. runs-on: ubuntu-latest
  306. permissions:
  307. contents: write
  308. # Serialize racing pushes; never cancel an in-flight upload, or the dev
  309. # release could be left with a partial asset set.
  310. concurrency:
  311. group: dev-release
  312. cancel-in-progress: false
  313. steps:
  314. - name: Checkout repository
  315. uses: actions/checkout@v7
  316. - name: Download all build artifacts
  317. uses: actions/download-artifact@v8
  318. with:
  319. path: dev-artifacts
  320. merge-multiple: true
  321. - name: Publish dev-latest pre-release
  322. env:
  323. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  324. COMMIT: ${{ github.sha }}
  325. run: |
  326. set -e
  327. short="${COMMIT::8}"
  328. notes="Rolling development build — installs via the panel's Dev update channel.
  329. commit=${COMMIT}
  330. built=$(date -u +%Y-%m-%dT%H:%M:%SZ)
  331. Automated per-commit build from main. Not a stable release."
  332. # Force-move the dev-latest tag to this commit so the release tracks it.
  333. git tag -f dev-latest "${COMMIT}"
  334. git push -f origin refs/tags/dev-latest
  335. if gh release view dev-latest >/dev/null 2>&1; then
  336. gh release edit dev-latest --prerelease --latest=false \
  337. --title "Dev build ${short}" --notes "${notes}"
  338. else
  339. gh release create dev-latest --prerelease --latest=false \
  340. --target "${COMMIT}" --title "Dev build ${short}" --notes "${notes}"
  341. fi
  342. gh release upload dev-latest dev-artifacts/*.tar.gz dev-artifacts/*.zip --clobber