scheduled-assets-update.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. on:
  7. workflow_dispatch:
  8. schedule:
  9. # Update GeoData on every day (22:30 UTC)
  10. - cron: "30 22 * * *"
  11. push:
  12. # Prevent triggering update request storm
  13. paths:
  14. - ".github/workflows/scheduled-assets-update.yml"
  15. pull_request:
  16. # Prevent triggering update request storm
  17. paths:
  18. - ".github/workflows/scheduled-assets-update.yml"
  19. jobs:
  20. geodat:
  21. if: github.event.schedule == '30 22 * * *' || github.event_name == 'push'|| github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
  22. runs-on: ubuntu-latest
  23. steps:
  24. - name: Restore Geodat Cache
  25. uses: actions/cache/restore@v4
  26. with:
  27. path: resources
  28. key: xray-geodat-
  29. - name: Update Geodat
  30. id: update
  31. uses: nick-fields/retry@v3
  32. with:
  33. timeout_minutes: 60
  34. retry_wait_seconds: 60
  35. max_attempts: 60
  36. command: |
  37. [ -d 'resources' ] || mkdir resources
  38. LIST=('Loyalsoldier v2ray-rules-dat geoip geoip' 'Loyalsoldier v2ray-rules-dat geosite geosite')
  39. for i in "${LIST[@]}"
  40. do
  41. INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3,$4}'))
  42. FILE_NAME="${INFO[3]}.dat"
  43. echo -e "Verifying HASH key..."
  44. 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}')"
  45. if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
  46. continue
  47. else
  48. echo -e "Downloading https://raw.githubusercontent.com/${INFO[0]}/${INFO[1]}/release/${INFO[2]}.dat..."
  49. curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://raw.githubusercontent.com/${INFO[0]}/${INFO[1]}/release/${INFO[2]}.dat" -o ./resources/${FILE_NAME}
  50. echo -e "Verifying HASH key..."
  51. [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
  52. echo "unhit=true" >> $GITHUB_OUTPUT
  53. fi
  54. done
  55. - name: Save Geodat Cache
  56. uses: actions/cache/save@v4
  57. if: ${{ steps.update.outputs.unhit }}
  58. with:
  59. path: resources
  60. key: xray-geodat-${{ github.sha }}-${{ github.run_number }}