notify-discord.yml 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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,htmlUrl,author,publishedAt,tagName)
  31. echo "tag_name=$(echo "$RELEASE_INFO" | jq -r '.tagName')" >> $GITHUB_OUTPUT
  32. echo "name=$(echo "$RELEASE_INFO" | jq -r '.name')" >> $GITHUB_OUTPUT
  33. echo "body=$(echo "$RELEASE_INFO" | jq -r '.body')" >> $GITHUB_OUTPUT
  34. echo "html_url=$(echo "$RELEASE_INFO" | jq -r '.htmlUrl')" >> $GITHUB_OUTPUT
  35. echo "author_login=$(echo "$RELEASE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT
  36. echo "author_html_url=https://github.com/$(echo "$RELEASE_INFO" | jq -r '.author.login')" >> $GITHUB_OUTPUT
  37. echo "published_at=$(echo "$RELEASE_INFO" | jq -r '.publishedAt')" >> $GITHUB_OUTPUT
  38. else
  39. # Pour trigger automatique, utilise les données de l'événement
  40. echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
  41. echo "name=${{ github.event.release.name }}" >> $GITHUB_OUTPUT
  42. echo "body=${{ github.event.release.body }}" >> $GITHUB_OUTPUT
  43. echo "html_url=${{ github.event.release.html_url }}" >> $GITHUB_OUTPUT
  44. echo "author_login=${{ github.event.release.author.login }}" >> $GITHUB_OUTPUT
  45. echo "author_html_url=${{ github.event.release.author.html_url }}" >> $GITHUB_OUTPUT
  46. echo "published_at=${{ github.event.release.published_at }}" >> $GITHUB_OUTPUT
  47. fi
  48. env:
  49. GH_TOKEN: ${{ github.token }}
  50. - name: Get previous release
  51. id: previous-release
  52. run: |
  53. PREV_TAG=$(git tag --sort=-version:refname | grep -v '${{ steps.release-info.outputs.tag_name }}' | head -n1)
  54. echo "previous_tag=${PREV_TAG}" >> $GITHUB_OUTPUT
  55. - name: Get changed files since last release
  56. id: changed-files
  57. uses: tj-actions/changed-files@v44
  58. with:
  59. base_sha: ${{ steps.previous-release.outputs.previous_tag }}
  60. separator: "\n• "
  61. - name: Discord notification
  62. env:
  63. DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
  64. DISCORD_AVATAR: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
  65. DISCORD_EMBEDS: '[{
  66. "title": "🚀 New Release: ${{ steps.release-info.outputs.tag_name }}",
  67. "description": "${{ steps.release-info.outputs.name }}\n\n${{ steps.release-info.outputs.body }}",
  68. "url": "${{ steps.release-info.outputs.html_url }}",
  69. "color": 5763719,
  70. "thumbnail": {
  71. "url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  72. },
  73. "fields": [
  74. { "name": "📦 Version", "value": "`${{ steps.release-info.outputs.tag_name }}`", "inline": true },
  75. { "name": "👤 Released by", "value": "[${{ steps.release-info.outputs.author_login }}](${{ steps.release-info.outputs.author_html_url }})", "inline": true },
  76. { "name": "📁 Repository", "value": "[${{ github.event.repository.name }}](${{ github.event.repository.html_url }})", "inline": true },
  77. { "name": "🔗 Download", "value": "[Release Page](${{ steps.release-info.outputs.html_url }})", "inline": true },
  78. { "name": "📝 Files Changed", "value": "• ${{ steps.changed-files.outputs.all_changed_files }}", "inline": false }
  79. ],
  80. "timestamp": "${{ steps.release-info.outputs.published_at }}",
  81. "footer": {
  82. "text": "Workout Cool • Release",
  83. "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
  84. }
  85. }]'
  86. uses: Ilshidur/action-discord@master
  87. # https://stackoverflow.com/a/68068674/19395252
  88. # https://birdie0.github.io/discord-webhooks-guide/structure/embeds.html
  89. # https://github.com/marketplace/actions/changed-files