release.yml 5.7 KB

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