release-win7.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. name: Build and Release for Windows 7
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [published]
  6. push:
  7. pull_request:
  8. types: [opened, synchronize, reopened]
  9. jobs:
  10. check-assets:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Restore Geodat Cache
  14. uses: actions/cache/restore@v5
  15. with:
  16. path: resources
  17. key: xray-geodat-
  18. - name: Restore Wintun Cache
  19. uses: actions/cache/restore@v5
  20. with:
  21. path: resources
  22. key: xray-wintun-
  23. - name: Check Assets Existence
  24. id: check-assets
  25. run: |
  26. [ -d 'resources' ] || mkdir resources
  27. LIST=('geoip.dat' 'geosite.dat')
  28. for FILE_NAME in "${LIST[@]}"
  29. do
  30. echo -e "Checking ${FILE_NAME}..."
  31. if [ -s "./resources/${FILE_NAME}" ]; then
  32. echo -e "${FILE_NAME} exists."
  33. else
  34. echo -e "${FILE_NAME} does not exist."
  35. echo "missing=true" >> $GITHUB_OUTPUT
  36. break
  37. fi
  38. done
  39. LIST=('amd64' 'x86')
  40. for ARCHITECTURE in "${LIST[@]}"
  41. do
  42. echo -e "Checking wintun.dll for ${ARCHITECTURE}..."
  43. if [ -s "./resources/wintun/bin/${ARCHITECTURE}/wintun.dll" ]; then
  44. echo -e "wintun.dll for ${ARCHITECTURE} exists."
  45. else
  46. echo -e "wintun.dll for ${ARCHITECTURE} is missing."
  47. echo "missing=true" >> $GITHUB_OUTPUT
  48. break
  49. fi
  50. done
  51. - name: Sleep for 90 seconds if Assets Missing
  52. if: steps.check-assets.outputs.missing == 'true'
  53. run: sleep 90
  54. build:
  55. needs: check-assets
  56. permissions:
  57. contents: write
  58. strategy:
  59. matrix:
  60. include:
  61. # BEGIN Windows 7
  62. - goos: windows
  63. goarch: amd64
  64. assetname: win7-64
  65. - goos: windows
  66. goarch: 386
  67. assetname: win7-32
  68. # END Windows 7
  69. fail-fast: false
  70. runs-on: ubuntu-latest
  71. env:
  72. GOOS: ${{ matrix.goos}}
  73. GOARCH: ${{ matrix.goarch }}
  74. CGO_ENABLED: 0
  75. steps:
  76. - name: Checkout codebase
  77. uses: actions/checkout@v6
  78. - name: Show workflow information
  79. run: |
  80. _NAME=${{ matrix.assetname }}
  81. echo "GOOS: ${{ matrix.goos }}, GOARCH: ${{ matrix.goarch }}, RELEASE_NAME: $_NAME"
  82. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  83. - name: Set up Go
  84. uses: actions/setup-go@v6
  85. with:
  86. go-version-file: go.mod
  87. check-latest: true
  88. - name: Setup patched builder
  89. run: |
  90. GOSDK=$(go env GOROOT)
  91. rm -r $GOSDK/*
  92. cd $GOSDK
  93. curl -O -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://github.com/XTLS/go-win7/releases/latest/download/go-for-win7-linux-amd64.zip
  94. unzip ./go-for-win7-linux-amd64.zip -d $GOSDK
  95. rm ./go-for-win7-linux-amd64.zip
  96. - name: Get project dependencies
  97. run: go mod download
  98. - name: Build Xray
  99. run: |
  100. mkdir -p build_assets
  101. COMMID=$(git describe --always --dirty)
  102. echo 'Building Xray for Windows 7...'
  103. go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  104. # The line below is for without running conhost.exe version. Commented for not being used. Provided for reference.
  105. # go build -o build_assets/wxray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
  106. - name: Restore Geodat Cache
  107. uses: actions/cache/restore@v5
  108. with:
  109. path: resources
  110. key: xray-geodat-
  111. - name: Restore Wintun Cache
  112. uses: actions/cache/restore@v5
  113. with:
  114. path: resources
  115. key: xray-wintun-
  116. - name: Add additional assets into package
  117. run: |
  118. mv -f resources/geo* build_assets/
  119. if [[ ${GOOS} == 'windows' ]]; then
  120. echo 'CreateObject("Wscript.Shell").Run "xray.exe -config config.json",0' > build_assets/xray_no_window.vbs
  121. echo 'Start-Process -FilePath ".\xray.exe" -ArgumentList "-config .\config.json" -WindowStyle Hidden' > build_assets/xray_no_window.ps1
  122. if [[ ${GOARCH} == 'amd64' ]]; then
  123. mv resources/wintun/bin/amd64/wintun.dll build_assets/
  124. fi
  125. if [[ ${GOARCH} == '386' ]]; then
  126. mv resources/wintun/bin/x86/wintun.dll build_assets/
  127. fi
  128. mv resources/wintun/LICENSE.txt build_assets/LICENSE-wintun.txt
  129. fi
  130. - name: Copy README.md & LICENSE
  131. run: |
  132. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  133. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  134. - name: Create ZIP archive
  135. if: github.event_name == 'release'
  136. shell: bash
  137. run: |
  138. pushd build_assets || exit 1
  139. touch -mt $(date +%Y01010000) *
  140. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  141. popd || exit 1
  142. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  143. DGST=$FILE.dgst
  144. for METHOD in {"md5","sha1","sha256","sha512"}
  145. do
  146. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  147. done
  148. - name: Upload binaries to release
  149. uses: svenstaro/upload-release-action@v2
  150. if: github.event_name == 'release'
  151. with:
  152. repo_token: ${{ secrets.GITHUB_TOKEN }}
  153. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  154. tag: ${{ github.ref }}
  155. file_glob: true
  156. - name: Upload files to Artifacts
  157. uses: actions/upload-artifact@v6
  158. with:
  159. name: Xray-${{ env.ASSET_NAME }}
  160. path: |
  161. ./build_assets/*