11import { setFailed , saveState , getState } from '@actions/core'
22import * as core from '@actions/core'
3+ import * as fs from 'fs'
34import axios , { isAxiosError } from 'axios'
45import restoreCache from './cache-restore'
56import saveCache from './cache-save'
@@ -10,19 +11,49 @@ import pnpmInstall from './pnpm-install'
1011import pruneStore from './pnpm-store-prune'
1112
1213async function validateSubscription ( ) : Promise < void > {
13- const API_URL = `https://agent.api.stepsecurity.io/v1/github/${ process . env . GITHUB_REPOSITORY } /actions/subscription`
14+ const eventPath = process . env . GITHUB_EVENT_PATH
15+ let repoPrivate : boolean | undefined
1416
17+ if ( eventPath && fs . existsSync ( eventPath ) ) {
18+ const eventData = JSON . parse ( fs . readFileSync ( eventPath , 'utf8' ) )
19+ repoPrivate = eventData ?. repository ?. private
20+ }
21+
22+ const upstream = 'pnpm/action-setup'
23+ const action = process . env . GITHUB_ACTION_REPOSITORY
24+ const docsUrl =
25+ 'https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions'
26+
27+ core . info ( '' )
28+ core . info ( '\u001b[1;36mStepSecurity Maintained Action\u001b[0m' )
29+ core . info ( `Secure drop-in replacement for ${ upstream } ` )
30+ if ( repoPrivate === false )
31+ 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
1540 try {
16- 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+ )
1746 } catch ( error ) {
1847 if ( isAxiosError ( error ) && error . response ?. status === 403 ) {
1948 core . error (
20- 'Subscription is not valid. Reach out to support@stepsecurity.io'
49+ `\u001b[1;31mThis action requires a StepSecurity subscription for private repositories.\u001b[0m`
50+ )
51+ core . error (
52+ `\u001b[31mLearn how to enable a subscription: ${ docsUrl } \u001b[0m`
2153 )
2254 process . exit ( 1 )
23- } else {
24- core . info ( 'Timeout or API not reachable. Continuing to next step.' )
2555 }
56+ core . info ( 'Timeout or API not reachable. Continuing to next step.' )
2657 }
2758}
2859
0 commit comments