Skip to content

Commit 6ea3474

Browse files
Merge pull request #70 from step-security/feat/update-subscription-check
feat: added banner and update subscription check to make maintained actions free for public repos
2 parents 501a5b1 + 83c3040 commit 6ea3474

2 files changed

Lines changed: 36 additions & 12 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
# StepSecurity Maintained npm-get-version-action Actions
24

35
Forked from: [martinbeentjes/npm-get-version-action](https://github.com/martinbeentjes/npm-get-version-action)

entrypoint.sh

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
#!/bin/sh -l
2-
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/subscription"
2+
REPO_PRIVATE=$(jq -r '.repository.private | tostring' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
3+
UPSTREAM="martinbeentjes/npm-get-version-action"
4+
ACTION_REPO="${GITHUB_ACTION_REPOSITORY:-}"
5+
DOCS_URL="https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"
36

4-
# Set a timeout for the curl command (3 seconds)
5-
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" "$API_URL" -o /dev/null) || true
6-
CURL_EXIT_CODE=${?}
7+
echo ""
8+
echo -e "\033[1;36mStepSecurity Maintained Action\033[0m"
9+
echo "Secure drop-in replacement for $UPSTREAM"
10+
if [ "$REPO_PRIVATE" = "false" ]; then
11+
echo -e "\033[32m✓ Free for public repositories\033[0m"
12+
fi
13+
echo -e "\033[36mLearn more:\033[0m $DOCS_URL"
14+
echo ""
15+
16+
if [ "$REPO_PRIVATE" != "false" ]; then
17+
SERVER_URL="${GITHUB_SERVER_URL:-https://github.com}"
18+
19+
if [ "$SERVER_URL" != "https://github.com" ]; then
20+
BODY=$(printf '{"action":"%s","ghes_server":"%s"}' "$ACTION_REPO" "$SERVER_URL")
21+
else
22+
BODY=$(printf '{"action":"%s"}' "$ACTION_REPO")
23+
fi
724

8-
# Check if the response code is not 200
9-
if [ $CURL_EXIT_CODE -ne 0 ]; then
25+
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/maintained-actions-subscription"
26+
27+
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" \
28+
-X POST \
29+
-H "Content-Type: application/json" \
30+
-d "$BODY" \
31+
"$API_URL" -o /dev/null) && CURL_EXIT_CODE=0 || CURL_EXIT_CODE=$?
32+
33+
if [ $CURL_EXIT_CODE -ne 0 ]; then
1034
echo "Timeout or API not reachable. Continuing to next step."
11-
elif [ "$RESPONSE" = "200" ]; then
12-
:
13-
elif [ "$RESPONSE" = "403" ]; then
14-
echo "Subscription is not valid. Reach out to support@stepsecurity.io"
35+
elif [ "$RESPONSE" = "403" ]; then
36+
echo -e "::error::\033[1;31mThis action requires a StepSecurity subscription for private repositories.\033[0m"
37+
echo -e "::error::\033[31mLearn how to enable a subscription: $DOCS_URL\033[0m"
1538
exit 1
16-
else
17-
echo "Timeout or API not reachable. Continuing to next step."
39+
fi
1840
fi
1941

2042
PACKAGE_JSON_PATH="${1-.}"

0 commit comments

Comments
 (0)