Skip to content

Commit 2f24137

Browse files
committed
Add versioner summary
1 parent 4498092 commit 2f24137

3 files changed

Lines changed: 180 additions & 1 deletion

File tree

dist/index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34840,9 +34840,79 @@ var __importStar = (this && this.__importStar) || (function () {
3484034840
})();
3484134841
Object.defineProperty(exports, "__esModule", ({ value: true }));
3484234842
const core = __importStar(__nccwpck_require__(7484));
34843+
const fs = __importStar(__nccwpck_require__(9896));
3484334844
const inputs_1 = __nccwpck_require__(8422);
3484434845
const github_context_1 = __nccwpck_require__(8886);
3484534846
const api_client_1 = __nccwpck_require__(7475);
34847+
/**
34848+
* Get the Versioner hostname from API URL
34849+
*/
34850+
function getVersionerHostname(apiUrl) {
34851+
// Convert API URL to UI hostname
34852+
// https://api.versioner.io -> https://app.versioner.io
34853+
// https://development-api.versioner.io -> https://dev.versioner.io
34854+
const url = new URL(apiUrl);
34855+
if (url.hostname === 'api.versioner.io') {
34856+
return 'https://app.versioner.io';
34857+
}
34858+
else if (url.hostname === 'development-api.versioner.io') {
34859+
return 'https://dev.versioner.io';
34860+
}
34861+
// For custom domains, try to infer UI hostname
34862+
return apiUrl.replace('api', 'app');
34863+
}
34864+
/**
34865+
* Get status emoji based on status string
34866+
*/
34867+
function getStatusEmoji(status) {
34868+
switch (status) {
34869+
case 'success':
34870+
return '✅';
34871+
case 'failure':
34872+
return '❌';
34873+
case 'in_progress':
34874+
return '🔄';
34875+
default:
34876+
return '⚠️';
34877+
}
34878+
}
34879+
/**
34880+
* Write summary to GitHub Step Summary
34881+
*/
34882+
function writeSummary(eventType, version, status, scmSha, apiUrl, resourceId, environment) {
34883+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
34884+
if (!summaryPath) {
34885+
core.debug('GITHUB_STEP_SUMMARY not available, skipping summary');
34886+
return;
34887+
}
34888+
const hostname = getVersionerHostname(apiUrl);
34889+
const statusEmoji = getStatusEmoji(status);
34890+
let summary = '## 🚀 Versioner Summary\n\n';
34891+
if (eventType === 'build') {
34892+
const viewUrl = `${hostname}/manage/versions?view=${resourceId}`;
34893+
summary += `**Action:** Build\n\n`;
34894+
summary += `**Status:** ${statusEmoji} ${status}\n\n`;
34895+
summary += `**Version:** \`${version}\`\n\n`;
34896+
summary += `**Git SHA:** \`${scmSha}\`\n\n`;
34897+
summary += `[View in Versioner →](${viewUrl})\n`;
34898+
}
34899+
else {
34900+
const viewUrl = `${hostname}/deployments/${resourceId}`;
34901+
summary += `**Action:** Deployment\n\n`;
34902+
summary += `**Environment:** ${environment}\n\n`;
34903+
summary += `**Status:** ${statusEmoji} ${status}\n\n`;
34904+
summary += `**Version:** \`${version}\`\n\n`;
34905+
summary += `**Git SHA:** \`${scmSha}\`\n\n`;
34906+
summary += `[View in Versioner →](${viewUrl})\n`;
34907+
}
34908+
try {
34909+
fs.appendFileSync(summaryPath, summary);
34910+
core.debug('Summary written to GITHUB_STEP_SUMMARY');
34911+
}
34912+
catch (error) {
34913+
core.warning(`Failed to write summary: ${error instanceof Error ? error.message : String(error)}`);
34914+
}
34915+
}
3484634916
/**
3484734917
* Main action entrypoint
3484834918
*/
@@ -34901,6 +34971,8 @@ async function run() {
3490134971
core.info(` Product ID: ${response.product_id}`);
3490234972
// Create GitHub annotation for visibility
3490334973
core.notice(`Build tracked: ${productName}@${inputs.version} (${inputs.status})`);
34974+
// Write to GitHub Step Summary
34975+
writeSummary('build', inputs.version, inputs.status, githubMetadata.scm_sha, inputs.apiUrl, response.version_id);
3490434976
}
3490534977
else {
3490634978
// Build deployment event payload
@@ -34934,6 +35006,8 @@ async function run() {
3493435006
core.info(` Event ID: ${response.event_id}`);
3493535007
// Create GitHub annotation for visibility
3493635008
core.notice(`Deployment tracked: ${productName}@${inputs.version} → ${inputs.environment} (${inputs.status})`);
35009+
// Write to GitHub Step Summary
35010+
writeSummary('deployment', inputs.version, inputs.status, githubMetadata.scm_sha, inputs.apiUrl, response.deployment_id, inputs.environment);
3493735011
}
3493835012
}
3493935013
catch (error) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,93 @@
11
import * as core from '@actions/core'
2+
import * as fs from 'fs'
23
import { getInputs } from './inputs'
34
import { getGitHubMetadata } from './github-context'
45
import { sendDeploymentEvent, sendBuildEvent } from './api-client'
56
import { DeploymentEventPayload, BuildEventPayload } from './types'
67

8+
/**
9+
* Get the Versioner hostname from API URL
10+
*/
11+
function getVersionerHostname(apiUrl: string): string {
12+
// Convert API URL to UI hostname
13+
// https://api.versioner.io -> https://app.versioner.io
14+
// https://development-api.versioner.io -> https://dev.versioner.io
15+
const url = new URL(apiUrl)
16+
if (url.hostname === 'api.versioner.io') {
17+
return 'https://app.versioner.io'
18+
} else if (url.hostname === 'development-api.versioner.io') {
19+
return 'https://dev.versioner.io'
20+
}
21+
// For custom domains, try to infer UI hostname
22+
return apiUrl.replace('api', 'app')
23+
}
24+
25+
/**
26+
* Get status emoji based on status string
27+
*/
28+
function getStatusEmoji(status: string): string {
29+
switch (status) {
30+
case 'success':
31+
return '✅'
32+
case 'failure':
33+
return '❌'
34+
case 'in_progress':
35+
return '🔄'
36+
default:
37+
return '⚠️'
38+
}
39+
}
40+
41+
/**
42+
* Write summary to GitHub Step Summary
43+
*/
44+
function writeSummary(
45+
eventType: string,
46+
version: string,
47+
status: string,
48+
scmSha: string,
49+
apiUrl: string,
50+
resourceId: string,
51+
environment?: string
52+
): void {
53+
const summaryPath = process.env.GITHUB_STEP_SUMMARY
54+
if (!summaryPath) {
55+
core.debug('GITHUB_STEP_SUMMARY not available, skipping summary')
56+
return
57+
}
58+
59+
const hostname = getVersionerHostname(apiUrl)
60+
const statusEmoji = getStatusEmoji(status)
61+
62+
let summary = '## 🚀 Versioner Summary\n\n'
63+
64+
if (eventType === 'build') {
65+
const viewUrl = `${hostname}/manage/versions?view=${resourceId}`
66+
summary += `**Action:** Build\n\n`
67+
summary += `**Status:** ${statusEmoji} ${status}\n\n`
68+
summary += `**Version:** \`${version}\`\n\n`
69+
summary += `**Git SHA:** \`${scmSha}\`\n\n`
70+
summary += `[View in Versioner →](${viewUrl})\n`
71+
} else {
72+
const viewUrl = `${hostname}/deployments/${resourceId}`
73+
summary += `**Action:** Deployment\n\n`
74+
summary += `**Environment:** ${environment}\n\n`
75+
summary += `**Status:** ${statusEmoji} ${status}\n\n`
76+
summary += `**Version:** \`${version}\`\n\n`
77+
summary += `**Git SHA:** \`${scmSha}\`\n\n`
78+
summary += `[View in Versioner →](${viewUrl})\n`
79+
}
80+
81+
try {
82+
fs.appendFileSync(summaryPath, summary)
83+
core.debug('Summary written to GITHUB_STEP_SUMMARY')
84+
} catch (error) {
85+
core.warning(
86+
`Failed to write summary: ${error instanceof Error ? error.message : String(error)}`
87+
)
88+
}
89+
}
90+
791
/**
892
* Main action entrypoint
993
*/
@@ -76,6 +160,16 @@ async function run(): Promise<void> {
76160

77161
// Create GitHub annotation for visibility
78162
core.notice(`Build tracked: ${productName}@${inputs.version} (${inputs.status})`)
163+
164+
// Write to GitHub Step Summary
165+
writeSummary(
166+
'build',
167+
inputs.version,
168+
inputs.status,
169+
githubMetadata.scm_sha,
170+
inputs.apiUrl,
171+
response.version_id
172+
)
79173
} else {
80174
// Build deployment event payload
81175
const payload: DeploymentEventPayload = {
@@ -119,6 +213,17 @@ async function run(): Promise<void> {
119213
core.notice(
120214
`Deployment tracked: ${productName}@${inputs.version}${inputs.environment} (${inputs.status})`
121215
)
216+
217+
// Write to GitHub Step Summary
218+
writeSummary(
219+
'deployment',
220+
inputs.version,
221+
inputs.status,
222+
githubMetadata.scm_sha,
223+
inputs.apiUrl,
224+
response.deployment_id,
225+
inputs.environment
226+
)
122227
}
123228
} catch (error) {
124229
// Handle errors and fail the action

0 commit comments

Comments
 (0)