release.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. name: Release 3X-UI
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [published]
  6. push:
  7. branches:
  8. - main
  9. tags:
  10. - "v*.*.*"
  11. paths:
  12. - '.github/workflows/release.yml'
  13. - '**.js'
  14. - '**.css'
  15. - '**.html'
  16. - '**.sh'
  17. - '**.go'
  18. - 'go.mod'
  19. - 'go.sum'
  20. - 'x-ui.service'
  21. jobs:
  22. build:
  23. permissions:
  24. contents: write
  25. strategy:
  26. matrix:
  27. platform:
  28. - amd64
  29. - arm64
  30. - armv7
  31. - armv6
  32. - 386
  33. - armv5
  34. - s390x
  35. runs-on: ubuntu-latest
  36. steps:
  37. - name: Checkout repository
  38. uses: actions/checkout@v5
  39. - name: Setup Go
  40. uses: actions/setup-go@v5
  41. with:
  42. go-version-file: go.mod
  43. check-latest: true
  44. - name: Build 3X-UI
  45. run: |
  46. export CGO_ENABLED=1
  47. export GOOS=linux
  48. export GOARCH=${{ matrix.platform }}
  49. # Use Bootlin prebuilt cross-toolchains (musl 1.2.5 in stable series)
  50. case "${{ matrix.platform }}" in
  51. amd64) BOOTLIN_ARCH="x86-64" ;;
  52. arm64) BOOTLIN_ARCH="aarch64" ;;
  53. armv7) BOOTLIN_ARCH="armv7-eabihf"; export GOARCH=arm GOARM=7 ;;
  54. armv6) BOOTLIN_ARCH="armv6-eabihf"; export GOARCH=arm GOARM=6 ;;
  55. armv5) BOOTLIN_ARCH="armv5-eabi"; export GOARCH=arm GOARM=5 ;;
  56. 386) BOOTLIN_ARCH="x86-i686" ;;
  57. s390x) BOOTLIN_ARCH="s390x-z13" ;;
  58. esac
  59. echo "Resolving Bootlin musl toolchain for arch=$BOOTLIN_ARCH (platform=${{ matrix.platform }})"
  60. TARBALL_BASE="https://toolchains.bootlin.com/downloads/releases/toolchains/$BOOTLIN_ARCH/tarballs/"
  61. TARBALL_URL=$(curl -fsSL "$TARBALL_BASE" | grep -oE "${BOOTLIN_ARCH}--musl--stable-[^\"]+\\.tar\\.xz" | sort -r | head -n1)
  62. [ -z "$TARBALL_URL" ] && { echo "Failed to locate Bootlin musl toolchain for arch=$BOOTLIN_ARCH" >&2; exit 1; }
  63. echo "Downloading: $TARBALL_URL"
  64. cd /tmp
  65. curl -fL -sS -o "$(basename "$TARBALL_URL")" "$TARBALL_BASE/$TARBALL_URL"
  66. tar -xf "$(basename "$TARBALL_URL")"
  67. TOOLCHAIN_DIR=$(find . -maxdepth 1 -type d -name "${BOOTLIN_ARCH}--musl--stable-*" | head -n1)
  68. export PATH="$(realpath "$TOOLCHAIN_DIR")/bin:$PATH"
  69. export CC=$(realpath "$(find "$TOOLCHAIN_DIR/bin" -name '*-gcc.br_real' -type f -executable | head -n1)")
  70. [ -z "$CC" ] && { echo "No gcc.br_real found in $TOOLCHAIN_DIR/bin" >&2; exit 1; }
  71. cd -
  72. go build -ldflags "-w -s -linkmode external -extldflags '-static'" -o xui-release -v main.go
  73. file xui-release
  74. ldd xui-release || echo "Static binary confirmed"
  75. mkdir x-ui
  76. cp xui-release x-ui/
  77. cp x-ui.service x-ui/
  78. cp x-ui.sh x-ui/
  79. mv x-ui/xui-release x-ui/x-ui
  80. mkdir x-ui/bin
  81. cd x-ui/bin
  82. # Download dependencies
  83. Xray_URL="https://github.com/XTLS/Xray-core/releases/download/v25.9.5/"
  84. if [ "${{ matrix.platform }}" == "amd64" ]; then
  85. wget -q ${Xray_URL}Xray-linux-64.zip
  86. unzip Xray-linux-64.zip
  87. rm -f Xray-linux-64.zip
  88. elif [ "${{ matrix.platform }}" == "arm64" ]; then
  89. wget -q ${Xray_URL}Xray-linux-arm64-v8a.zip
  90. unzip Xray-linux-arm64-v8a.zip
  91. rm -f Xray-linux-arm64-v8a.zip
  92. elif [ "${{ matrix.platform }}" == "armv7" ]; then
  93. wget -q ${Xray_URL}Xray-linux-arm32-v7a.zip
  94. unzip Xray-linux-arm32-v7a.zip
  95. rm -f Xray-linux-arm32-v7a.zip
  96. elif [ "${{ matrix.platform }}" == "armv6" ]; then
  97. wget -q ${Xray_URL}Xray-linux-arm32-v6.zip
  98. unzip Xray-linux-arm32-v6.zip
  99. rm -f Xray-linux-arm32-v6.zip
  100. elif [ "${{ matrix.platform }}" == "386" ]; then
  101. wget -q ${Xray_URL}Xray-linux-32.zip
  102. unzip Xray-linux-32.zip
  103. rm -f Xray-linux-32.zip
  104. elif [ "${{ matrix.platform }}" == "armv5" ]; then
  105. wget -q ${Xray_URL}Xray-linux-arm32-v5.zip
  106. unzip Xray-linux-arm32-v5.zip
  107. rm -f Xray-linux-arm32-v5.zip
  108. elif [ "${{ matrix.platform }}" == "s390x" ]; then
  109. wget -q ${Xray_URL}Xray-linux-s390x.zip
  110. unzip Xray-linux-s390x.zip
  111. rm -f Xray-linux-s390x.zip
  112. fi
  113. rm -f geoip.dat geosite.dat
  114. wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
  115. wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
  116. wget -q -O geoip_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
  117. wget -q -O geosite_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
  118. wget -q -O geoip_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat
  119. wget -q -O geosite_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat
  120. mv xray xray-linux-${{ matrix.platform }}
  121. cd ../..
  122. - name: Package
  123. run: tar -zcvf x-ui-linux-${{ matrix.platform }}.tar.gz x-ui
  124. - name: Upload files to Artifacts
  125. uses: actions/upload-artifact@v4
  126. with:
  127. name: x-ui-linux-${{ matrix.platform }}
  128. path: ./x-ui-linux-${{ matrix.platform }}.tar.gz
  129. - name: Upload files to GH release
  130. uses: svenstaro/upload-release-action@v2
  131. if: github.event_name == 'release' && github.event.action == 'published'
  132. with:
  133. repo_token: ${{ secrets.GITHUB_TOKEN }}
  134. tag: ${{ github.ref }}
  135. file: x-ui-linux-${{ matrix.platform }}.tar.gz
  136. asset_name: x-ui-linux-${{ matrix.platform }}.tar.gz
  137. prerelease: true