release-win7.yml 4.7 KB

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