1
0

release.yml 15 KB

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