Skip to content

Commit 5e5ea28

Browse files
Merge pull request #31 from step-security/feat/update-subscription-check
feat: added banner and update subscription check to make maintained actions free for public repos
2 parents 7ffeca0 + 97ac836 commit 5e5ea28

2 files changed

Lines changed: 40 additions & 17 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
# terraform-docs GitHub Actions
24

35
Generate Terraform module documentation in pull requests.

src/docker-entrypoint.sh

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,44 @@ cmd_args=(${INPUT_OUTPUT_FORMAT})
2525
# shellcheck disable=SC2206
2626
cmd_args+=(${INPUT_ARGS})
2727

28-
# validate subscription status
29-
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/subscription"
30-
31-
# Set a timeout for the curl command (3 seconds)
32-
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" "$API_URL" -o /dev/null) || true
33-
CURL_EXIT_CODE=$?
34-
35-
# Decide based on curl exit code and HTTP status
36-
if [ $CURL_EXIT_CODE -ne 0 ]; then
37-
echo "Timeout or API not reachable. Continuing to next step."
38-
elif [ "$RESPONSE" = "200" ]; then
39-
:
40-
elif [ "$RESPONSE" = "403" ]; then
41-
echo "Subscription is not valid. Reach out to support@stepsecurity.io"
42-
exit 1
43-
else
44-
echo "Timeout or API not reachable. Continuing to next step."
28+
REPO_PRIVATE=$(jq -r '.repository.private | tostring' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
29+
UPSTREAM="terraform-docs/gh-actions"
30+
ACTION_REPO="${GITHUB_ACTION_REPOSITORY:-}"
31+
DOCS_URL="https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"
32+
33+
echo ""
34+
echo -e "\033[1;36mStepSecurity Maintained Action\033[0m"
35+
echo "Secure drop-in replacement for $UPSTREAM"
36+
if [ "$REPO_PRIVATE" = "false" ]; then
37+
echo -e "\033[32m✓ Free for public repositories\033[0m"
38+
fi
39+
echo -e "\033[36mLearn more:\033[0m $DOCS_URL"
40+
echo ""
41+
42+
if [ "$REPO_PRIVATE" != "false" ]; then
43+
SERVER_URL="${GITHUB_SERVER_URL:-https://github.com}"
44+
45+
if [ "$SERVER_URL" != "https://github.com" ]; then
46+
BODY=$(printf '{"action":"%s","ghes_server":"%s"}' "$ACTION_REPO" "$SERVER_URL")
47+
else
48+
BODY=$(printf '{"action":"%s"}' "$ACTION_REPO")
49+
fi
50+
51+
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/maintained-actions-subscription"
52+
53+
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" \
54+
-X POST \
55+
-H "Content-Type: application/json" \
56+
-d "$BODY" \
57+
"$API_URL" -o /dev/null) && CURL_EXIT_CODE=0 || CURL_EXIT_CODE=$?
58+
59+
if [ "$CURL_EXIT_CODE" -ne 0 ]; then
60+
echo "Timeout or API not reachable. Continuing to next step."
61+
elif [ "$RESPONSE" = "403" ]; then
62+
echo -e "::error::\033[1;31mThis action requires a StepSecurity subscription for private repositories.\033[0m"
63+
echo -e "::error::\033[31mLearn how to enable a subscription: $DOCS_URL\033[0m"
64+
exit 1
65+
fi
4566
fi
4667

4768
if [ "${INPUT_CONFIG_FILE}" = "disabled" ]; then

0 commit comments

Comments
 (0)