# Discord Webhook Notification # Sends a success or failure embed to a Discord channel # # Usage: # - uses: cal/gitea-actions/discord-notify@main # if: always() # with: # webhook_url: ${{ secrets.DISCORD_WEBHOOK }} # title: My App # status: ${{ job.status }} name: Discord Notification description: Send a build notification embed to Discord inputs: webhook_url: description: Discord webhook URL required: true title: description: Embed title (e.g., "Paper Dynasty Bot") required: true status: description: Build status - "success" or "failure" required: false default: success version: description: CalVer version string required: false default: "" image_tag: description: Docker image tag (version-sha) required: false default: "" commit_sha: description: Short commit SHA required: false default: "" author: description: Commit author required: false default: ${{ github.actor }} run_url: description: URL to the Actions run required: false default: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} branch: description: Branch name required: false default: ${{ github.ref_name }} timestamp: description: ISO 8601 timestamp required: false default: "" runs: using: composite steps: - name: Send Discord notification shell: bash run: | if [ "${{ inputs.status }}" = "success" ]; then COLOR=3066993 DESCRIPTION="Docker image built and pushed to Docker Hub" LINK_LABEL="View Run" # Build fields JSON for success FIELDS='[ {"name": "Version", "value": "`${{ inputs.version }}`", "inline": true}, {"name": "Image Tag", "value": "`${{ inputs.image_tag }}`", "inline": true}, {"name": "Commit", "value": "`${{ inputs.commit_sha }}`", "inline": true}, {"name": "Author", "value": "${{ inputs.author }}", "inline": true}, {"name": "'"$LINK_LABEL"'", "value": "[Click here](${{ inputs.run_url }})", "inline": false} ]' else COLOR=15158332 DESCRIPTION="Docker build encountered an error." LINK_LABEL="View Logs" # Build fields JSON for failure FIELDS='[ {"name": "Branch", "value": "`${{ inputs.branch }}`", "inline": true}, {"name": "Commit", "value": "`'"$GITHUB_SHA"'`", "inline": true}, {"name": "Author", "value": "${{ inputs.author }}", "inline": true}, {"name": "'"$LINK_LABEL"'", "value": "[Click here](${{ inputs.run_url }})", "inline": false} ]' fi # Use provided timestamp or generate one TS="${{ inputs.timestamp }}" if [ -z "$TS" ]; then TS=$(date -u +%Y-%m-%dT%H:%M:%SZ) fi # Send the webhook curl -s -H "Content-Type: application/json" \ -d "{ \"embeds\": [{ \"title\": \"${{ inputs.title }} - Build $([ '${{ inputs.status }}' = 'success' ] && echo 'Successful' || echo 'Failed')\", \"description\": \"${DESCRIPTION}\", \"color\": ${COLOR}, \"fields\": ${FIELDS}, \"timestamp\": \"${TS}\" }] }" \ "${{ inputs.webhook_url }}"