Skip to content

Commit

Permalink
Fix deprecated commands (set-env, add-path) (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG authored Dec 7, 2020
1 parent dafbd02 commit 302740d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GitHubActions"
uuid = "6b79fd1a-b13a-48ab-b6b0-aaee1fee41df"
authors = ["Chris de Graaf <me@cdg.dev> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ Utilities for working within GitHub Actions, modelled after [`actions/core`](htt

Perhaps the most common use case is to set the global logger to one compatible with GitHub Actions' log format:

### Inside the package
### In A Package

For package code, set the global logger in `__init__`.

```
using Logging: global_logger
using GitHubActions: GitHubActionsLogger
function __init__()
# Using GitHubActions logger in CI
get(ENV, "GITHUB_ACTIONS", "false") == "true" && global_logger(GitHubActionsLogger())
end
```

### Inside the runtests
### In Tests

In tests, set the global logger at the top level.

```jl
using Logging: global_logger
using GitHubActions: GitHubActionsLogger
# Using GitHubActions logger in CI
get(ENV, "GITHUB_ACTIONS", "false") == "true" && global_logger(GitHubActionsLogger())
@warn "This warning will be visible in your GitHub Actions logs!"
```



For information on the other provided functions, see the documentation.
10 changes: 8 additions & 2 deletions src/GitHubActions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ end

fail() = exit(1)

add_to_file(k, v) = open(f -> println(f, v), ENV[k], "a")

"""
end_group()
Expand Down Expand Up @@ -152,7 +154,7 @@ Add `v` to the system `PATH`.
function add_path(v)
sep = @static Sys.iswindows() ? ';' : ':'
ENV["PATH"] = v * sep * ENV["PATH"]
command("add-path", (), v)
add_to_file("GITHUB_PATH", v)
end

"""
Expand Down Expand Up @@ -186,7 +188,11 @@ Set environment variable `k` to value `v`.
function set_env(k, v)
val = cmd_value(v)
ENV[k] = val
command("set-env", (name=k,), val)
delimiter = "EOF"
while occursin(delimiter, val)
delimiter *= "EOF"
end
add_to_file("GITHUB_ENV", join(["$k<<$delimiter", val, delimiter], "\n"))
end

"""
Expand Down
34 changes: 25 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ const GHA = GitHubActions

@test (@capture_out start_group("a")) == "::group::a\n"

withenv("PATH" => "/bin") do
@test (@capture_out add_path("a")) == "::add-path::a\n"
sep = Sys.iswindows() ? ';' : ':'
@test ENV["PATH"] == "a$sep/bin"
mktemp() do file, io
withenv("GITHUB_PATH" => file, "PATH" => "/bin") do
sep = Sys.iswindows() ? ';' : ':'
add_path("a")
@test ENV["PATH"] == string("a", sep, "/bin")
@test read(file, String) == "a\n"
add_path("b")
@test ENV["PATH"] == string("b", sep, "a", sep, "/bin")
@test read(file, String) == "a\nb\n"
end
end

withenv(() -> (@test get_input("A") == ""), "INPUT_A" => "")
Expand All @@ -54,11 +60,21 @@ const GHA = GitHubActions

@test (@capture_out group(() -> println("!"), "a")) == "::group::a\n!\n::endgroup::\n"

withenv("a" => nothing) do
@test (@capture_out set_env("a", "b")) == "::set-env name=a::b\n"
@test ENV["a"] == "b"
@test (@capture_out set_env("a", ())) == "::set-env name=a::[]\n"
@test ENV["a"] == "[]"
mktemp() do file, io
withenv("GITHUB_ENV" => file, map(c -> string(c) => nothing, 'a':'z')...) do
set_env("a", "b")
@test ENV["a"] == "b"
@test read(file, String) == "a<<EOF\nb\nEOF\n"
set_env("b", "fooEOFbar")
@test read(file, String) == "a<<EOF\nb\nEOF\nb<<EOFEOF\nfooEOFbar\nEOFEOF\n"
rm(file)
set_env("c", [])
@test ENV["c"] == "[]"
@test read(file, String) == "c<<EOF\n[]\nEOF\n"
set_env("d", nothing)
@test ENV["d"] == ""
@test read(file, String) == "c<<EOF\n[]\nEOF\nd<<EOF\n\nEOF\n"
end
end

mock(atexit) do ae
Expand Down

2 comments on commit 302740d

@christopher-dG
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:
The deprecated add-path and set-env GHA commands have been updated.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/26005

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 302740d513e58ab753d10d123f7fc8db41c839f8
git push origin v0.1.1

Please sign in to comment.