release.yml 11 KB

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