Skip to content

Commit 1faf846

Browse files
committed
Allow dry-run of notify workflow
1 parent 1ecef6c commit 1faf846

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

.github/workflows/notify.exs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ Mix.install([
66
{:jason, "~> 1.0"}
77
])
88

9-
%{status: 200, body: body} =
9+
%{status: 200, body: release} =
1010
Req.get!("https://api.github.com/repos/elixir-lang/elixir/releases/tags/#{tag}")
1111

12-
if body["draft"] do
12+
if release["draft"] do
1313
raise "cannot notify a draft release"
1414
end
1515

1616
## Notify on elixir-lang-ann
1717

1818
names_and_checksums =
19-
for asset <- body["assets"],
19+
for asset <- release["assets"],
2020
name = asset["name"],
2121
name =~ ~r/.sha\d+sum$/,
2222
do: {name, Req.get!(asset["browser_download_url"]).body}
@@ -29,34 +29,44 @@ line_items =
2929
" * #{root} - #{type} - #{checksum}\n"
3030
end
3131

32-
headers = %{
33-
"X-Postmark-Server-Token" => System.fetch_env!("ELIXIR_LANG_ANN_TOKEN")
34-
}
35-
36-
body = %{
32+
mail = %{
3733
"From" => "[email protected]",
3834
"To" => "[email protected]",
3935
"Subject" => "Elixir #{tag} released",
4036
"HtmlBody" => "https://github.com/elixir-lang/elixir/releases/tag/#{tag}\n\n#{line_items}",
41-
"MessageStream": "outbound"
37+
"MessageStream" => "outbound"
4238
}
4339

44-
resp = Req.post!("https://api.postmarkapp.com/email", {:json, body}, headers: headers)
45-
IO.puts("#{resp.status} elixir-lang-ann\n#{inspect(resp.body)}")
40+
if System.get_env("DRYRUN") do
41+
IO.puts("MAIL")
42+
IO.inspect(mail)
43+
else
44+
headers = %{
45+
"X-Postmark-Server-Token" => System.fetch_env!("ELIXIR_LANG_ANN_TOKEN")
46+
}
4647

47-
## Notify on Elixir Forum
48+
resp = Req.post!("https://api.postmarkapp.com/email", {:json, mail}, headers: headers)
49+
IO.puts("#{resp.status} elixir-lang-ann\n#{inspect(resp.body)}")
50+
end
4851

49-
headers = %{
50-
"api-key" => System.fetch_env!("ELIXIR_FORUM_TOKEN"),
51-
"api-username" => "Elixir"
52-
}
52+
## Notify on Elixir Forum
5353

54-
body = %{
54+
post = %{
5555
"title" => "Elixir #{tag} released",
56-
"raw" => "https://github.com/elixir-lang/elixir/releases/tag/#{tag}\n\n#{body["body"]}",
56+
"raw" => "https://github.com/elixir-lang/elixir/releases/tag/#{tag}\n\n#{release["body"]}",
5757
# Elixir News
5858
"category" => 28
5959
}
6060

61-
resp = Req.post!("https://elixirforum.com/posts.json", {:json, body}, headers: headers)
62-
IO.puts("#{resp.status} Elixir Forum\n#{inspect(resp.body)}")
61+
if System.get_env("DRYRUN") do
62+
IO.puts("POST")
63+
IO.inspect(post)
64+
else
65+
headers = %{
66+
"api-key" => System.fetch_env!("ELIXIR_FORUM_TOKEN"),
67+
"api-username" => "Elixir"
68+
}
69+
70+
resp = Req.post!("https://elixirforum.com/posts.json", {:json, post}, headers: headers)
71+
IO.puts("#{resp.status} Elixir Forum\n#{inspect(resp.body)}")
72+
end

0 commit comments

Comments
 (0)