release-win7.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. name: Build and Release for Windows 7
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [published]
  6. push:
  7. branches:
  8. - main
  9. paths:
  10. # - "**/*.go"
  11. - "go.mod"
  12. - "go.sum"
  13. - ".github/workflows/release-win7.yml"
  14. pull_request:
  15. types: [opened, synchronize, reopened]
  16. paths:
  17. # - "**/*.go"
  18. - "go.mod"
  19. - "go.sum"
  20. - ".github/workflows/release-win7.yml"
  21. jobs:
  22. prepare:
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Restore Cache
  26. uses: actions/cache/restore@v4
  27. with:
  28. path: resources
  29. key: xray-geodat-
  30. - name: Update Geodat
  31. id: update
  32. uses: nick-fields/retry@v3
  33. with:
  34. timeout_minutes: 60
  35. retry_wait_seconds: 60
  36. max_attempts: 60
  37. command: |
  38. [ -d 'resources' ] || mkdir resources
  39. LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
  40. for i in "${LIST[@]}"
  41. do
  42. INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
  43. FILE_NAME="${INFO[2]}.dat"
  44. echo -e "Verifying HASH key..."
  45. HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
  46. if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
  47. continue
  48. else
  49. echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..."
  50. curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME}
  51. echo -e "Verifying HASH key..."
  52. [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
  53. echo "unhit=true" >> $GITHUB_OUTPUT
  54. fi
  55. done
  56. - name: Save Cache
  57. uses: actions/cache/save@v4
  58. if: ${{ steps.update.outputs.unhit }}
  59. with:
  60. path: resources
  61. key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
  62. build:
  63. needs: prepare
  64. permissions:
  65. contents: write
  66. strategy:
  67. matrix:
  68. include:
  69. # BEGIN Windows 7
  70. - goos: windows
  71. goarch: amd64
  72. assetname: win7-64
  73. - goos: windows
  74. goarch: 386
  75. assetname: win7-32
  76. # END Windows 7
  77. fail-fast: false
  78. runs-on: ubuntu-latest
  79. env:
  80. GOOS: ${{ matrix.goos}}
  81. GOARCH: ${{ matrix.goarch }}
  82. CGO_ENABLED: 0
  83. steps:
  84. - name: Show workflow information
  85. run: |
  86. _NAME=${{ matrix.assetname }}
  87. echo "GOOS: ${{ matrix.goos }}, GOARCH: ${{ matrix.goarch }}, RELEASE_NAME: $_NAME"
  88. echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
  89. - name: Set up Go
  90. uses: actions/setup-go@v5
  91. with:
  92. go-version: stable
  93. check-latest: true
  94. - name: Setup patched builder
  95. run: |
  96. GOSDK=$(go env GOROOT)
  97. curl -O -L https://github.com/XTLS/go-win7/releases/latest/download/go-for-win7-linux-amd64.zip
  98. rm -r $GOSDK/*
  99. unzip ./go-for-win7-linux-amd64.zip -d $GOSDK
  100. - name: Checkout codebase
  101. uses: actions/checkout@v4
  102. - name: Get project dependencies
  103. run: go mod download
  104. - name: Build Xray
  105. run: |
  106. mkdir -p build_assets
  107. make
  108. find . -maxdepth 1 -type f -regex './\(wxray\|xray\).exe' -exec mv {} ./build_assets/ \;
  109. - name: Restore Cache
  110. uses: actions/cache/restore@v4
  111. with:
  112. path: resources
  113. key: xray-geodat-
  114. - name: Copy README.md & LICENSE
  115. run: |
  116. mv -f resources/* build_assets
  117. cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
  118. cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
  119. - name: Create ZIP archive
  120. if: github.event_name == 'release'
  121. shell: bash
  122. run: |
  123. pushd build_assets || exit 1
  124. touch -mt $(date +%Y01010000) *
  125. zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
  126. popd || exit 1
  127. FILE=./Xray-${{ env.ASSET_NAME }}.zip
  128. DGST=$FILE.dgst
  129. for METHOD in {"md5","sha1","sha256","sha512"}
  130. do
  131. openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
  132. done
  133. - name: Change the name
  134. run: |
  135. mv build_assets Xray-${{ env.ASSET_NAME }}
  136. - name: Upload files to Artifacts
  137. uses: actions/upload-artifact@v4
  138. with:
  139. name: Xray-${{ env.ASSET_NAME }}
  140. path: |
  141. ./Xray-${{ env.ASSET_NAME }}/*
  142. - name: Upload binaries to release
  143. uses: svenstaro/upload-release-action@v2
  144. if: github.event_name == 'release'
  145. with:
  146. repo_token: ${{ secrets.GITHUB_TOKEN }}
  147. file: ./Xray-${{ env.ASSET_NAME }}.zip*
  148. tag: ${{ github.ref }}
  149. file_glob: true