Skip to content

Commit fb95bf8

Browse files
authored
Merge pull request #34 from step-security/feat/update-subscription-check
feat: added banner and update subscription check to make maintained actions free for public repos
2 parents cb8d0f4 + 3f5de4d commit fb95bf8

2 files changed

Lines changed: 39 additions & 14 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
# Github Release On Push Action
24

35
> Stop using files for versioning. Use git tags instead!

src/release_on_push_action/core.clj

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,43 @@
172172
(println (prepare-key-value "body" (:body release-data))))))
173173

174174
(defn validate-subscription! [context]
175-
(let [repo (:repo context)
176-
url (str "https://agent.api.stepsecurity.io/v1/github/" repo "/actions/subscription")]
177-
(try
178-
(curl/get url {:timeout 3000})
179-
(catch clojure.lang.ExceptionInfo e
180-
(let [status (-> e ex-data :status)]
181-
(if (= status 403)
182-
(do
183-
(println "::error::Subscription is not valid. Reach out to support@stepsecurity.io")
184-
(System/exit 1))
185-
(println "INFO: Timeout or API not reachable. Continuing to next step."))))
186-
(catch Exception _
187-
;; handle unexpected error types (network issues, DNS, etc.)
188-
(println "INFO: Timeout or API not reachable. Continuing to next step.")))))
175+
(let [event-path (System/getenv "GITHUB_EVENT_PATH")
176+
repo-private (when (and event-path (.exists (io/file event-path)))
177+
(try
178+
(get-in (json/parse-string (slurp event-path) true)
179+
[:repository :private])
180+
(catch Exception _ nil)))
181+
upstream "rymndhng/release-on-push-action"
182+
action (System/getenv "GITHUB_ACTION_REPOSITORY")
183+
docs-url "https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"]
184+
(println "")
185+
(println "StepSecurity Maintained Action")
186+
(println (str "Secure drop-in replacement for " upstream))
187+
(when (false? repo-private)
188+
(println "✓ Free for public repositories"))
189+
(println (str "Learn more: " docs-url))
190+
(println "")
191+
(when-not (false? repo-private)
192+
(let [server-url (or (System/getenv "GITHUB_SERVER_URL") "https://github.com")
193+
body (cond-> {:action (or action "")}
194+
(not= server-url "https://github.com") (assoc :ghes_server server-url))
195+
url (str "https://agent.api.stepsecurity.io/v1/github/"
196+
(:repo context)
197+
"/actions/maintained-actions-subscription")]
198+
(try
199+
(curl/post url {:body (json/generate-string body)
200+
:headers {"Content-Type" "application/json"}
201+
:timeout 3000})
202+
(catch clojure.lang.ExceptionInfo e
203+
(let [status (-> e ex-data :status)]
204+
(if (= status 403)
205+
(do
206+
(println "::error::This action requires a StepSecurity subscription for private repositories.")
207+
(println (str "::error::Learn how to enable a subscription: " docs-url ""))
208+
(System/exit 1))
209+
(println "Timeout or API not reachable. Continuing to next step."))))
210+
(catch Exception _
211+
(println "Timeout or API not reachable. Continuing to next step.")))))))
189212

190213

191214
(defn -main [& args]

0 commit comments

Comments
 (0)