11import * as crypto from 'crypto' ;
2+ import * as fs from 'fs' ;
23import path from 'path' ;
34import * as core from '@actions/core' ;
45import * as actionsToolkit from '@docker/actions-toolkit' ;
@@ -12,17 +13,43 @@ import * as context from './context.js';
1213import * as stateHelper from './state-helper.js' ;
1314
1415async function validateSubscription ( ) : Promise < void > {
15- const API_URL = `https://agent.api.stepsecurity.io/v1/github/${ process . env . GITHUB_REPOSITORY } /actions/subscription` ;
16+ const eventPath = process . env . GITHUB_EVENT_PATH ;
17+ let repoPrivate : boolean | undefined ;
1618
19+ if ( eventPath && fs . existsSync ( eventPath ) ) {
20+ const eventData = JSON . parse ( fs . readFileSync ( eventPath , 'utf8' ) ) ;
21+ repoPrivate = eventData ?. repository ?. private ;
22+ }
23+
24+ const upstream = 'crazy-max/ghaction-setup-docker' ;
25+ const action = process . env . GITHUB_ACTION_REPOSITORY ;
26+ const docsUrl = 'https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions' ;
27+
28+ core . info ( '' ) ;
29+ core . info ( '\u001b[1;36mStepSecurity Maintained Action\u001b[0m' ) ;
30+ core . info ( `Secure drop-in replacement for ${ upstream } ` ) ;
31+ if ( repoPrivate === false ) core . info ( '\u001b[32m\u2713 Free for public repositories\u001b[0m' ) ;
32+ core . info ( `\u001b[36mLearn more:\u001b[0m ${ docsUrl } ` ) ;
33+ core . info ( '' ) ;
34+
35+ if ( repoPrivate === false ) return ;
36+
37+ const serverUrl = process . env . GITHUB_SERVER_URL || 'https://github.com' ;
38+ const body : Record < string , string > = { action : action || '' } ;
39+ if ( serverUrl !== 'https://github.com' ) body . ghes_server = serverUrl ;
1740 try {
18- await axios . get ( API_URL , { timeout : 3000 } ) ;
41+ await axios . post (
42+ `https://agent.api.stepsecurity.io/v1/github/${ process . env . GITHUB_REPOSITORY } /actions/maintained-actions-subscription` ,
43+ body ,
44+ { timeout : 3000 }
45+ ) ;
1946 } catch ( error ) {
2047 if ( isAxiosError ( error ) && error . response ?. status === 403 ) {
21- core . error ( 'Subscription is not valid. Reach out to support@stepsecurity.io' ) ;
48+ core . error ( `\u001b[1;31mThis action requires a StepSecurity subscription for private repositories.\u001b[0m` ) ;
49+ core . error ( `\u001b[31mLearn how to enable a subscription: ${ docsUrl } \u001b[0m` ) ;
2250 process . exit ( 1 ) ;
23- } else {
24- core . info ( 'Timeout or API not reachable. Continuing to next step.' ) ;
2551 }
52+ core . info ( 'Timeout or API not reachable. Continuing to next step.' ) ;
2653 }
2754}
2855
0 commit comments