Skip to content

Commit 9636ed2

Browse files
authored
Merge pull request #187 from step-security/feat/update-subscription-check
feat: added banner and update subscription check to make maintained actions free for public repos
2 parents bde6deb + a8edea0 commit 9636ed2

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

.github/workflows/actions_release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
description: "Specify a script to run after audit fix"
1111
required: false
1212
default: "pnpm build"
13+
node_version:
14+
description: "Specify Node.js version (e.g., '18', '20', 'lts/*')"
15+
required: false
16+
default: "24"
1317

1418
permissions:
1519
contents: read
@@ -24,3 +28,4 @@ jobs:
2428
with:
2529
tag: "${{ github.event.inputs.tag }}"
2630
script: "${{ github.event.inputs.script }}"
31+
node_version: "${{ github.event.inputs.node_version }}"

.github/workflows/audit-package.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
description: "Specify a base branch"
1212
required: false
1313
default: "main"
14+
node_version:
15+
description: "Specify Node.js version (e.g., '18', '20', 'lts/*')"
16+
required: false
17+
default: "24"
1418
schedule:
1519
- cron: "0 0 * * 1"
1620

@@ -19,7 +23,8 @@ jobs:
1923
uses: step-security/reusable-workflows/.github/workflows/audit_fix.yml@v1
2024
with:
2125
force: ${{ inputs.force || false }}
22-
base_branch: ${{ inputs.base_branch || 'main' }}
26+
base_branch: ${{ inputs.base_branch || 'main' }}
27+
node_version: "${{ inputs.node_version || '24' }}"
2328

2429
permissions:
2530
contents: write

.github/workflows/auto_cherry_pick.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ on:
1919
description: "Run mode: cherry-pick or verify"
2020
required: false
2121
default: "cherry-pick"
22+
node_version:
23+
description: "Specify Node.js version (e.g., '18', '20', 'lts/*')"
24+
required: false
25+
default: "24"
2226

2327
pull_request:
2428
types: [labeled, opened, synchronize]
@@ -40,3 +44,4 @@ jobs:
4044
package_manager: "pnpm"
4145
script: ${{ inputs.script || 'pnpm build' }}
4246
mode: ${{ github.event_name == 'pull_request' && 'verify' || inputs.mode }}
47+
node_version: "${{ inputs.node_version || '24' }}"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![StepSecurity Maintained Action](https://raw.githubusercontent.com/step-security/maintained-actions-assets/main/assets/maintained-action-banner.png)](https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions)
2+
13
# Setup pnpm
24

35
Install pnpm package manager.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { setFailed, saveState, getState } from '@actions/core'
22
import * as core from '@actions/core'
3+
import * as fs from 'fs'
34
import axios, {isAxiosError} from 'axios'
45
import restoreCache from './cache-restore'
56
import saveCache from './cache-save'
@@ -10,19 +11,49 @@ import pnpmInstall from './pnpm-install'
1011
import pruneStore from './pnpm-store-prune'
1112

1213
async 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

Comments
 (0)