|
3 | 3 | set -euo pipefail |
4 | 4 | [[ -n "${DEBUG:-}" ]] && set -x |
5 | 5 |
|
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 |
23 | 44 | fi |
24 | 45 |
|
25 | 46 | COMMIT_MESSAGE="${1:?Missing commit_message input}" |
|
0 commit comments