release.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. name: Build and Release
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [published]
  6. push:
  7. pull_request:
  8. types: [opened, synchronize, reopened]
  9. jobs:
  10. build:
  11. permissions:
  12. contents: write
  13. strategy:
  14. matrix:
  15. # Include amd64 on all platforms.
  16. goos: [windows, freebsd, openbsd, linux, darwin]
  17. goarch: [amd64, 386]
  18. patch-assetname: [""]
  19. exclude:
  20. # Exclude i386 on darwin
  21. - goarch: 386
  22. goos: darwin
  23. include:
  24. # BEGIN MacOS ARM64
  25. - goos: darwin
  26. goarch: arm64
  27. # END MacOS ARM64
  28. # BEGIN Linux ARM 5 6 7
  29. - goos: linux
  30. goarch: arm
  31. goarm: 7
  32. - goos: linux
  33. goarch: arm
  34. goarm: 6
  35. - goos: linux
  36. goarch: arm
  37. goarm: 5
  38. # END Linux ARM 5 6 7
  39. # BEGIN Android ARM 8
  40. - goos: android
  41. goarch: arm64
  42. # END Android ARM 8
  43. # Windows ARM
  44. - goos: windows
  45. goarch: arm64
  46. - goos: windows
  47. goarch: arm
  48. goarm: 7
  49. # BEGIN Other architectures
  50. # BEGIN riscv64 & ARM64 & LOONG64
  51. - goos: linux
  52. goarch: arm64
  53. - goos: linux
  54. goarch: riscv64
  55. - goos: linux
  56. goarch: loong64
  57. # END riscv64 & ARM64 & LOONG64
  58. # BEGIN MIPS
  59. - goos: linux
  60. goarch: mips64
  61. - goos: linux
  62. goarch: mips64le
  63. - goos: linux
  64. goarch: mipsle
  65. - goos: linux
  66. goarch: mips
  67. # END MIPS
  68. # BEGIN PPC
  69. - goos: linux
  70. goarch: ppc64
  71. - goos: linux
  72. goarch: ppc64le
  73. # END PPC
  74. # BEGIN FreeBSD ARM
  75. - goos: freebsd
  76. goarch: arm64
  77. - goos: freebsd
  78. goarch: arm
  79. goarm: 7
  80. # END FreeBSD ARM
  81. # BEGIN S390X
  82. - goos: linux
  83. goarch: s390x
  84. # END S390X
  85. # END Other architectures
  86. # BEGIN OPENBSD ARM
  87. - goos: openbsd
  88. goarch: arm64
  89. - goos: openbsd
  90. goarch: arm
  91. goarm: 7
  92. # END OPENBSD ARM
  93. fail-fast: false
  94. runs-on: ubuntu-latest
  95. env:
  96. GOOS: ${{ matrix.goos }}
  97. GOARCH: ${{ matrix.goarch }}
  98. GOARM: ${{ matrix.goarm }}
  99. CGO_ENABLED: 0
  100. steps:
  101. - name: Checkout codebase
  102. uses: actions/checkout@v4
  103. - name: Show workflow information
  104. run: |
  105. _NAME=${{ matrix.patch-assetname }}
  106. [ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  107. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  108. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  109. - name: Set up Go
  110. uses: actions/setup-go@v5
  111. with:
  112. go-version-file: go.mod
  113. check-latest: true
  114. - name: Get project dependencies
  115. run: go mod download
  116. - name: Build Xray
  117. run: |
  118. mkdir -p build_assets
  119. COMMID=$(git describe --always --dirty)
  120. if [[ ${GOOS} == 'windows' ]]; then
  121. echo 'Building Xray for Windows...'
  122. go build -o build_assets/xray.exe -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  123. echo 'CreateObject("Wscript.Shell").Run "xray.exe -config config.json",0' > build_assets/xray_no_window.vbs
  124. echo 'Start-Process -FilePath ".\xray.exe" -ArgumentList "-config .\config.json" -WindowStyle Hidden' > build_assets/xray_no_window.ps1
  125. # The line below is for without running conhost.exe version. Commented for not being used. Provided for reference.
  126. # go build -o build_assets/wxray.exe -trimpath -buildvcs=false -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  127. else
  128. echo 'Building Xray...'
  129. go build -o build_assets/xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  130. if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
  131. echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
  132. GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  133. fi
  134. fi
  135. - name: Restore Geodat Cache
  136. uses: actions/cache/restore@v4
  137. with:
  138. path: resources
  139. key: xray-geodat-
  140. - name: Copy README.md & LICENSE
  141. run: |
  142. mv -f resources/* build_assets
  143. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  144. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  145. - name: Create ZIP archive
  146. if: github.event_name == 'release'
  147. shell: bash
  148. run: |
  149. pushd build_assets || exit 1
  150. touch -mt $(date +%Y01010000) *
  151. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  152. popd || exit 1
  153. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  154. DGST=$FILE.dgst
  155. for METHOD in {"md5","sha1","sha256","sha512"}
  156. do
  157. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  158. done
  159. - name: Change the name
  160. run: |
  161. mv build_assets Xray-${{ env.ASSET_NAME }}
  162. - name: Upload files to Artifacts
  163. uses: actions/upload-artifact@v4
  164. with:
  165. name: Xray-${{ env.ASSET_NAME }}
  166. path: |
  167. ./Xray-${{ env.ASSET_NAME }}/*
  168. - name: Upload binaries to release
  169. uses: svenstaro/upload-release-action@v2
  170. if: github.event_name == 'release'
  171. with:
  172. repo_token: ${{ secrets.GITHUB_TOKEN }}
  173. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  174. tag: ${{ github.ref }}
  175. file_glob: true