1
0

release.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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.22/"
  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 (MTProto sidecar) - only for arches mtg publishes
  152. MTG_VER="2.2.8"
  153. case "${{ matrix.platform }}" in
  154. amd64|arm64|armv7|armv6|386)
  155. wget -q "https://github.com/9seconds/mtg/releases/download/v${MTG_VER}/mtg-${MTG_VER}-linux-${{ matrix.platform }}.tar.gz"
  156. tar -xzf "mtg-${MTG_VER}-linux-${{ matrix.platform }}.tar.gz"
  157. mv "mtg-${MTG_VER}-linux-${{ matrix.platform }}/mtg" "mtg-linux-${{ matrix.platform }}" 2>/dev/null || mv mtg "mtg-linux-${{ matrix.platform }}"
  158. rm -rf "mtg-${MTG_VER}-linux-${{ matrix.platform }}" "mtg-${MTG_VER}-linux-${{ matrix.platform }}.tar.gz"
  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.22/"
  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. # Download mtg (MTProto sidecar) for Windows
  261. $MTG_VER = "2.2.8"
  262. Invoke-WebRequest -Uri "https://github.com/9seconds/mtg/releases/download/v$MTG_VER/mtg-$MTG_VER-windows-amd64.zip" -OutFile "mtg-windows-amd64.zip"
  263. Expand-Archive -Path "mtg-windows-amd64.zip" -DestinationPath "mtg-tmp"
  264. $mtgExe = Get-ChildItem -Path "mtg-tmp" -Recurse -Filter "mtg.exe" | Select-Object -First 1
  265. Move-Item $mtgExe.FullName "mtg-windows-amd64.exe"
  266. Remove-Item "mtg-windows-amd64.zip", "mtg-tmp" -Recurse -Force
  267. cd ..
  268. Copy-Item -Path ..\windows_files\* -Destination . -Recurse
  269. cd ..
  270. - name: Package to Zip
  271. shell: pwsh
  272. run: |
  273. Compress-Archive -Path .\x-ui -DestinationPath "x-ui-windows-amd64.zip"
  274. - name: Upload files to Artifacts
  275. uses: actions/upload-artifact@v7
  276. with:
  277. name: x-ui-windows-amd64
  278. path: ./x-ui-windows-amd64.zip
  279. - name: Upload files to GH release
  280. uses: svenstaro/upload-release-action@v2
  281. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
  282. with:
  283. repo_token: ${{ secrets.GITHUB_TOKEN }}
  284. tag: ${{ github.ref_name }}
  285. file: x-ui-windows-amd64.zip
  286. asset_name: x-ui-windows-amd64.zip
  287. overwrite: true
  288. prerelease: true
  289. # =================================
  290. # Rolling dev channel (per-commit)
  291. # =================================
  292. # Publishes/overwrites the build artifacts to a single fixed-tag pre-release
  293. # `dev-latest`, force-moved to the new commit on every push to main. The panel's
  294. # "Dev" update channel installs from this tag. `--latest=false` is load-bearing:
  295. # it keeps releases/latest pointing at the real stable tag, so the stable
  296. # channel is unaffected.
  297. publish-dev:
  298. name: Publish rolling dev release
  299. needs: [build, build-windows]
  300. if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  301. runs-on: ubuntu-latest
  302. permissions:
  303. contents: write
  304. # Serialize racing pushes; never cancel an in-flight upload, or the dev
  305. # release could be left with a partial asset set.
  306. concurrency:
  307. group: dev-release
  308. cancel-in-progress: false
  309. steps:
  310. - name: Checkout repository
  311. uses: actions/checkout@v7
  312. - name: Download all build artifacts
  313. uses: actions/download-artifact@v7
  314. with:
  315. path: dev-artifacts
  316. merge-multiple: true
  317. - name: Publish dev-latest pre-release
  318. env:
  319. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  320. COMMIT: ${{ github.sha }}
  321. run: |
  322. set -e
  323. short="${COMMIT::8}"
  324. notes="Rolling development build — installs via the panel's Dev update channel.
  325. commit=${COMMIT}
  326. built=$(date -u +%Y-%m-%dT%H:%M:%SZ)
  327. Automated per-commit build from main. Not a stable release."
  328. # Force-move the dev-latest tag to this commit so the release tracks it.
  329. git tag -f dev-latest "${COMMIT}"
  330. git push -f origin refs/tags/dev-latest
  331. if gh release view dev-latest >/dev/null 2>&1; then
  332. gh release edit dev-latest --prerelease --latest=false \
  333. --title "Dev build ${short}" --notes "${notes}"
  334. else
  335. gh release create dev-latest --prerelease --latest=false \
  336. --target "${COMMIT}" --title "Dev build ${short}" --notes "${notes}"
  337. fi
  338. gh release upload dev-latest dev-artifacts/*.tar.gz dev-artifacts/*.zip --clobber