1- import { getInput , setFailed , info , error , warning , setOutput } from '@actions/core'
1+ import { getInput , setFailed , info , error , warning , setOutput , startGroup , endGroup } from '@actions/core'
22import axios from 'axios'
33import { readFileSync } from 'fs'
44import { join , normalize } from 'path'
@@ -16,6 +16,7 @@ let packageFileURL = (getInput('file-url') || '').trim()
1616const allowedTags = [ '::before' ]
1717
1818type outputKey = 'changed' | 'type' | 'version' | 'commit'
19+ const outputs : Partial < Record < outputKey , string | boolean > > = { }
1920
2021// #region Functions
2122async function main ( ) {
@@ -32,25 +33,25 @@ async function main() {
3233 const { before, repository } = event
3334 if ( before && repository ) {
3435 packageFileURL = `https://raw.githubusercontent.com/${ repository ?. full_name } /${ before } /${ packageFileName } `
35- info ( '::group:: URL tag resolution...')
36+ startGroup ( ' URL tag resolution...')
3637 info ( `::before tag resolved to ${ repository ?. full_name } /${ String ( before ) . substr ( 0 , 7 ) } /${ packageFileName } ` )
3738 info ( `Current package file URL: ${ packageFileURL } ` )
3839 info ( `Using token for remote url: ${ ! ! token } ` )
39- info ( '::endgroup::' )
40+ endGroup ( )
4041 } else
4142 throw new Error ( `Can't correctly read event file (before: ${ before } , repository: ${ repository } )` )
4243 }
4344
4445 if ( staticChecking ) {
4546 if ( ! packageFileURL ) return setFailed ( 'Static checking cannot be performed without a `file-url` argument.' )
4647
47- info ( '::group:: Static-checking files...')
48+ startGroup ( ' Static-checking files...')
4849 info ( `Package file name: "${ packageFileName } "` )
4950 info ( `Package file URL: "${ packageFileURL } "` )
5051 const local : string = ( await readJson ( join ( dir , packageFileName ) ) ) ?. version ,
5152 remote : string = ( await readJson ( packageFileURL , isPackageFileURLBefore && token ? token : undefined ) ) ?. version
5253 if ( ! local || ! remote ) {
53- info ( '::endgroup::' )
54+ endGroup ( )
5455 return setFailed ( `Couldn't find ${ local ? 'local' : 'remote' } version.` )
5556 }
5657
@@ -59,7 +60,7 @@ async function main() {
5960 output ( 'version' , staticChecking == 'localIsNew' ? local : remote )
6061 output ( 'type' , staticChecking == 'localIsNew' ? semverDiff ( remote , local ) : semverDiff ( local , remote ) )
6162
62- info ( '::endgroup::' )
63+ endGroup ( )
6364 info ( `Found match for version ${ staticChecking == 'localIsNew' ? local : remote } ` )
6465 }
6566 } else {
@@ -121,7 +122,7 @@ async function processDirectory(dir: string, commits: LocalCommit[] | PartialCom
121122
122123async function checkCommits ( commits : LocalCommit [ ] | PartialCommitResponse [ ] , version : string ) {
123124 try {
124- info ( `::group:: Searching in ${ commits . length } commit${ commits . length == 1 ? '' : 's' } ...`)
125+ startGroup ( ` Searching in ${ commits . length } commit${ commits . length == 1 ? '' : 's' } ...`)
125126 info ( `Package file name: "${ packageFileName } "` )
126127 info ( `Package file URL: ${ packageFileURL ? `"${ packageFileURL } "` : 'undefined' } ` )
127128 info ( `Version assumptions: ${ assumeSameVersion ? `"${ assumeSameVersion } "` : 'undefined' } ` )
@@ -130,13 +131,13 @@ async function checkCommits(commits: LocalCommit[] | PartialCommitResponse[], ve
130131 const match = message . match ( semverRegex ( ) ) || [ ]
131132 if ( match . includes ( version ) ) {
132133 if ( await checkDiff ( sha , version ) ) {
133- info ( '::endgroup::' )
134+ endGroup ( )
134135 info ( `Found match for version ${ version } : ${ sha . substring ( 0 , 7 ) } ${ message } ` )
135136 return true
136137 }
137138 }
138139 }
139- info ( '::endgroup::' )
140+ endGroup ( )
140141
141142 if ( getInput ( 'diff-search' ) ) {
142143 info ( 'No standard npm version commit found, switching to diff search (this could take more time...)' )
@@ -147,20 +148,21 @@ async function checkCommits(commits: LocalCommit[] | PartialCommitResponse[], ve
147148 )
148149 }
149150
150- info ( `::group:: Checking the diffs of ${ commits . length } commit${ commits . length == 1 ? '' : 's' } ...`)
151+ startGroup ( ` Checking the diffs of ${ commits . length } commit${ commits . length == 1 ? '' : 's' } ...`)
151152 for ( const commit of commits ) {
152153 const { message, sha } = getBasicInfo ( commit )
153154
154155 if ( await checkDiff ( sha , version ) ) {
155- info ( '::endgroup::' )
156+ endGroup ( )
156157 info ( `Found match for version ${ version } : ${ sha . substring ( 0 , 7 ) } - ${ message } ` )
157158 return true
158159 }
159160 }
160161 }
161162
162- info ( '::endgroup::' )
163+ endGroup ( )
163164 info ( 'No matching commit found.' )
165+ output ( 'changed' , false )
164166 return false
165167 } catch ( e ) {
166168 setFailed ( `${ e } ` )
@@ -252,6 +254,7 @@ function matchVersion(str: string): string {
252254}
253255
254256function output ( name : outputKey , value ?: string | boolean ) {
257+ outputs [ name ] = value
255258 return setOutput ( name , `${ value } ` )
256259}
257260// #endregion
@@ -271,7 +274,17 @@ class NeutralExitError extends Error { }
271274
272275if ( require . main == module ) {
273276 info ( 'Searching for version update...' )
274- main ( ) . catch ( e => {
277+ main ( ) . then ( ( ) => {
278+ if ( typeof outputs . changed == 'undefined' ) {
279+ output ( 'changed' , false )
280+ }
281+
282+ startGroup ( 'Outputs' )
283+ Object . entries ( outputs ) . forEach ( ( [ key , value ] ) => {
284+ info ( `${ key } : ${ value } ` )
285+ } )
286+ endGroup ( )
287+ } ) . catch ( e => {
275288 if ( e instanceof NeutralExitError ) process . exitCode = 78
276289 else {
277290 process . exitCode = 1
0 commit comments