release.yml 11 KB

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