release.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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) is pure Go, so build it from source for the
  152. # target arch (GOOS/GOARCH/GOARM are already exported above). Its release
  153. # binaries only cover linux/darwin amd64/arm64; skip s390x/armv5 as before.
  154. # go install rejects GOBIN for cross-compiled targets, so let it install
  155. # into GOPATH/bin (a GOOS_GOARCH subdir when cross-compiling) and fetch
  156. # the binary from there.
  157. MTG_MULTI_VER="v1.11.0"
  158. case "${{ matrix.platform }}" in
  159. amd64|arm64|armv7|armv6|386)
  160. CGO_ENABLED=0 go install -trimpath -ldflags "-s -w" "github.com/dolonet/mtg-multi@${MTG_MULTI_VER}"
  161. MTG_BIN=$(find "$(go env GOPATH)/bin" -type f -name mtg-multi | head -n1)
  162. [ -n "$MTG_BIN" ] || { echo "mtg-multi binary not found under $(go env GOPATH)/bin" >&2; exit 1; }
  163. mv "$MTG_BIN" "mtg-linux-${{ matrix.platform }}"
  164. ;;
  165. esac
  166. cd ../..
  167. - name: Package
  168. run: tar -zcvf x-ui-linux-${{ matrix.platform }}.tar.gz x-ui
  169. - name: Upload files to Artifacts
  170. uses: actions/upload-artifact@v7
  171. with:
  172. name: x-ui-linux-${{ matrix.platform }}
  173. path: ./x-ui-linux-${{ matrix.platform }}.tar.gz
  174. - name: Upload files to GH release
  175. uses: svenstaro/upload-release-action@v2
  176. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
  177. with:
  178. repo_token: ${{ secrets.GITHUB_TOKEN }}
  179. tag: ${{ github.ref_name }}
  180. file: x-ui-linux-${{ matrix.platform }}.tar.gz
  181. asset_name: x-ui-linux-${{ matrix.platform }}.tar.gz
  182. overwrite: true
  183. prerelease: true
  184. # =================================
  185. # Windows Build
  186. # =================================
  187. build-windows:
  188. name: Build for Windows
  189. permissions:
  190. contents: write
  191. strategy:
  192. matrix:
  193. platform:
  194. - amd64
  195. runs-on: windows-latest
  196. steps:
  197. - name: Checkout repository
  198. uses: actions/checkout@v7
  199. - name: Setup Go
  200. uses: actions/setup-go@v6
  201. with:
  202. go-version-file: go.mod
  203. check-latest: true
  204. # Frontend dist must be built BEFORE go build — see comment on the
  205. # Linux job above. This step is identical except npm runs on the
  206. # Windows runner here.
  207. - name: Setup Node.js
  208. uses: actions/setup-node@v6
  209. with:
  210. node-version-file: .nvmrc
  211. cache: 'npm'
  212. cache-dependency-path: frontend/package-lock.json
  213. - name: Build frontend bundle
  214. shell: pwsh
  215. run: |
  216. npm ci
  217. npm run build
  218. working-directory: frontend
  219. - name: Install MSYS2
  220. uses: msys2/setup-msys2@v2
  221. with:
  222. msystem: MINGW64
  223. update: true
  224. install: >-
  225. mingw-w64-x86_64-gcc
  226. mingw-w64-x86_64-sqlite3
  227. mingw-w64-x86_64-pkg-config
  228. - name: Build 3X-UI for Windows (CGO)
  229. shell: msys2 {0}
  230. run: |
  231. export PATH="/c/hostedtoolcache/windows/go/$(ls /c/hostedtoolcache/windows/go | sort -V | tail -n1)/x64/bin:$PATH"
  232. export CGO_ENABLED=1
  233. export GOOS=windows
  234. export GOARCH=amd64
  235. export CC=x86_64-w64-mingw32-gcc
  236. which go
  237. go version
  238. gcc --version
  239. # Stamp the commit into per-commit (dev channel) builds only.
  240. LDFLAGS="-w -s"
  241. if [[ "$GITHUB_REF" != refs/tags/* ]]; then
  242. 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)"
  243. fi
  244. go build -ldflags "$LDFLAGS" -o xui-release.exe -v main.go
  245. - name: Copy and download resources
  246. shell: pwsh
  247. run: |
  248. mkdir x-ui
  249. Copy-Item xui-release.exe x-ui\x-ui.exe
  250. mkdir x-ui\bin
  251. cd x-ui\bin
  252. # Download Xray for Windows
  253. $Xray_URL = "https://github.com/XTLS/Xray-core/releases/download/v26.6.27/"
  254. Invoke-WebRequest -Uri "${Xray_URL}Xray-windows-64.zip" -OutFile "Xray-windows-64.zip"
  255. Expand-Archive -Path "Xray-windows-64.zip" -DestinationPath .
  256. Remove-Item "Xray-windows-64.zip"
  257. Remove-Item geoip.dat, geosite.dat -ErrorAction SilentlyContinue
  258. Invoke-WebRequest -Uri "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" -OutFile "geoip.dat"
  259. Invoke-WebRequest -Uri "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" -OutFile "geosite.dat"
  260. Invoke-WebRequest -Uri "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat" -OutFile "geoip_IR.dat"
  261. Invoke-WebRequest -Uri "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat" -OutFile "geosite_IR.dat"
  262. Invoke-WebRequest -Uri "https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat" -OutFile "geoip_RU.dat"
  263. Invoke-WebRequest -Uri "https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat" -OutFile "geosite_RU.dat"
  264. Rename-Item xray.exe xray-windows-amd64.exe
  265. # mtg-multi (MTProto sidecar) is pure Go; build it from source since the
  266. # fork publishes no Windows release binary.
  267. $MTG_MULTI_VER = "v1.11.0"
  268. $env:CGO_ENABLED = "0"
  269. $env:GOOS = "windows"
  270. $env:GOARCH = "amd64"
  271. $env:GOBIN = (Get-Location).Path
  272. go install -trimpath -ldflags "-s -w" "github.com/dolonet/mtg-multi@$MTG_MULTI_VER"
  273. Move-Item "mtg-multi.exe" "mtg-windows-amd64.exe"
  274. cd ..
  275. Copy-Item -Path ..\windows_files\* -Destination . -Recurse
  276. cd ..
  277. - name: Package to Zip
  278. shell: pwsh
  279. run: |
  280. Compress-Archive -Path .\x-ui -DestinationPath "x-ui-windows-amd64.zip"
  281. - name: Upload files to Artifacts
  282. uses: actions/upload-artifact@v7
  283. with:
  284. name: x-ui-windows-amd64
  285. path: ./x-ui-windows-amd64.zip
  286. - name: Upload files to GH release
  287. uses: svenstaro/upload-release-action@v2
  288. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
  289. with:
  290. repo_token: ${{ secrets.GITHUB_TOKEN }}
  291. tag: ${{ github.ref_name }}
  292. file: x-ui-windows-amd64.zip
  293. asset_name: x-ui-windows-amd64.zip
  294. overwrite: true
  295. prerelease: true
  296. # =================================
  297. # Rolling dev channel (per-commit)
  298. # =================================
  299. # Publishes/overwrites the build artifacts to a single fixed-tag pre-release
  300. # `dev-latest`, force-moved to the new commit on every push to main. The panel's
  301. # "Dev" update channel installs from this tag. `--latest=false` is load-bearing:
  302. # it keeps releases/latest pointing at the real stable tag, so the stable
  303. # channel is unaffected.
  304. publish-dev:
  305. name: Publish rolling dev release
  306. needs: [build, build-windows]
  307. if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  308. runs-on: ubuntu-latest
  309. permissions:
  310. contents: write
  311. # Serialize racing pushes; never cancel an in-flight upload, or the dev
  312. # release could be left with a partial asset set.
  313. concurrency:
  314. group: dev-release
  315. cancel-in-progress: false
  316. steps:
  317. - name: Checkout repository
  318. uses: actions/checkout@v7
  319. - name: Download all build artifacts
  320. uses: actions/download-artifact@v8
  321. with:
  322. path: dev-artifacts
  323. merge-multiple: true
  324. - name: Publish dev-latest pre-release
  325. env:
  326. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  327. COMMIT: ${{ github.sha }}
  328. run: |
  329. set -e
  330. short="${COMMIT::8}"
  331. notes="Rolling development build — installs via the panel's Dev update channel.
  332. commit=${COMMIT}
  333. built=$(date -u +%Y-%m-%dT%H:%M:%SZ)
  334. Automated per-commit build from main. Not a stable release."
  335. # Force-move the dev-latest tag to this commit so the release tracks it.
  336. git tag -f dev-latest "${COMMIT}"
  337. git push -f origin refs/tags/dev-latest
  338. if gh release view dev-latest >/dev/null 2>&1; then
  339. gh release edit dev-latest --prerelease --latest=false \
  340. --title "Dev build ${short}" --notes "${notes}"
  341. else
  342. gh release create dev-latest --prerelease --latest=false \
  343. --target "${COMMIT}" --title "Dev build ${short}" --notes "${notes}"
  344. fi
  345. gh release upload dev-latest dev-artifacts/*.tar.gz dev-artifacts/*.zip --clobber