release.yml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. name: Release
  2. on:
  3. release:
  4. types: [prereleased]
  5. push:
  6. branches:
  7. - master
  8. - v*
  9. - dev*
  10. paths:
  11. - "**/*.go"
  12. - "go.mod"
  13. - "go.sum"
  14. - ".github/workflows/*.yml"
  15. pull_request:
  16. types: [opened, synchronize, reopened]
  17. paths:
  18. - "**/*.go"
  19. - "go.mod"
  20. - "go.sum"
  21. - ".github/workflows/*.yml"
  22. jobs:
  23. build:
  24. strategy:
  25. matrix:
  26. # Include amd64 on all platforms.
  27. goos: [windows, freebsd, openbsd, linux, dragonfly, darwin]
  28. goarch: [amd64, 386]
  29. exclude:
  30. # Exclude i386 on darwin and dragonfly.
  31. - goarch: 386
  32. goos: dragonfly
  33. - goarch: 386
  34. goos: darwin
  35. include:
  36. # BEGIN Linux ARM 5 6 7
  37. - goos: linux
  38. goarch: arm
  39. goarm: 7
  40. - goos: linux
  41. goarch: arm
  42. goarm: 6
  43. - goos: linux
  44. goarch: arm
  45. goarm: 5
  46. # END Linux ARM 5 6 7
  47. # BEGIN Windows ARM 7
  48. - goos: windows
  49. goarch: arm
  50. goarm: 7
  51. # END Windows ARM 7
  52. # BEGIN FreeBSD ARM 6 7
  53. - goos: freebsd
  54. goarch: arm
  55. goarm: 6
  56. - goos: freebsd
  57. goarch: arm
  58. goarm: 7
  59. # END FreeBSD ARM 6 7
  60. # BEGIN OpenBSD ARM 6 7
  61. - goos: openbsd
  62. goarch: arm
  63. goarm: 6
  64. - goos: openbsd
  65. goarch: arm
  66. goarm: 7
  67. # END OpenBSD ARM 6 7
  68. # BEGIN Other architectures
  69. - goos: darwin
  70. goarch: arm64
  71. - goos: linux
  72. goarch: arm64
  73. - goos: linux
  74. goarch: riscv64
  75. - goos: linux
  76. goarch: loong64
  77. - goos: windows
  78. goarch: arm64
  79. - goos: android
  80. goarch: arm64
  81. - goos: freebsd
  82. goarch: arm64
  83. - goos: openbsd
  84. goarch: arm64
  85. # BEGIN MIPS
  86. - goos: linux
  87. goarch: mips64
  88. - goos: linux
  89. goarch: mips64le
  90. - goos: linux
  91. goarch: mipsle
  92. - goos: linux
  93. goarch: mips
  94. # END MIPS
  95. # END Other architectures
  96. fail-fast: false
  97. runs-on: ubuntu-latest
  98. env:
  99. GOOS: ${{ matrix.goos }}
  100. GOARCH: ${{ matrix.goarch }}
  101. GOARM: ${{ matrix.goarm }}
  102. CGO_ENABLED: 0
  103. steps:
  104. - name: Checkout codebase
  105. uses: actions/checkout@v3
  106. with:
  107. fetch-depth: 0
  108. - name: Show workflow information
  109. id: get_filename
  110. run: |
  111. export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM\"].friendlyName" -r < release/friendly-filenames.json)
  112. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, RELEASE_NAME: $_NAME"
  113. echo "ASSET_NAME=$_NAME" >> $GITHUB_OUTPUT
  114. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  115. - name: Set up Go
  116. uses: actions/setup-go@v4
  117. with:
  118. go-version: ^1.20
  119. - name: Get project dependencies
  120. run: go mod download
  121. - name: Build V2Ray
  122. run: |
  123. mkdir -p build_assets
  124. go build -v -o build_assets/v2ray -trimpath -ldflags "-s -w -buildid=" ./main
  125. - name: Rename Windows V2Ray
  126. if: matrix.goos == 'windows'
  127. run: |
  128. cd ./build_assets || exit 1
  129. mv v2ray v2ray.exe
  130. - name: Download geo files
  131. run: |
  132. wget -O release/config/geoip.dat "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
  133. wget -O release/config/geoip-only-cn-private.dat "https://raw.githubusercontent.com/v2fly/geoip/release/geoip-only-cn-private.dat"
  134. wget -O release/config/geosite.dat "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
  135. - name: Prepare package
  136. run: cp -v ./release/config/*.* ./build_assets
  137. - name: Prepare package for Linux
  138. if: matrix.goos == 'linux'
  139. run: cp -rv ./release/config/systemd ./build_assets/
  140. - name: Create ZIP archive
  141. run: |
  142. pushd build_assets || exit 1
  143. zip -9vr ../v2ray-$ASSET_NAME.zip .
  144. popd || exit 1
  145. FILE=./v2ray-$ASSET_NAME.zip
  146. DGST=$FILE.dgst
  147. openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST
  148. openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST
  149. openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST
  150. openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST
  151. - name: Upload ZIP file to Artifacts
  152. uses: actions/upload-artifact@v3
  153. with:
  154. name: v2ray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip
  155. path: v2ray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip
  156. - name: Upload files to GitHub release
  157. uses: svenstaro/upload-release-action@v2
  158. if: github.event_name == 'release'
  159. with:
  160. repo_token: ${{ secrets.GITHUB_TOKEN }}
  161. file_glob: true
  162. file: ./v2ray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip*
  163. tag: ${{ github.ref }}
  164. signature:
  165. runs-on: ubuntu-latest
  166. needs: build
  167. steps:
  168. - name: Checkout codebase
  169. uses: actions/checkout@v3
  170. with:
  171. fetch-depth: 0
  172. - name: Set up Go
  173. uses: actions/setup-go@v4
  174. with:
  175. go-version: ^1.20
  176. - uses: actions/download-artifact@v3
  177. with:
  178. path: build_artifacts
  179. - name: Create extra package
  180. run: |
  181. pushd ./release/extra/
  182. zip -9vr ../../build_artifacts/v2ray-extra.zip .
  183. popd
  184. - name: Generate shasum
  185. run: |
  186. go get -v github.com/v2fly/V2BuildAssist/v2buildutil
  187. cd build_artifacts || exit 1
  188. mkdir .temp
  189. mv ./*/*.zip ./.temp
  190. rmdir ./*/
  191. mv ./.temp/* .
  192. ls -lah --recursive
  193. {
  194. go run github.com/v2fly/V2BuildAssist/v2buildutil gen version $(git describe --tags $(git rev-list --tags --max-count=1))
  195. go run github.com/v2fly/V2BuildAssist/v2buildutil gen project "v2fly"
  196. for zip in $(ls *.zip); do
  197. go run github.com/v2fly/V2BuildAssist/v2buildutil gen file ${zip}
  198. done
  199. } >Release.unsigned.unsorted
  200. go run github.com/v2fly/V2BuildAssist/v2buildutil gen sort < Release.unsigned.unsorted > Release.unsigned
  201. rm -f Release.unsigned.unsorted
  202. FILE=./Release.unsigned
  203. DGST=$FILE.dgst
  204. openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST
  205. openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST
  206. openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST
  207. openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST
  208. - uses: actions/upload-artifact@v3
  209. with:
  210. name: Release.unsigned
  211. path: build_artifacts/Release.unsigned
  212. - uses: actions/upload-artifact@v3
  213. with:
  214. name: Release.unsigned.dgst
  215. path: build_artifacts/Release.unsigned.dgst
  216. - uses: actions/upload-artifact@v3
  217. with:
  218. name: v2ray-extra.zip
  219. path: build_artifacts/v2ray-extra.zip
  220. - name: Upload Release.unsigned related files
  221. uses: svenstaro/upload-release-action@v2
  222. if: github.event_name == 'release'
  223. with:
  224. repo_token: ${{ secrets.GITHUB_TOKEN }}
  225. file_glob: true
  226. file: build_artifacts/Release.unsigned*
  227. tag: ${{ github.ref }}
  228. - name: Upload extra package
  229. uses: svenstaro/upload-release-action@v2
  230. if: github.event_name == 'release'
  231. with:
  232. repo_token: ${{ secrets.GITHUB_TOKEN }}
  233. file_glob: true
  234. file: build_artifacts/v2ray-extra.zip
  235. tag: ${{ github.ref }}
  236. buildContainer:
  237. if: github.event_name == 'release'
  238. needs: signature
  239. strategy:
  240. fail-fast: false
  241. matrix:
  242. variant: [std, extra]
  243. arch:
  244. - v2Name: 32
  245. containerName: 386
  246. - v2Name: 64
  247. containerName: amd64
  248. - v2Name: arm32-v6
  249. containerName: arm/v6
  250. - v2Name: arm32-v7a
  251. containerName: arm/v7
  252. - v2Name: arm64-v8a
  253. containerName: arm64
  254. - v2Name: arm64-v8a
  255. containerName: arm64/v8
  256. name: Build And Push image
  257. runs-on: ubuntu-latest
  258. env:
  259. REGISTRY_USER: ${{ github.actor }}
  260. REGISTRY_PASSWORD: ${{ github.token }}
  261. IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
  262. RELEASE_REPO: ${{ github.repository }}
  263. steps:
  264. - uses: actions/checkout@v3
  265. - name: Log in to ghcr.io
  266. uses: redhat-actions/podman-login@v1
  267. with:
  268. username: ${{ env.REGISTRY_USER }}
  269. password: ${{ env.REGISTRY_PASSWORD }}
  270. registry: ${{ env.IMAGE_REGISTRY }}
  271. - name: Download Assets
  272. run: |
  273. bash ./release/container/downloadAssets.sh ${{ github.ref_name }} ${{ matrix.arch.v2Name }} ${{ matrix.arch.containerName }} ${{ matrix.variant }}
  274. - name: Buildah Action
  275. id: build-image
  276. uses: redhat-actions/buildah-build@v2
  277. with:
  278. image: v2ray
  279. tags: ${{ github.ref_name }}-${{ matrix.arch.v2Name }}-${{ matrix.variant }}
  280. containerfiles: |
  281. ./release/container/Containerfile
  282. build-args: |
  283. TARGETPLATFORM=${{ matrix.arch.containerName }}
  284. VARIANT=${{ matrix.variant }}
  285. archs: ${{ matrix.arch.containerName }}
  286. context: context/linux/${{ matrix.arch.containerName }}/${{ matrix.variant }}
  287. extra-args: |
  288. --squash
  289. --timestamp 0
  290. - name: Push To ghcr.io
  291. uses: redhat-actions/push-to-registry@v2
  292. with:
  293. image: ${{ steps.build-image.outputs.image }}
  294. tags: ${{ steps.build-image.outputs.tags }}
  295. registry: ${{ env.IMAGE_REGISTRY }}