action.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. name: 'Telegram Notification'
  2. description: 'Send Telegram notifications for kernel builds'
  3. inputs:
  4. release_type:
  5. description: 'Type of release (Actions, Pre-Release, Release)'
  6. required: true
  7. new_tag:
  8. description: 'New release tag'
  9. required: false
  10. default: ''
  11. release_result:
  12. description: 'Result of the release job'
  13. required: false
  14. default: 'success'
  15. telegram_bot_token:
  16. description: 'Telegram bot token'
  17. required: true
  18. telegram_chat_id:
  19. description: 'Telegram chat ID for announcements'
  20. required: true
  21. telegram_topic_id:
  22. description: 'Telegram topic/thread ID'
  23. required: true
  24. telegram_user_id:
  25. description: 'Telegram user ID for direct messages'
  26. required: true
  27. artifact_pattern:
  28. description: 'Pattern for artifacts to download'
  29. required: false
  30. default: '*-TheWildJames-AnyKernel3'
  31. runs:
  32. using: "composite"
  33. steps:
  34. - name: Download Kernel Artifacts
  35. uses: actions/download-artifact@v5
  36. with:
  37. path: ./downloaded-artifacts
  38. pattern: ${{ inputs.artifact_pattern }}
  39. - name: Prepare Artifact Zips
  40. shell: bash
  41. run: |
  42. shopt -s nullglob
  43. # Iterate over directories in downloaded-artifacts
  44. for dir in ./downloaded-artifacts/*-AnyKernel3; do
  45. [ -d "$dir" ] || continue
  46. artifact_name=$(basename "$dir")
  47. # Create zip for each artifact
  48. (cd "$dir" && zip -r -q -9 "$GITHUB_WORKSPACE/${artifact_name}.zip" ./*)
  49. done
  50. - name: Send Telegram Notification (Actions)
  51. if: ${{ inputs.release_type == 'Actions' }}
  52. shell: bash
  53. run: |
  54. curl -X POST "https://api.telegram.org/bot${{ inputs.telegram_bot_token }}/sendMessage" \
  55. -F chat_id="${{ inputs.telegram_chat_id }}" \
  56. -F message_thread_id="${{ inputs.telegram_topic_id }}" \
  57. -F text="
  58. 🌽 *New Kernel Actions Build Finished*
  59. 📦 *Repository:* [${{ github.repository }}](https://github.com/${{ github.repository }})
  60. ✏️ *Commit:* [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
  61. [🔗 View Action Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" \
  62. -F parse_mode="Markdown"
  63. - name: Send Telegram Notification (Release)
  64. if: ${{ inputs.release_type != 'Actions' && inputs.release_result == 'success' }}
  65. shell: bash
  66. run: |
  67. RELEASE_TYPE_TEXT=""
  68. if [ "${{ inputs.release_type }}" == "Pre-Release" ]; then
  69. RELEASE_TYPE_TEXT="🧪 *Pre-Release*"
  70. else
  71. RELEASE_TYPE_TEXT="🚀 *Release*"
  72. fi
  73. curl -X POST "https://api.telegram.org/bot${{ inputs.telegram_bot_token }}/sendMessage" \
  74. -F chat_id="${{ inputs.telegram_chat_id }}" \
  75. -F message_thread_id="${{ inputs.telegram_topic_id }}" \
  76. -F text="
  77. 🌽 *New Kernel $RELEASE_TYPE_TEXT Uploaded*
  78. 📦 *Repository:* [${{ github.repository }}](https://github.com/${{ github.repository }})
  79. ✏️ *Commit:* [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
  80. [🔗 View GitHub Release](https://github.com/${{ github.repository }}/releases/tag/${{ inputs.new_tag }})" \
  81. -F parse_mode="Markdown"
  82. - name: Send Direct Message with Artifacts
  83. if: always()
  84. shell: bash
  85. run: |
  86. shopt -s nullglob
  87. files=("$GITHUB_WORKSPACE"/*.zip)
  88. if [ ${#files[@]} -eq 0 ]; then
  89. echo "No ZIP files found for DM."
  90. exit 0
  91. fi
  92. if [ -z "${{ inputs.telegram_user_id }}" ]; then
  93. echo "Error: telegram_user_id is not set."
  94. exit 1
  95. fi
  96. for file in "${files[@]}"; do
  97. # Send each zip to Telegram DM
  98. # Using || true to prevent failure of one send from failing the whole action
  99. curl -v -F chat_id="${{ inputs.telegram_user_id }}" \
  100. -F document=@"$file" \
  101. -F caption="📦 Build: $(basename "$file")" \
  102. https://api.telegram.org/bot${{ inputs.telegram_bot_token }}/sendDocument || true
  103. done