scheduled-assets-update.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. name: Scheduled assets update
  2. # NOTE: This Github Actions is required by other actions, for preparing other packaging assets in a
  3. # routine manner, for example: GeoIP/GeoSite.
  4. # Currently updating:
  5. # - Geodat (GeoIP/Geosite)
  6. # - Wintun (wintun.dll)
  7. on:
  8. workflow_dispatch:
  9. schedule:
  10. # Update GeoData on every day (22:30 UTC)
  11. - cron: "30 22 * * *"
  12. push:
  13. # Prevent triggering update request storm
  14. paths:
  15. - ".github/workflows/scheduled-assets-update.yml"
  16. pull_request:
  17. # Prevent triggering update request storm
  18. paths:
  19. - ".github/workflows/scheduled-assets-update.yml"
  20. jobs:
  21. geodat:
  22. if: github.event.schedule == '30 22 * * *' || github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Restore Geodat Cache
  26. uses: actions/cache/restore@v5
  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=('Loyalsoldier v2ray-rules-dat geoip geoip' 'Loyalsoldier v2ray-rules-dat geosite geosite')
  40. for i in "${LIST[@]}"
  41. do
  42. INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3,$4}'))
  43. FILE_NAME="${INFO[3]}.dat"
  44. echo -e "Verifying HASH key..."
  45. HASH="$(curl -sL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://raw.githubusercontent.com/${INFO[0]}/${INFO[1]}/release/${INFO[2]}.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/${INFO[0]}/${INFO[1]}/release/${INFO[2]}.dat..."
  50. curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://raw.githubusercontent.com/${INFO[0]}/${INFO[1]}/release/${INFO[2]}.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 Geodat Cache
  57. uses: actions/cache/save@v5
  58. if: ${{ steps.update.outputs.unhit }}
  59. with:
  60. path: resources
  61. key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
  62. wintun:
  63. if: github.event.schedule == '30 22 * * *' || github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
  64. runs-on: ubuntu-latest
  65. steps:
  66. - name: Restore Wintun Cache
  67. uses: actions/cache/restore@v5
  68. with:
  69. path: resources
  70. key: xray-wintun-
  71. - name: Force downloading if run manually or on file update
  72. if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
  73. run: |
  74. echo "FORCE_UPDATE=true" >> $GITHUB_ENV
  75. - name: Update Wintun
  76. id: update
  77. uses: nick-fields/retry@v3
  78. with:
  79. timeout_minutes: 60
  80. retry_wait_seconds: 60
  81. max_attempts: 60
  82. command: |
  83. [ -d 'resources' ] || mkdir resources
  84. LIST=('amd64' 'x86' 'arm64' 'arm')
  85. for ARCHITECTURE in "${LIST[@]}"
  86. do
  87. FILE_PATH="resources/wintun/bin/${ARCHITECTURE}/wintun.dll"
  88. echo -e "Checking if wintun.dll for ${ARCHITECTURE} exists..."
  89. if [ -s "./resources/wintun/bin/${ARCHITECTURE}/wintun.dll" ]; then
  90. echo -e "wintun.dll for ${ARCHITECTURE} exists"
  91. continue
  92. else
  93. echo -e "wintun.dll for ${ARCHITECTURE} is missing"
  94. missing=true
  95. fi
  96. done
  97. if [ -s "./resources/wintun/LICENSE.txt" ]; then
  98. echo -e "LICENSE for Wintun exists"
  99. else
  100. echo -e "LICENSE for Wintun is missing"
  101. missing=true
  102. fi
  103. if [[ -v FORCE_UPDATE ]]; then
  104. missing=true
  105. fi
  106. if [[ "$missing" == true ]]; then
  107. FILENAME=wintun.zip
  108. DOWNLOAD_FILE=wintun-0.14.1.zip
  109. echo -e "Downloading https://www.wintun.net/builds/${DOWNLOAD_FILE}..."
  110. curl -L "https://www.wintun.net/builds/${DOWNLOAD_FILE}" -o "${FILENAME}"
  111. echo -e "Unpacking wintun..."
  112. unzip -u ${FILENAME} -d resources/
  113. echo "unhit=true" >> $GITHUB_OUTPUT
  114. fi
  115. - name: Save Wintun Cache
  116. uses: actions/cache/save@v5
  117. if: ${{ steps.update.outputs.unhit }}
  118. with:
  119. path: resources
  120. key: xray-wintun-${{ github.sha }}-${{ github.run_number }}