Skip to content

Commit 94ccf84

Browse files
feat: added banner and update subscription check to make maintained actions free for public repos
1 parent 80f7757 commit 94ccf84

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

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
[![GitHub release](https://img.shields.io/github/release/step-security/ghaction-setup-docker.svg?style=flat-square)](https://github.com/step-security/ghaction-setup-docker/releases/latest)
24
[![GitHub marketplace](https://img.shields.io/badge/marketplace-docker--setup--docker-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/docker-setup-docker)
35
[![CI workflow](https://img.shields.io/github/actions/workflow/status/step-security/ghaction-setup-docker/ci.yml?branch=main&label=ci&logo=github&style=flat-square)](https://github.com/step-security/ghaction-setup-docker/actions?workflow=ci)

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

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/main.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as crypto from 'crypto';
2+
import * as fs from 'fs';
23
import path from 'path';
34
import * as core from '@actions/core';
45
import * as actionsToolkit from '@docker/actions-toolkit';
@@ -12,17 +13,43 @@ import * as context from './context.js';
1213
import * as stateHelper from './state-helper.js';
1314

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

Comments
 (0)