|
1 | 1 | #!/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" |
3 | 6 |
|
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 |
7 | 24 |
|
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 |
10 | 34 | 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" |
15 | 38 | exit 1 |
16 | | -else |
17 | | - echo "Timeout or API not reachable. Continuing to next step." |
| 39 | + fi |
18 | 40 | fi |
19 | 41 |
|
20 | 42 | PACKAGE_JSON_PATH="${1-.}" |
|
0 commit comments