release.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. name: Build and Release
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [published]
  6. push:
  7. branches:
  8. - main
  9. paths:
  10. - "**/*.go"
  11. - "go.mod"
  12. - "go.sum"
  13. - ".github/workflows/*.yml"
  14. pull_request:
  15. types: [opened, synchronize, reopened]
  16. paths:
  17. - "**/*.go"
  18. - "go.mod"
  19. - "go.sum"
  20. - ".github/workflows/*.yml"
  21. jobs:
  22. prepare:
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Restore Cache
  26. uses: actions/cache/restore@v3
  27. with:
  28. path: resources
  29. key: xray-geodat-
  30. - name: Update Geodat
  31. id: update
  32. uses: nick-fields/retry@v2
  33. with:
  34. timeout_minutes: 60
  35. retry_wait_seconds: 60
  36. max_attempts: 60
  37. command: |
  38. [ -d 'resources' ] || mkdir resources
  39. LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
  40. for i in "${LIST[@]}"
  41. do
  42. INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
  43. FILE_NAME="${INFO[2]}.dat"
  44. echo -e "Verifying HASH key..."
  45. HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
  46. if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
  47. continue
  48. else
  49. echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..."
  50. curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME}
  51. echo -e "Verifying HASH key..."
  52. [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
  53. echo "unhit=true" >> $GITHUB_OUTPUT
  54. fi
  55. done
  56. - name: Save Cache
  57. uses: actions/cache/save@v3
  58. if: ${{ steps.update.outputs.unhit }}
  59. with:
  60. path: resources
  61. key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
  62. build:
  63. needs: prepare
  64. permissions:
  65. contents: write
  66. strategy:
  67. matrix:
  68. # Include amd64 on all platforms.
  69. goos: [windows, freebsd, openbsd, linux, dragonfly, darwin]
  70. goarch: [amd64, 386]
  71. exclude:
  72. # Exclude i386 on darwin and dragonfly.
  73. - goarch: 386
  74. goos: dragonfly
  75. - goarch: 386
  76. goos: darwin
  77. include:
  78. # BEIGIN MacOS ARM64
  79. - goos: darwin
  80. goarch: arm64
  81. # END MacOS ARM64
  82. # BEGIN Linux ARM 5 6 7
  83. - goos: linux
  84. goarch: arm
  85. goarm: 7
  86. - goos: linux
  87. goarch: arm
  88. goarm: 6
  89. - goos: linux
  90. goarch: arm
  91. goarm: 5
  92. # END Linux ARM 5 6 7
  93. # BEGIN Android ARM 8
  94. - goos: android
  95. goarch: arm64
  96. # END Android ARM 8
  97. # Windows ARM
  98. - goos: windows
  99. goarch: arm64
  100. - goos: windows
  101. goarch: arm
  102. goarm: 7
  103. # BEGIN Other architectures
  104. # BEGIN riscv64 & ARM64 & LOONG64
  105. - goos: linux
  106. goarch: arm64
  107. - goos: linux
  108. goarch: riscv64
  109. - goos: linux
  110. goarch: loong64
  111. # END riscv64 & ARM64 & LOONG64
  112. # BEGIN MIPS
  113. - goos: linux
  114. goarch: mips64
  115. - goos: linux
  116. goarch: mips64le
  117. - goos: linux
  118. goarch: mipsle
  119. - goos: linux
  120. goarch: mips
  121. # END MIPS
  122. # BEGIN PPC
  123. - goos: linux
  124. goarch: ppc64
  125. - goos: linux
  126. goarch: ppc64le
  127. # END PPC
  128. # BEGIN FreeBSD ARM
  129. - goos: freebsd
  130. goarch: arm64
  131. - goos: freebsd
  132. goarch: arm
  133. goarm: 7
  134. # END FreeBSD ARM
  135. # BEGIN S390X
  136. - goos: linux
  137. goarch: s390x
  138. # END S390X
  139. # END Other architectures
  140. # BEGIN OPENBSD ARM
  141. - goos: openbsd
  142. goarch: arm64
  143. - goos: openbsd
  144. goarch: arm
  145. goarm: 7
  146. # END OPENBSD ARM
  147. fail-fast: false
  148. runs-on: ubuntu-latest
  149. env:
  150. GOOS: ${{ matrix.goos }}
  151. GOARCH: ${{ matrix.goarch }}
  152. GOARM: ${{ matrix.goarm }}
  153. CGO_ENABLED: 0
  154. steps:
  155. - name: Checkout codebase
  156. uses: actions/checkout@v3
  157. - name: Show workflow information
  158. run: |
  159. export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  160. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  161. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  162. - name: Set up Go
  163. uses: actions/setup-go@v4
  164. with:
  165. go-version: '1.20'
  166. check-latest: true
  167. - name: Get project dependencies
  168. run: go mod download
  169. - name: Replace Custom to Commit ID
  170. if: github.event_name != 'release'
  171. run: |
  172. ID=$(git rev-parse --short ${{ github.sha }})
  173. if [ "${{ github.event_name }}" == 'pull_request' ]
  174. then
  175. ID=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})
  176. fi
  177. sed -i '/build/ s/Custom/'$ID'/' ./core/core.go
  178. - name: Build Xray
  179. run: |
  180. mkdir -p build_assets
  181. go build -v -o build_assets/xray -trimpath -ldflags "-s -w -buildid=" ./main
  182. - name: Build background Xray on Windows
  183. if: matrix.goos == 'windows'
  184. run: |
  185. go build -v -o build_assets/wxray.exe -trimpath -ldflags "-s -w -H windowsgui -buildid=" ./main
  186. - name: Build Mips softfloat Xray
  187. if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
  188. run: |
  189. GOMIPS=softfloat go build -v -o build_assets/xray_softfloat -trimpath -ldflags "-s -w -buildid=" ./main
  190. - name: Rename Windows Xray
  191. if: matrix.goos == 'windows'
  192. run: |
  193. cd ./build_assets || exit 1
  194. mv xray xray.exe
  195. - name: Restore Cache
  196. uses: actions/cache/restore@v3
  197. with:
  198. path: resources
  199. key: xray-geodat-
  200. - name: Copy README.md & LICENSE
  201. run: |
  202. mv -f resources/* build_assets
  203. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  204. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  205. - name: Create ZIP archive
  206. shell: bash
  207. run: |
  208. pushd build_assets || exit 1
  209. touch -mt $(date +%Y01010000) *
  210. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  211. popd || exit 1
  212. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  213. DGST=$FILE.dgst
  214. for METHOD in {"md5","sha1","sha256","sha512"}
  215. do
  216. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  217. done
  218. - name: Change the name
  219. run: |
  220. mv build_assets Xray-${{ env.ASSET_NAME }}
  221. - name: Upload files to Artifacts
  222. uses: actions/upload-artifact@v3
  223. with:
  224. name: Xray-${{ env.ASSET_NAME }}
  225. path: |
  226. ./Xray-${{ env.ASSET_NAME }}/*
  227. - name: Upload binaries to release
  228. uses: svenstaro/upload-release-action@v2
  229. if: github.event_name == 'release'
  230. with:
  231. repo_token: ${{ secrets.GITHUB_TOKEN }}
  232. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  233. tag: ${{ github.ref }}
  234. file_glob: true