release.yml 5.8 KB

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