| 1 |
local server_port = (os.getenv("IRC_HOST_PORT") or "irc.libera.chat 6667") |
| 2 |
local channel = os.getenv("IRC_CHANNEL") |
| 3 |
local url = os.getenv("JOB_URL") or "???" |
| 4 |
|
| 5 |
local remote = io.popen("git remote get-url origin 2> /dev/null"):read('*l') |
| 6 |
if remote == nil then |
| 7 |
-- no git / no git repo, this is not an upstream CI job |
| 8 |
return function() end |
| 9 |
end |
| 10 |
local is_origin = remote:find('~technomancy/fennel$') ~= nil |
| 11 |
|
| 12 |
local branch = io.popen("git rev-parse --abbrev-ref HEAD"):read('*l') |
| 13 |
local is_main = branch == 'main' |
| 14 |
|
| 15 |
-- This may fail in future if libera chat once again blocks builds.sr.ht |
| 16 |
-- from connecting; it currently works after we asked them to look into it |
| 17 |
return function(failure_count) |
| 18 |
if (0 ~= tonumber(failure_count)) and is_main and is_origin and channel then |
| 19 |
print("Announcing failure on", server_port, channel) |
| 20 |
|
| 21 |
local git_log = io.popen("git log --oneline -n 1 HEAD") |
| 22 |
local log = git_log:read("*a"):gsub("\n", " "):gsub("\n", " ") |
| 23 |
|
| 24 |
local nc = io.popen(string.format("nc %s > /dev/null", server_port), "w") |
| 25 |
|
| 26 |
nc:write("NICK fennel-build\n") |
| 27 |
nc:write("USER fennel-build 8 x : fennel-build\n") |
| 28 |
nc:write("JOIN " .. channel .. "\n") |
| 29 |
nc:write(string.format("PRIVMSG %s :Build failure! %s / %s\n", |
| 30 |
channel, log, url)) |
| 31 |
nc:write("QUIT\n") |
| 32 |
nc:close() |
| 33 |
end |
| 34 |
if(failure_count ~= 0) then os.exit(1) end |
| 35 |
end |