@@ -63,5 +63,124 @@ jobs:
6363 user : ${{ secrets.NUGET_USER }}
6464
6565 - name : Publish to NuGet
66+ id : publish_step
6667 if : steps.version-check.outputs.exists == 'false'
6768 run : dotnet nuget push ./nupkg/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
69+
70+ - name : Notify Slack (success)
71+ if : steps.version-check.outputs.exists == 'false' && steps.publish_step.outcome == 'success'
72+ env :
73+ SLACK_DEPLOY_WEBHOOK_URL : ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }}
74+ VERSION : ${{ steps.version-check.outputs.version }}
75+ shell : bash
76+ run : |
77+ set -euo pipefail
78+ if [ -z "${SLACK_DEPLOY_WEBHOOK_URL:-}" ]; then
79+ echo "SLACK_DEPLOY_WEBHOOK_URL not set; skipping Slack notification"
80+ exit 0
81+ fi
82+
83+ node <<'JS'
84+ const fs = require('node:fs');
85+
86+ const version = process.env.VERSION;
87+ let latestChanges = 'See CHANGELOG for details.';
88+
89+ if (fs.existsSync('CHANGELOG.md')) {
90+ const lines = fs.readFileSync('CHANGELOG.md', 'utf8').split(/\r?\n/);
91+ const bullets = [];
92+ let inTargetSection = false;
93+ for (const line of lines) {
94+ if (line.startsWith(`## [${version}]`)) {
95+ inTargetSection = true;
96+ continue;
97+ }
98+ if (inTargetSection && line.startsWith('## [')) break;
99+ if (inTargetSection && line.startsWith('- ')) {
100+ bullets.push(line.slice(2).trim());
101+ }
102+ }
103+ if (bullets.length) {
104+ latestChanges = bullets.slice(0, 5).map((bullet) => `• ${bullet}`).join('\n');
105+ }
106+ }
107+
108+ fs.writeFileSync('/tmp/slack_payload.json', JSON.stringify({
109+ text: `Facturapi .NET SDK ${version} published to NuGet`,
110+ blocks: [
111+ {
112+ type: 'header',
113+ text: {
114+ type: 'plain_text',
115+ text: `.NET SDK ${version} published to NuGet`,
116+ },
117+ },
118+ {
119+ type: 'section',
120+ fields: [
121+ { type: 'mrkdwn', text: `*Package:* \`Facturapi ${version}\`` },
122+ { type: 'mrkdwn', text: `*Branch:* \`${process.env.GITHUB_REF_NAME}\`` },
123+ { type: 'mrkdwn', text: `*Commit:* \`${process.env.GITHUB_SHA}\`` },
124+ { type: 'mrkdwn', text: `*Actor:* \`${process.env.GITHUB_ACTOR}\`` },
125+ ],
126+ },
127+ {
128+ type: 'section',
129+ text: {
130+ type: 'mrkdwn',
131+ text: [
132+ '*Useful links*',
133+ `• NuGet: <https://www.nuget.org/packages/Facturapi/${version}|View package>`,
134+ `• Workflow run: <${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}|Open run>`,
135+ `• Changelog: <${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA}/CHANGELOG.md|Read changes>`,
136+ ].join('\n'),
137+ },
138+ },
139+ {
140+ type: 'section',
141+ text: {
142+ type: 'mrkdwn',
143+ text: `*Latest changes*\n${latestChanges}`,
144+ },
145+ },
146+ ],
147+ }));
148+ JS
149+
150+ curl -sS -X POST -H "Content-type: application/json" --data "@/tmp/slack_payload.json" "$SLACK_DEPLOY_WEBHOOK_URL" || true
151+
152+ - name : Notify Slack (failure)
153+ if : failure() && steps.version-check.outputs.exists == 'false' && steps.publish_step.outcome == 'failure'
154+ env :
155+ SLACK_DEPLOY_WEBHOOK_URL : ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }}
156+ VERSION : ${{ steps.version-check.outputs.version }}
157+ shell : bash
158+ run : |
159+ set -euo pipefail
160+ if [ -z "${SLACK_DEPLOY_WEBHOOK_URL:-}" ]; then
161+ echo "SLACK_DEPLOY_WEBHOOK_URL not set; skipping Slack notification"
162+ exit 0
163+ fi
164+
165+ node <<'JS'
166+ const fs = require('node:fs');
167+
168+ fs.writeFileSync('/tmp/slack_payload_failure.json', JSON.stringify({
169+ text: `Facturapi .NET SDK ${process.env.VERSION} publish failed`,
170+ blocks: [
171+ {
172+ type: 'section',
173+ text: {
174+ type: 'mrkdwn',
175+ text: [
176+ `*.NET SDK ${process.env.VERSION} publish failed*`,
177+ `• Workflow run: <${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}|Open run>`,
178+ `• Commit: \`${process.env.GITHUB_SHA}\``,
179+ ].join('\n'),
180+ },
181+ },
182+ ],
183+ }));
184+ JS
185+
186+ curl -sS -X POST -H "Content-type: application/json" --data "@/tmp/slack_payload_failure.json" "$SLACK_DEPLOY_WEBHOOK_URL" || true
0 commit comments