diff --git a/build b/build
index d768a70e..9b231411 100755
--- a/build
+++ b/build
@@ -5,7 +5,7 @@ cd sources
case "$1" in
all)
npm clean-install
- nprm run all
+ npm run all
;;
act)
# Build and copy outputs to the dist directory
@@ -26,4 +26,4 @@ case "$1" in
npm install
npm run build
;;
-esac
\ No newline at end of file
+esac
diff --git a/sources/src/job-summary.ts b/sources/src/job-summary.ts
index ec3a69e5..afaefffd 100644
--- a/sources/src/job-summary.ts
+++ b/sources/src/job-summary.ts
@@ -78,7 +78,7 @@ Note that this permission is never available for a workflow triggered from a rep
return mainWarning
}
-function renderSummaryTable(results: BuildResult[]): string {
+export function renderSummaryTable(results: BuildResult[]): string {
return `${renderDeprecations()}\n${renderBuildResults(results)}`
}
@@ -113,7 +113,7 @@ function renderBuildResults(results: BuildResult[]): string {
Requested Tasks |
Gradle Version |
Build Outcome |
- Build Scan® |
+ Build Scan® |
${results.map(result => renderBuildResultRow(result)).join('')}
`
@@ -134,23 +134,46 @@ function renderOutcome(result: BuildResult): string {
return result.buildFailed ? ':x:' : ':white_check_mark:'
}
+interface BadgeSpec {
+ text: string
+ alt: string
+ color: string
+ logo: boolean
+ targetUrl: string
+}
+
function renderBuildScan(result: BuildResult): string {
if (result.buildScanFailed) {
- return renderBuildScanBadge(
- 'PUBLISH_FAILED',
- 'orange',
- 'https://docs.gradle.com/develocity/gradle-plugin/#troubleshooting'
- )
+ return renderBuildScanBadge({
+ text: 'Publish failed',
+ alt: 'Build Scan publish failed',
+ color: 'orange',
+ logo: false,
+ targetUrl: 'https://docs.gradle.com/develocity/gradle-plugin/#troubleshooting'
+ })
}
if (result.buildScanUri) {
- return renderBuildScanBadge('PUBLISHED', '06A0CE', result.buildScanUri)
+ return renderBuildScanBadge({
+ text: 'Build Scan®',
+ alt: 'Build Scan published',
+ color: '06A0CE',
+ logo: true,
+ targetUrl: result.buildScanUri
+ })
}
- return renderBuildScanBadge('NOT_PUBLISHED', 'lightgrey', 'https://scans.gradle.com')
+ return renderBuildScanBadge({
+ text: 'Not published',
+ alt: 'Build Scan not published',
+ color: 'lightgrey',
+ logo: false,
+ targetUrl: 'https://scans.gradle.com'
+ })
}
-function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetUrl: string): string {
- const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle`
- const badgeHtml = ``
+function renderBuildScanBadge({text, alt, color, logo, targetUrl}: BadgeSpec): string {
+ const encodedText = encodeURIComponent(text)
+ const badgeUrl = `https://img.shields.io/badge/${encodedText}-${color}${logo ? '?logo=Gradle' : ''}`
+ const badgeHtml = ``
return `${badgeHtml}`
}
diff --git a/sources/test/jest/job-summary.test.ts b/sources/test/jest/job-summary.test.ts
new file mode 100644
index 00000000..91cffa24
--- /dev/null
+++ b/sources/test/jest/job-summary.test.ts
@@ -0,0 +1,177 @@
+import { BuildResult } from '../../src/build-results'
+import { renderSummaryTable } from '../../src/job-summary'
+import dedent from 'dedent'
+
+
+const successfulHelpBuild: BuildResult = {
+ rootProjectName: 'root',
+ rootProjectDir: '/',
+ requestedTasks: 'help',
+ gradleVersion: '8.0',
+ gradleHomeDir: '/opt/gradle',
+ buildFailed: false,
+ buildScanUri: 'https://scans.gradle.com/s/abc123',
+ buildScanFailed: false
+}
+
+const failedHelpBuild: BuildResult = {
+ ...successfulHelpBuild,
+ buildFailed: true
+}
+
+const longArgsBuild: BuildResult = {
+ ...successfulHelpBuild,
+ requestedTasks: 'check publishMyLongNamePluginPublicationToMavenCentral publishMyLongNamePluginPublicationToPluginPortal',
+}
+
+const scanPublishDisabledBuild: BuildResult = {
+ ...successfulHelpBuild,
+ buildScanUri: '',
+ buildScanFailed: false,
+}
+
+const scanPublishFailedBuild: BuildResult = {
+ ...successfulHelpBuild,
+ buildScanUri: '',
+ buildScanFailed: true,
+}
+
+describe('renderSummaryTable', () => {
+ describe('renders', () => {
+ it('successful build', () => {
+ const table = renderSummaryTable([successfulHelpBuild])
+ expect(table.trim()).toBe(dedent`
+
+
+ Gradle Root Project |
+ Requested Tasks |
+ Gradle Version |
+ Build Outcome |
+ Build Scan® |
+
+
+ root |
+ help |
+ 8.0 |
+ :white_check_mark: |
+ |
+
+
+ `);
+ })
+ it('failed build', () => {
+ const table = renderSummaryTable([failedHelpBuild])
+ expect(table.trim()).toBe(dedent`
+
+
+ Gradle Root Project |
+ Requested Tasks |
+ Gradle Version |
+ Build Outcome |
+ Build Scan® |
+
+
+ root |
+ help |
+ 8.0 |
+ :x: |
+ |
+
+
+ `);
+ })
+ describe('when build scan', () => {
+ it('publishing disabled', () => {
+ const table = renderSummaryTable([scanPublishDisabledBuild])
+ expect(table.trim()).toBe(dedent`
+
+
+ Gradle Root Project |
+ Requested Tasks |
+ Gradle Version |
+ Build Outcome |
+ Build Scan® |
+
+
+ root |
+ help |
+ 8.0 |
+ :white_check_mark: |
+ |
+
+
+ `);
+ })
+ it('publishing failed', () => {
+ const table = renderSummaryTable([scanPublishFailedBuild])
+ expect(table.trim()).toBe(dedent`
+
+
+ Gradle Root Project |
+ Requested Tasks |
+ Gradle Version |
+ Build Outcome |
+ Build Scan® |
+
+
+ root |
+ help |
+ 8.0 |
+ :white_check_mark: |
+ |
+
+
+ `);
+ })
+ })
+ it('multiple builds', () => {
+ const table = renderSummaryTable([successfulHelpBuild, failedHelpBuild])
+ expect(table.trim()).toBe(dedent`
+
+
+ Gradle Root Project |
+ Requested Tasks |
+ Gradle Version |
+ Build Outcome |
+ Build Scan® |
+
+
+ root |
+ help |
+ 8.0 |
+ :white_check_mark: |
+ |
+
+
+ root |
+ help |
+ 8.0 |
+ :x: |
+ |
+
+
+ `);
+ })
+ it('truncating long requested tasks', () => {
+ const table = renderSummaryTable([longArgsBuild])
+ expect(table.trim()).toBe(dedent`
+
+
+ Gradle Root Project |
+ Requested Tasks |
+ Gradle Version |
+ Build Outcome |
+ Build Scan® |
+
+
+ root |
+ check publishMyLongNamePluginPublicationToMavenCentral publ… |
+ 8.0 |
+ :white_check_mark: |
+ |
+
+
+ `);
+ })
+ })
+})