@@ -126,11 +126,15 @@ jobs:
126126 needs :
127127 - check-nuget
128128 - build
129+ # Allow this job to run even if build is skipped
130+ if : always() && needs.check-nuget.result == 'success'
129131 runs-on : ubuntu-latest
130132
131133 steps :
132134 - name : Get artifact ID for nupkgs
133135 id : get_artifact
136+ # Only try to get artifact if build actually ran
137+ if : needs.build.result == 'success'
134138 run : |
135139 artifacts=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts)
136140 id=$(echo "$artifacts" | jq '.artifacts[] | select(.name=="nupkgs") | .id')
@@ -139,6 +143,8 @@ jobs:
139143 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
140144
141145 - name : Trigger publish.yml with artifact ID
146+ # Only trigger publish if build succeeded and created artifact
147+ if : needs.build.result == 'success'
142148 uses : actions/github-script@v7
143149 env :
144150 GH_PAT : ${{ secrets.PAT_TOKEN }}
@@ -168,3 +174,71 @@ jobs:
168174 } else {
169175 console.log(`✅ Successfully triggered publish with artifact ID: ${artifactId}`);
170176 }
177+
178+ - name : Send Discord Notification
179+ if : always()
180+ run : |
181+ # Safely handle the commit message
182+ REPO_NAME="${GITHUB_REPOSITORY#*/}"
183+ BRANCH="${GITHUB_REF#refs/heads/}"
184+
185+ if [[ "${{ github.event.head_commit.message }}" =~ ^Merge\ pull\ request ]]; then
186+ PR_BRANCH=$(echo "${{ github.event.head_commit.message }}" | sed -n "s/Merge pull request #[0-9]\+ from [^/]*\/\(.*\)/\1/p")
187+ MESSAGE="📦 *${REPO_NAME}* | Branch: \`${BRANCH}\` | Merged from: \`${PR_BRANCH}\`"
188+ else
189+ # Use a shortened commit message to avoid issues
190+ SHORT_MSG=$(echo "${{ github.event.head_commit.message }}" | head -n1)
191+ MESSAGE="📦 *${REPO_NAME}* | Branch: \`${BRANCH}\` | Commit: \`${SHORT_MSG}\`"
192+ fi
193+
194+ # Determine status based on check-nuget and build results
195+ if [ "${{ needs.check-nuget.result }}" != "success" ]; then
196+ STATUS_EMOJI="❌"
197+ STATUS_TEXT="Failed"
198+ COLOR="15158332"
199+ elif [ "${{ needs.build.result }}" == "skipped" ]; then
200+ STATUS_EMOJI="⏭️"
201+ STATUS_TEXT="Skipped (Packages already exist)"
202+ COLOR="16776960"
203+ elif [ "${{ needs.build.result }}" != "success" ]; then
204+ STATUS_EMOJI="❌"
205+ STATUS_TEXT="Build Failed"
206+ COLOR="15158332"
207+ else
208+ STATUS_EMOJI="✅"
209+ STATUS_TEXT="Successful"
210+ COLOR="3066993"
211+ fi
212+
213+ # Create a proper JSON payload in a separate file
214+ cat > payload.json << EOF
215+ {
216+ "embeds": [
217+ {
218+ "title": "${STATUS_EMOJI} TickerQ Deployment ${STATUS_TEXT}",
219+ "description": "${MESSAGE}",
220+ "color": ${COLOR},
221+ "fields": [
222+ {
223+ "name": "Version",
224+ "value": "${{ needs.check-nuget.outputs.version }}",
225+ "inline": true
226+ },
227+ {
228+ "name": "Build Status",
229+ "value": "${{ needs.build.result }}",
230+ "inline": true
231+ }
232+ ],
233+ "footer": {
234+ "text": "Deployed on $(date +'%Y-%m-%d %H:%M UTC')"
235+ }
236+ }
237+ ]
238+ }
239+ EOF
240+
241+ # Send with the file as payload
242+ curl -H "Content-Type: application/json" \
243+ -X POST "${{ secrets.DISCORD_WEBHOOK }}" \
244+ --data @payload.json
0 commit comments