release.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. build:
  23. strategy:
  24. matrix:
  25. # Include amd64 on all platforms.
  26. goos: [windows, freebsd, openbsd, linux, dragonfly, darwin]
  27. goarch: [amd64, 386]
  28. exclude:
  29. # Exclude i386 on darwin and dragonfly.
  30. - goarch: 386
  31. goos: dragonfly
  32. - goarch: 386
  33. goos: darwin
  34. include:
  35. # BEIGIN MacOS ARM64
  36. - goos: darwin
  37. goarch: arm64
  38. # END MacOS ARM64
  39. # BEGIN Linux ARM 5 6 7
  40. - goos: linux
  41. goarch: arm
  42. goarm: 7
  43. - goos: linux
  44. goarch: arm
  45. goarm: 6
  46. - goos: linux
  47. goarch: arm
  48. goarm: 5
  49. # END Linux ARM 5 6 7
  50. # BEGIN Android ARM 8
  51. - goos: android
  52. goarch: arm64
  53. # END Android ARM 8
  54. # Windows ARM 7
  55. - goos: windows
  56. goarch: arm
  57. goarm: 7
  58. # BEGIN Other architectures
  59. # BEGIN riscv64 & ARM64
  60. - goos: linux
  61. goarch: arm64
  62. - goos: linux
  63. goarch: riscv64
  64. # END riscv64 & ARM64
  65. # BEGIN MIPS
  66. - goos: linux
  67. goarch: mips64
  68. - goos: linux
  69. goarch: mips64le
  70. - goos: linux
  71. goarch: mipsle
  72. - goos: linux
  73. goarch: mips
  74. # END MIPS
  75. # BEGIN PPC
  76. - goos: linux
  77. goarch: ppc64
  78. - goos: linux
  79. goarch: ppc64le
  80. # END PPC
  81. # BEGIN FreeBSD ARM
  82. - goos: freebsd
  83. goarch: arm64
  84. - goos: freebsd
  85. goarch: arm
  86. goarm: 7
  87. # END FreeBSD ARM
  88. # BEGIN S390X
  89. - goos: linux
  90. goarch: s390x
  91. # END S390X
  92. # END Other architectures
  93. # BEGIN OPENBSD ARM
  94. - goos: openbsd
  95. goarch: arm64
  96. - goos: openbsd
  97. goarch: arm
  98. goarm: 7
  99. # END OPENBSD ARM
  100. fail-fast: false
  101. runs-on: ubuntu-latest
  102. env:
  103. GOOS: ${{ matrix.goos }}
  104. GOARCH: ${{ matrix.goarch }}
  105. GOARM: ${{ matrix.goarm }}
  106. CGO_ENABLED: 0
  107. steps:
  108. - name: Checkout codebase
  109. uses: actions/checkout@v2
  110. - name: Show workflow information
  111. id: get_filename
  112. run: |
  113. export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
  114. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
  115. echo "::set-output name=ASSET_NAME::$_NAME"
  116. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  117. - name: Set up Go
  118. uses: actions/setup-go@v2
  119. with:
  120. go-version: ^1.16
  121. - name: Get project dependencies
  122. run: go mod download
  123. - name: Replace Custom to Commit ID
  124. if: github.event_name != 'release'
  125. run: |
  126. ID=$(git rev-parse --short ${{ github.sha }})
  127. if [ "${{ github.event_name }}" == 'pull_request' ]
  128. then
  129. ID=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})
  130. fi
  131. sed -i '/build/ s/Custom/'$ID'/' ./core/core.go
  132. - name: Build Xray
  133. run: |
  134. mkdir -p build_assets
  135. go build -v -o build_assets/xray -trimpath -ldflags "-s -w -buildid=" ./main
  136. - name: Build Mips softfloat Xray
  137. if: matrix.goarch == 'mips' || matrix.goarch == 'mipsle'
  138. run: |
  139. GOMIPS=softfloat go build -v -o build_assets/xray_softfloat -trimpath -ldflags "-s -w -buildid=" ./main
  140. - name: Rename Windows Xray
  141. if: matrix.goos == 'windows'
  142. run: |
  143. cd ./build_assets || exit 1
  144. mv xray xray.exe
  145. - name: Prepare to release
  146. run: |
  147. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  148. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  149. LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
  150. for i in "${LIST[@]}"
  151. do
  152. INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
  153. LASTEST_TAG="$(curl -sL "https://api.github.com/repos/v2fly/${INFO[0]}/releases" | jq -r ".[0].tag_name" || echo "latest")"
  154. FILE_NAME="${INFO[2]}.dat"
  155. echo -e "Downloading ${FILE_NAME}..."
  156. curl -L "https://github.com/v2fly/${INFO[0]}/releases/download/${LASTEST_TAG}/${INFO[1]}.dat" -o ./build_assets/${FILE_NAME}
  157. echo -e "Verifying HASH key..."
  158. HASH="$(curl -sL "https://github.com/v2fly/${INFO[0]}/releases/download/${LASTEST_TAG}/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
  159. [ "$(sha256sum "./build_assets/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
  160. done
  161. - name: Create ZIP archive
  162. shell: bash
  163. run: |
  164. pushd build_assets || exit 1
  165. touch -mt $(date +%Y01010000) *
  166. zip -9vr ../Xray-$ASSET_NAME.zip .
  167. popd || exit 1
  168. FILE=./Xray-$ASSET_NAME.zip
  169. DGST=$FILE.dgst
  170. for METHOD in {"md5","sha1","sha256","sha512"}
  171. do
  172. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  173. done
  174. - name: Change the name
  175. run: |
  176. mv build_assets Xray-$ASSET_NAME
  177. - name: Upload files to Artifacts
  178. uses: actions/upload-artifact@v2
  179. with:
  180. name: Xray-${{ steps.get_filename.outputs.ASSET_NAME }}
  181. path: |
  182. ./Xray-${{ steps.get_filename.outputs.ASSET_NAME }}/*
  183. - name: Upload binaries to release
  184. uses: svenstaro/upload-release-action@v2
  185. if: github.event_name == 'release'
  186. with:
  187. repo_token: ${{ secrets.GITHUB_TOKEN }}
  188. file: ./Xray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip*
  189. tag: ${{ github.ref }}
  190. file_glob: true