Skip to content

Commit 1b544b2

Browse files
Merge pull request #54 from step-security/feat/update-subscription-check
feat: added banner and update subscription check to make maintained actions free for public repos
2 parents 4690da6 + ab27182 commit 1b544b2

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM golang:1.26-alpine3.23@sha256:2389ebfa5b7f43eeafbd6be0c3700cc46690ef842ad96
33
ARG GHCOMMIT_VERSION=v0.1.77
44

55
# hadolint ignore=DL3018
6-
RUN apk add --no-cache bash git-crypt curl git
6+
RUN apk add --no-cache bash git-crypt curl git jq
77

88
# Download and build ghcommit from source
99
RUN git clone --depth 1 --branch "${GHCOMMIT_VERSION}" https://github.com/planetscale/ghcommit.git /ghcommit

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
# ghcommit-action
24

35
A GitHub Action to detect changed files during a Workflow run and to commit and

entrypoint.sh

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,44 @@
33
set -euo pipefail
44
[[ -n "${DEBUG:-}" ]] && set -x
55

6-
# validate subscription status
7-
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/subscription"
8-
9-
# Set a timeout for the curl command (3 seconds)
10-
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" "$API_URL" -o /dev/null) || true
11-
CURL_EXIT_CODE=$?
12-
13-
# Decide based on curl exit code and HTTP status
14-
if [ $CURL_EXIT_CODE -ne 0 ]; then
15-
echo "Timeout or API not reachable. Continuing to next step."
16-
elif [ "$RESPONSE" = "200" ]; then
17-
:
18-
elif [ "$RESPONSE" = "403" ]; then
19-
echo "Subscription is not valid. Reach out to support@stepsecurity.io"
20-
exit 1
21-
else
22-
echo "Timeout or API not reachable. Continuing to next step."
6+
REPO_PRIVATE=$(jq -r '.repository.private | tostring' "${GITHUB_EVENT_PATH:-}" 2>/dev/null || echo "")
7+
UPSTREAM="planetscale/ghcommit-action"
8+
ACTION_REPO="${GITHUB_ACTION_REPOSITORY:-}"
9+
DOCS_URL="https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"
10+
11+
echo ""
12+
echo -e "\033[1;36mStepSecurity Maintained Action\033[0m"
13+
echo "Secure drop-in replacement for $UPSTREAM"
14+
if [ "$REPO_PRIVATE" = "false" ]; then
15+
echo -e "\033[32m✓ Free for public repositories\033[0m"
16+
fi
17+
echo -e "\033[36mLearn more:\033[0m $DOCS_URL"
18+
echo ""
19+
20+
if [ "$REPO_PRIVATE" != "false" ]; then
21+
SERVER_URL="${GITHUB_SERVER_URL:-https://github.com}"
22+
23+
if [ "$SERVER_URL" != "https://github.com" ]; then
24+
BODY=$(printf '{"action":"%s","ghes_server":"%s"}' "$ACTION_REPO" "$SERVER_URL")
25+
else
26+
BODY=$(printf '{"action":"%s"}' "$ACTION_REPO")
27+
fi
28+
29+
API_URL="https://agent.api.stepsecurity.io/v1/github/$GITHUB_REPOSITORY/actions/maintained-actions-subscription"
30+
31+
RESPONSE=$(curl --max-time 3 -s -w "%{http_code}" \
32+
-X POST \
33+
-H "Content-Type: application/json" \
34+
-d "$BODY" \
35+
"$API_URL" -o /dev/null) && CURL_EXIT_CODE=0 || CURL_EXIT_CODE=$?
36+
37+
if [ "$CURL_EXIT_CODE" -ne 0 ]; then
38+
echo "Timeout or API not reachable. Continuing to next step."
39+
elif [ "$RESPONSE" = "403" ]; then
40+
echo -e "::error::\033[1;31mThis action requires a StepSecurity subscription for private repositories.\033[0m"
41+
echo -e "::error::\033[31mLearn how to enable a subscription: $DOCS_URL\033[0m"
42+
exit 1
43+
fi
2344
fi
2445

2546
COMMIT_MESSAGE="${1:?Missing commit_message input}"

0 commit comments

Comments
 (0)