release.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.23
  121. - name: Get project dependencies
  122. run: go mod download
  123. - name: Build V2Ray
  124. run: |
  125. mkdir -p build_assets
  126. EXTRA_ARG=""
  127. case "$GOOS-$GOARCH" in
  128. "linux-386")
  129. ;&
  130. "linux-amd64")
  131. ;&
  132. "linux-arm64")
  133. EXTRA_ARG=EXTRA_ARG+"-buildmode=pie"
  134. ;;
  135. esac
  136. go build -v -o build_assets/v2ray -trimpath -ldflags "-s -w -buildid=" ./main
  137. - name: Rename Windows V2Ray
  138. if: matrix.goos == 'windows'
  139. run: |
  140. cd ./build_assets || exit 1
  141. mv v2ray v2ray.exe
  142. - name: Download geo files
  143. run: |
  144. wget -O release/config/geoip.dat "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
  145. wget -O release/config/geoip-only-cn-private.dat "https://raw.githubusercontent.com/v2fly/geoip/release/geoip-only-cn-private.dat"
  146. wget -O release/config/geosite.dat "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.dat"
  147. - name: Prepare package
  148. run: cp -v ./release/config/*.* ./build_assets
  149. - name: Prepare package for Linux
  150. if: matrix.goos == 'linux'
  151. run: cp -rv ./release/config/systemd ./build_assets/
  152. - name: Create ZIP archive
  153. run: |
  154. pushd build_assets || exit 1
  155. zip -9vr ../v2ray-$ASSET_NAME.zip .
  156. popd || exit 1
  157. FILE=./v2ray-$ASSET_NAME.zip
  158. DGST=$FILE.dgst
  159. openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST
  160. openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST
  161. openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST
  162. openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST
  163. - name: Upload ZIP file to Artifacts
  164. uses: actions/upload-artifact@v3
  165. with:
  166. name: v2ray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip
  167. path: v2ray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip
  168. - name: Upload files to GitHub release
  169. uses: svenstaro/upload-release-action@v2
  170. if: github.event_name == 'release'
  171. with:
  172. repo_token: ${{ secrets.GITHUB_TOKEN }}
  173. file_glob: true
  174. file: ./v2ray-${{ steps.get_filename.outputs.ASSET_NAME }}.zip*
  175. tag: ${{ github.ref }}
  176. overwrite: true
  177. signature:
  178. runs-on: ubuntu-latest
  179. needs: build
  180. steps:
  181. - name: Checkout codebase
  182. uses: actions/checkout@v3
  183. with:
  184. fetch-depth: 0
  185. - name: Set up Go
  186. uses: actions/setup-go@v4
  187. with:
  188. go-version: ^1.23
  189. - uses: actions/download-artifact@v3
  190. with:
  191. path: build_artifacts
  192. - name: Create extra package
  193. run: |
  194. pushd ./release/extra/
  195. zip -9vr ../../build_artifacts/v2ray-extra.zip .
  196. popd
  197. - name: Generate shasum
  198. run: |
  199. go get -v github.com/v2fly/V2BuildAssist/v2buildutil
  200. cd build_artifacts || exit 1
  201. mkdir .temp
  202. mv ./*/*.zip ./.temp
  203. rmdir ./*/
  204. mv ./.temp/* .
  205. ls -lah --recursive
  206. {
  207. go run github.com/v2fly/V2BuildAssist/v2buildutil gen version $(git describe --tags $(git rev-list --tags --max-count=1))
  208. go run github.com/v2fly/V2BuildAssist/v2buildutil gen project "v2fly"
  209. for zip in $(ls *.zip); do
  210. go run github.com/v2fly/V2BuildAssist/v2buildutil gen file ${zip}
  211. done
  212. } >Release.unsigned.unsorted
  213. go run github.com/v2fly/V2BuildAssist/v2buildutil gen sort < Release.unsigned.unsorted > Release.unsigned
  214. rm -f Release.unsigned.unsorted
  215. FILE=./Release.unsigned
  216. DGST=$FILE.dgst
  217. openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST
  218. openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST
  219. openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST
  220. openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST
  221. - uses: actions/upload-artifact@v3
  222. with:
  223. name: Release.unsigned
  224. path: build_artifacts/Release.unsigned
  225. - uses: actions/upload-artifact@v3
  226. with:
  227. name: Release.unsigned.dgst
  228. path: build_artifacts/Release.unsigned.dgst
  229. - uses: actions/upload-artifact@v3
  230. with:
  231. name: v2ray-extra.zip
  232. path: build_artifacts/v2ray-extra.zip
  233. - name: Upload Release.unsigned related files
  234. uses: svenstaro/upload-release-action@v2
  235. if: github.event_name == 'release'
  236. with:
  237. repo_token: ${{ secrets.GITHUB_TOKEN }}
  238. file_glob: true
  239. file: build_artifacts/Release.unsigned*
  240. tag: ${{ github.ref }}
  241. overwrite: true
  242. - name: Upload extra package
  243. uses: svenstaro/upload-release-action@v2
  244. if: github.event_name == 'release'
  245. with:
  246. repo_token: ${{ secrets.GITHUB_TOKEN }}
  247. file_glob: true
  248. file: build_artifacts/v2ray-extra.zip
  249. tag: ${{ github.ref }}
  250. overwrite: true
  251. buildContainer:
  252. if: github.event_name == 'release'
  253. needs: signature
  254. name: Build And Push image
  255. runs-on: ubuntu-latest
  256. env:
  257. REGISTRY_USER: ${{ github.actor }}
  258. REGISTRY_PASSWORD: ${{ github.token }}
  259. IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
  260. RELEASE_REPO: ${{ github.repository }}
  261. VERSION: ${{ github.event.release.tag_name }}
  262. TIMESTAMP: ${{ github.event.release.created_at }}
  263. PRERELEASE: ${{ github.event.release.prerelease }}
  264. VARIANTS: | # <v2ray variant>:<image tag suffix>
  265. std:
  266. extra:-extra
  267. ARCHS: | # <v2ray arch name>:<container arch name>
  268. 32:386
  269. 64:amd64
  270. arm32-v6:arm/v6
  271. arm32-v7a:arm/v7
  272. arm64-v8a:arm64
  273. arm64-v8a:arm64/v8
  274. steps:
  275. - uses: actions/checkout@v3
  276. - name: Log in to ghcr.io
  277. uses: redhat-actions/podman-login@v1
  278. with:
  279. username: ${{ env.REGISTRY_USER }}
  280. password: ${{ env.REGISTRY_PASSWORD }}
  281. registry: ${{ env.IMAGE_REGISTRY }}
  282. - name: Build Images
  283. id: build-image
  284. run: |
  285. image=v2ray
  286. tags=
  287. timestamp=$(date -d $TIMESTAMP +%s)
  288. versions="$VERSION" # full version (v1.2.3)
  289. versions="$versions $(echo $VERSION | cut -d. -f1,2)" # minor version (v1.2)
  290. if [ $PRERELEASE = false ]; then
  291. versions="$versions $(echo $VERSION | cut -d. -f1)" # major version (v1)
  292. versions="$versions latest"
  293. fi
  294. formatEach() {
  295. format=$1
  296. shift 1
  297. echo "$@" | xargs -n1 | xargs -i echo "$format" | xargs
  298. }
  299. for variant in $VARIANTS; do
  300. v2Variant=$(echo $variant | cut -d: -f1)
  301. containerVariant=$(echo $variant | cut -d: -f2)
  302. variantTags=$(formatEach "{}$containerVariant" $versions)
  303. tags="$tags $variantTags"
  304. for arch in $ARCHS; do
  305. v2Arch=$(echo $arch | cut -d: -f1)
  306. containerArch=$(echo $arch | cut -d: -f2)
  307. bash ./release/container/downloadAssets.sh $VERSION $v2Arch $containerArch $v2Variant
  308. for tag in $variantTags; do
  309. buildah bud \
  310. --manifest $image:$tag \
  311. --file ./release/container/Containerfile \
  312. --platform linux/$containerArch \
  313. --timestamp $timestamp \
  314. --squash \
  315. ./context/linux/$containerArch/$v2Variant
  316. done
  317. done
  318. done
  319. echo image=$image >> $GITHUB_OUTPUT
  320. echo tags=$tags >> $GITHUB_OUTPUT
  321. - name: Push To ghcr.io
  322. uses: redhat-actions/push-to-registry@v2
  323. with:
  324. image: ${{ steps.build-image.outputs.image }}
  325. tags: ${{ steps.build-image.outputs.tags }}
  326. registry: ${{ env.IMAGE_REGISTRY }}