@@ -7,8 +7,9 @@ import * as core from '@actions/core';
77import * as exec from '@actions/exec' ;
88import * as path from 'path' ;
99
10+ import { PublishResult } from './contracts/collection' ;
1011import { generateFeaturesDocumentation , generateTemplateDocumentation } from './generateDocs' ;
11- import { ensureDevcontainerCliPresent , getGitHubMetadata , readdirLocal , validateFeatureSchema } from './utils' ;
12+ import { addRepoTagForPublishedTag , ensureDevcontainerCliPresent , getGitHubMetadata , readdirLocal , validateFeatureSchema } from './utils' ;
1213
1314async function run ( ) : Promise < void > {
1415 core . debug ( 'Reading input parameters...' ) ;
@@ -44,6 +45,8 @@ async function run(): Promise<void> {
4445 const disableSchemaValidationAsError = core . getInput ( 'disable-schema-validation' ) . toLowerCase ( ) === 'true' ;
4546 const validateOnly = core . getInput ( 'validate-only' ) . toLowerCase ( ) === 'true' ;
4647
48+ const disableRepoTagging = core . getInput ( 'disable-repo-tagging' ) . toLowerCase ( ) === 'true' ;
49+
4750 // -- Publish
4851
4952 if ( shouldPublishFeatures && shouldPublishTemplates ) {
@@ -75,30 +78,60 @@ async function run(): Promise<void> {
7578 }
7679
7780 if ( shouldPublishFeatures ) {
78- core . info ( 'Publishing features...' ) ;
79- if ( ! ( await publish ( 'feature' , featuresBasePath , featuresOciRegistry , featuresNamespace , cliDebugMode ) ) ) {
80- core . setFailed ( '(!) Failed to publish features.' ) ;
81+ core . info ( 'Publishing Features...' ) ;
82+ const publishedFeatures = await publish ( 'feature' , featuresBasePath , featuresOciRegistry , featuresNamespace , cliDebugMode ) ;
83+ if ( ! publishedFeatures ) {
84+ core . setFailed ( '(!) Failed to publish Features.' ) ;
8185 return ;
8286 }
87+
88+ // Add repo tag for this version at the current commit.
89+ if ( ! disableRepoTagging ) {
90+ for ( const featureId in publishedFeatures ) {
91+ const version = publishedFeatures [ featureId ] ?. version ;
92+ if ( ! version ) {
93+ core . debug ( `No version available for '${ featureId } ', so no repo tag was added for Feature` ) ;
94+ continue ;
95+ }
96+ if ( ! ( await addRepoTagForPublishedTag ( 'feature' , featureId , version ) ) ) {
97+ continue ;
98+ }
99+ }
100+ }
83101 }
84102
85103 if ( shouldPublishTemplates ) {
86- core . info ( 'Publishing templates...' ) ;
87- if ( ! ( await publish ( 'template' , templatesBasePath , templatesOciRegistry , templatesNamespace , cliDebugMode ) ) ) {
88- core . setFailed ( '(!) Failed to publish templates.' ) ;
104+ core . info ( 'Publishing Templates...' ) ;
105+ const publishedTemplates = await publish ( 'template' , templatesBasePath , templatesOciRegistry , templatesNamespace , cliDebugMode ) ;
106+ if ( ! publishedTemplates ) {
107+ core . setFailed ( '(!) Failed to publish Templates.' ) ;
89108 return ;
90109 }
110+
111+ // Add repo tag for this version at the current commit.
112+ if ( ! disableRepoTagging ) {
113+ for ( const templateId in publishedTemplates ) {
114+ const version = publishedTemplates [ templateId ] ?. version ;
115+ if ( ! version ) {
116+ core . debug ( `No version available for '${ templateId } ', so no repo tag was added for Feature` ) ;
117+ continue ;
118+ }
119+ if ( ! ( await addRepoTagForPublishedTag ( 'template' , templateId , version ) ) ) {
120+ continue ;
121+ }
122+ }
123+ }
91124 }
92125
93126 // -- Generate Documentation
94127
95128 if ( shouldGenerateDocumentation && featuresBasePath ) {
96- core . info ( 'Generating documentation for features ...' ) ;
129+ core . info ( 'Generating documentation for Features ...' ) ;
97130 await generateFeaturesDocumentation ( featuresBasePath , featuresOciRegistry , featuresNamespace ) ;
98131 }
99132
100133 if ( shouldGenerateDocumentation && templatesBasePath ) {
101- core . info ( 'Generating documentation for templates ...' ) ;
134+ core . info ( 'Generating documentation for Templates ...' ) ;
102135 await generateTemplateDocumentation ( templatesBasePath ) ;
103136 }
104137}
@@ -128,11 +161,11 @@ async function publish(
128161 ociRegistry : string ,
129162 namespace : string ,
130163 cliDebugMode = false
131- ) : Promise < boolean > {
164+ ) : Promise < { [ featureId : string ] : PublishResult } | undefined > {
132165 // Ensures we have the devcontainer CLI installed.
133166 if ( ! ( await ensureDevcontainerCliPresent ( cliDebugMode ) ) ) {
134167 core . setFailed ( 'Failed to install devcontainer CLI' ) ;
135- return false ;
168+ return ;
136169 }
137170
138171 try {
@@ -145,10 +178,11 @@ async function publish(
145178
146179 // Fails on non-zero exit code from the invoked process
147180 const res = await exec . getExecOutput ( cmd , args , { } ) ;
148- return res . exitCode === 0 ;
181+ const result : { [ featureId : string ] : PublishResult } = JSON . parse ( res . stdout ) ;
182+ return result ;
149183 } catch ( err : any ) {
150184 core . setFailed ( err ?. message ) ;
151- return false ;
185+ return ;
152186 }
153187}
154188
0 commit comments