notify-discord.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. name: Discord Notification
  2. on:
  3. release:
  4. types: [published]
  5. workflow_dispatch:
  6. inputs:
  7. tag_name:
  8. description: 'Tag name (leave empty for latest release)'
  9. required: false
  10. type: string
  11. jobs:
  12. Discord:
  13. runs-on: ubuntu-latest
  14. name: Discord Notifier
  15. steps:
  16. - uses: actions/checkout@v4
  17. with:
  18. fetch-depth: 0
  19. - name: Get release info
  20. id: release-info
  21. run: |
  22. if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
  23. # Pour trigger manuel, récupère le dernier release ou utilise l'input
  24. if [ -n "${{ github.event.inputs.tag_name }}" ]; then
  25. TAG_NAME="${{ github.event.inputs.tag_name }}"
  26. else
  27. TAG_NAME=$(gh release list --limit 1 --json tagName --jq '.[0].tagName')
  28. fi
  29. # Récupère les infos du release via GitHub CLI
  30. RELEASE_INFO=$(gh release view "$TAG_NAME" --json name,body,url,author,publishedAt,tagName)
  31. # Utilise des délimiteurs pour éviter les problèmes d'échappement
  32. echo "tag_name<<EOF" >> $GITHUB_OUTPUT
  33. echo "$RELEASE_INFO" | jq -r '.tagName' >> $GITHUB_OUTPUT
  34. echo "EOF" >> $GITHUB_OUTPUT
  35. echo "name<<EOF" >> $GITHUB_OUTPUT
  36. echo "$RELEASE_INFO" | jq -r '.name' >> $GITHUB_OUTPUT
  37. echo "EOF" >> $GITHUB_OUTPUT
  38. echo "body<<EOF" >> $GITHUB_OUTPUT
  39. echo "$RELEASE_INFO" | jq -r '.body' >> $GITHUB_OUTPUT
  40. echo "EOF" >> $GITHUB_OUTPUT
  41. echo "html_url<<EOF" >> $GITHUB_OUTPUT
  42. echo "$RELEASE_INFO" | jq -r '.url' >> $GITHUB_OUTPUT
  43. echo "EOF" >> $GITHUB_OUTPUT
  44. echo "author_login<<EOF" >> $GITHUB_OUTPUT
  45. echo "$RELEASE_INFO" | jq -r '.author.login' >> $GITHUB_OUTPUT
  46. echo "EOF" >> $GITHUB_OUTPUT
  47. echo "author_html_url<<EOF" >> $GITHUB_OUTPUT
  48. echo "https://github.com/$(echo "$RELEASE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT
  49. echo "EOF" >> $GITHUB_OUTPUT
  50. echo "published_at<<EOF" >> $GITHUB_OUTPUT
  51. echo "$RELEASE_INFO" | jq -r '.publishedAt' >> $GITHUB_OUTPUT
  52. echo "EOF" >> $GITHUB_OUTPUT
  53. else
  54. # Pour trigger automatique, utilise les données de l'événement
  55. echo "tag_name<<EOF" >> $GITHUB_OUTPUT
  56. echo "${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
  57. echo "EOF" >> $GITHUB_OUTPUT
  58. echo "name<<EOF" >> $GITHUB_OUTPUT
  59. echo "${{ github.event.release.name }}" >> $GITHUB_OUTPUT
  60. echo "EOF" >> $GITHUB_OUTPUT
  61. echo "body<<EOF" >> $GITHUB_OUTPUT
  62. echo "${{ github.event.release.body }}" >> $GITHUB_OUTPUT
  63. echo "EOF" >> $GITHUB_OUTPUT
  64. echo "html_url<<EOF" >> $GITHUB_OUTPUT
  65. echo "${{ github.event.release.html_url }}" >> $GITHUB_OUTPUT
  66. echo "EOF" >> $GITHUB_OUTPUT
  67. echo "author_login<<EOF" >> $GITHUB_OUTPUT
  68. echo "${{ github.event.release.author.login }}" >> $GITHUB_OUTPUT
  69. echo "EOF" >> $GITHUB_OUTPUT
  70. echo "author_html_url<<EOF" >> $GITHUB_OUTPUT
  71. echo "${{ github.event.release.author.html_url }}" >> $GITHUB_OUTPUT
  72. echo "EOF" >> $GITHUB_OUTPUT
  73. echo "published_at<<EOF" >> $GITHUB_OUTPUT
  74. echo "${{ github.event.release.published_at }}" >> $GITHUB_OUTPUT
  75. echo "EOF" >> $GITHUB_OUTPUT
  76. fi
  77. env:
  78. GH_TOKEN: ${{ github.token }}
  79. - name: Get previous release
  80. id: previous-release
  81. run: |
  82. PREV_TAG=$(git tag --sort=-version:refname | grep -v '${{ steps.release-info.outputs.tag_name }}' | head -n1 || echo "")
  83. echo "previous_tag<<EOF" >> $GITHUB_OUTPUT
  84. echo "${PREV_TAG}" >> $GITHUB_OUTPUT
  85. echo "EOF" >> $GITHUB_OUTPUT
  86. - name: Get changed files since last release
  87. id: changed-files
  88. if: steps.previous-release.outputs.previous_tag != ''
  89. uses: tj-actions/changed-files@v44
  90. with:
  91. base_sha: ${{ steps.previous-release.outputs.previous_tag }}
  92. separator: ", "
  93. safe_output: false
  94. - name: Discord notification
  95. env:
  96. DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
  97. DISCORD_AVATAR: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
  98. DISCORD_EMBEDS: '[{
  99. "title": "🚀 New Release: ${{ steps.release-info.outputs.tag_name }}",
  100. "description": "${{ steps.release-info.outputs.name }}\n\n${{ steps.release-info.outputs.body }}",
  101. "url": "${{ steps.release-info.outputs.html_url }}",
  102. "color": 5763719,
  103. "thumbnail": {
  104. "url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  105. },
  106. "fields": [
  107. { "name": "📦 Version", "value": "`${{ steps.release-info.outputs.tag_name }}`", "inline": true },
  108. { "name": "👤 Released by", "value": "[${{ steps.release-info.outputs.author_login }}](${{ steps.release-info.outputs.author_html_url }})", "inline": true },
  109. { "name": "📁 Repository", "value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})", "inline": true },
  110. { "name": "🔗 Download", "value": "[Release Page](${{ steps.release-info.outputs.html_url }})", "inline": true },
  111. { "name": "📝 Files Changed", "value": "${{ steps.changed-files.outputs.all_changed_files || 'No previous release to compare' }}", "inline": false }
  112. ],
  113. "timestamp": "${{ steps.release-info.outputs.published_at }}",
  114. "footer": {
  115. "text": "Workout Cool • Release",
  116. "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  117. }
  118. }]'
  119. uses: Ilshidur/action-discord@master
  120. # https://stackoverflow.com/a/68068674/19395252
  121. # https://birdie0.github.io/discord-webhooks-guide/structure/embeds.html
  122. # https://github.com/marketplace/actions/changed-files