Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Actions deprecations #1316

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
# https://github.com/zero88/gh-project-context/blob/26a3afdce1fe607734278e5ccec0851d50669ef5/README.md#latest-commit-message
fetch-depth: 2
# for grabbing the current commit msg (suprisingly hard!)
- uses: zero88/gh-project-context@af8b62dd9d7ecbb2763268a040d42390ecfeb0f3
- uses: zero88/gh-project-context@88bdb34d636c3c244f26d109618346dc6a38ba6f
id: gh-project-context
- name: Binary Cache
uses: actions/cache@v3
Expand Down
9 changes: 5 additions & 4 deletions scripts-test/actions/actions_helpers_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
:v "[\"a\",\"b\",\"c\"]"}]))]))

(deftest set-output-test
(is (.contains
(with-out-str
(sut/set-output "foo" "bar"))
"::set-output name=foo::bar\n")))
(let [github-output-file (File/createTempFile "github-output" nil)
{:keys [grab-history utils]} (th/mk-utils {"GITHUB_OUTPUT" (.getPath github-output-file)})
_ (sut/set-output utils "foo" "bar")
_ (is (empty? (grab-history)))
_ (is (= "foo=bar\n" (slurp github-output-file)))]))
Comment on lines +32 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(let [github-output-file (File/createTempFile "github-output" nil)
{:keys [grab-history utils]} (th/mk-utils {"GITHUB_OUTPUT" (.getPath github-output-file)})
_ (sut/set-output utils "foo" "bar")
_ (is (empty? (grab-history)))
_ (is (= "foo=bar\n" (slurp github-output-file)))]))
(let [github-output-file (File/createTempFile "github-output" nil)
{:keys [grab-history utils]} (th/mk-utils {"GITHUB_OUTPUT" (.getPath github-output-file)})]
(sut/set-output utils "foo" "bar")
(is (empty? (grab-history)))
(is (= "foo=bar\n" (slurp github-output-file)))))

Can we pull these out of the body of the let?

2 changes: 1 addition & 1 deletion scripts-test/actions/test_helpers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(throw (Exception. (format "No default :sh stub (args: %s)" (pr-str args)))))
:getenv (fn [k]
(get env-map k))
:set-output (fn [k v]
:set-output (fn [_utils k v]
(swap! state update :history conj
{:op :set-output
:k k
Expand Down
28 changes: 19 additions & 9 deletions scripts/actions/actions_helpers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,40 @@
(:require [cheshire.core :as json]
[clojure.java.shell :as sh]))

(defn append-file-var
"Add entry k=v to file pointed to by environment variable file-var.

eg., useful for:
echo '{name}={value}' >> $GITHUB_STATE"
[{:keys [getenv]} file-var k v]
{:pre [(string? file-var)]}
(println (str "Adding file var " file-var ": " k "=" v))
(let [f (getenv file-var)]
(assert f (str "append-file-var: file is null! " file-var))
(spit f
(str k "=" v "\n")
:append true)))

(defn add-env
"Add env var k=v to future GitHub Actions steps in this job"
[{:keys [getenv]} k v]
[utils k v]
(println (str "Adding env var: " k "=" v))
(spit (getenv "GITHUB_ENV")
(str k "=" v "\n")
:append true))
(append-file-var utils "GITHUB_ENV" k v))

(defn getenv ^String [^String s] (System/getenv s))

(defn set-json-output
"Create JSON 'output' `n` for this Actions step, accessible with ${{ fromJSON(<stepid>.outputs.<n>) }}."
[{:keys [set-output] :as utils} n v]
(set-output
n
(json/generate-string v {:pretty false})))
(set-output utils n (json/generate-string v {:pretty false})))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the encode/decode pattern but it doesn't really matter.

Suggested change
(set-output utils n (json/generate-string v {:pretty false})))
(set-output utils n (json/encode v)))


(defn set-output
"Create 'output' `n` for this Actions step, accessible with ${{ <stepid>.outputs.<n> }}."
[n s]
[utils n s]
{:pre [(string? s)]}
;; Actions does not print ::set-output commands to the build output
(println (format "DEBUG: Setting output: %s %s" n s))
(println (format "::set-output name=%s::%s" n s)))
(append-file-var utils "GITHUB_OUTPUT" n s))

(defn sh [& args]
(apply sh/sh args))
Expand Down
8 changes: 4 additions & 4 deletions scripts/actions/print_matrix.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
;; determines the build matrix for the GitHub Actions build.
;; try it locally:
;; # normal builds
;; $ GITHUB_ENV=$(mktemp) GITHUB_EVENT_NAME=pull_request ./scripts/actions/print-matrix.clj
;; $ GITHUB_ENV=$(mktemp) GITHUB_EVENT_NAME=push ./scripts/actions/print-matrix.clj
;; $ GITHUB_OUTPUTS=github-outputs.tmp GITHUB_ENV=$(mktemp) GITHUB_EVENT_NAME=pull_request ./scripts/actions/print_matrix.clj
;; $ GITHUB_ENV=$(mktemp) GITHUB_EVENT_NAME=push ./scripts/actions/print_matrix.clj
;; # cron build
;; $ GITHUB_ENV=$(mktemp) GITHUB_EVENT_NAME=schedule ./scripts/actions/print-matrix.clj
;; $ GITHUB_ENV=$(mktemp) CTIA_COMMIT_MESSAGE='{:test-suite :cron} try cron build' GITHUB_EVENT_NAME=push ./scripts/actions/print-matrix.clj
;; $ GITHUB_ENV=$(mktemp) GITHUB_EVENT_NAME=schedule ./scripts/actions/print_matrix.clj
;; $ GITHUB_ENV=$(mktemp) CTIA_COMMIT_MESSAGE='{:test-suite :cron} try cron build' GITHUB_EVENT_NAME=push ./scripts/actions/print_matrix.clj

(ns actions.print-matrix
(:require [actions.actions-helpers :as h]))
Expand Down