Skip to content
Draft
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
7 changes: 4 additions & 3 deletions docs/REIWIMSY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ and logs nothing said, and pings no one.

A message for each open pull request, each open issue and each push to main, in channels of their own, drawn from what
GitHub says now and edited as it changes: its state, its commits or changes, the latest comment a person wrote, each
package of its build. Its activity (a push, a person's comment, a change of state, a pull request's builds published
or failed) moves it to the end of its channel, posted again before the old one is deleted; a pull request or an issue
closed keeps its card a day, as it closed, then the card is deleted.
package of its build (a pull request's leaves out those only a nightly builds, unless its run made them). Its
activity (a push, a person's comment, a change of state, a pull request's builds published or failed) moves it to the
end of its channel, posted again before the old one is deleted; a pull request or an issue closed keeps its card a
day, as it closed, then the card is deleted.

The bot asks GitHub's API every 30 s, with ETags (an unchanged answer costs nothing of GitHub's 5000 an hour): the
issues and pull requests updated, the builds that run and their jobs, the nightly releases, main's head and the pushes
Expand Down
87 changes: 36 additions & 51 deletions rei/src/cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@

/* each release file, in the order the cards list them: the job of ScarletNX's build.yml that makes it (macOS's and
iOS's share one runner), what it is for, as scripts/nightly-notes.py's SYSTEMS has it, what it holds where that is
not all, and the application's emoji beside it (Wimsy as its system, scarletnx/wimsy-dist's emoji/) */
not all, the application's emoji beside it (Wimsy as its system, scarletnx/wimsy-dist's emoji/), and 1 for a file
only a run a nightly can come of makes (build.yml's appimage-cross): a pull request's card lists it only when its
run has its job or its release the file */
static const struct {
const char *file, *job, *system, *arch, *note, *icon;
int nightly;
} PACKAGES[] = {
{"ScarletNX-linux-x86_64.AppImage", "Linux AppImage (x86_64)", "Linux", "x86-64", "", "wimsy_linux"},
{"ScarletNX-linux-aarch64.AppImage", "Linux AppImage (aarch64)", "Linux", "ARM64", "", "wimsy_linux"},
{"ScarletNX-linux-ppc64le.AppImage", "Linux AppImage (ppc64le)", "Linux", "PowerPC64 LE", "", "wimsy_linux"},
{"ScarletNX-linux-x86_64.AppImage", "Linux AppImage (x86_64)", "Linux", "x86-64", "", "wimsy_linux", 0},
{"ScarletNX-linux-aarch64.AppImage", "Linux AppImage (aarch64)", "Linux", "ARM64", "", "wimsy_linux", 0},
{"ScarletNX-linux-ppc64le.AppImage", "Linux AppImage (ppc64le)", "Linux", "PowerPC64 LE", "", "wimsy_linux", 1},
{"ScarletNX-linux-ppc64.AppImage", "Linux AppImage (ppc64)", "Linux", "PowerPC64 BE", " (Linux programs)",
"wimsy_linux"},
{"ScarletNX-linux-riscv64.AppImage", "Linux AppImage (riscv64)", "Linux", "RISC-V 64", "", "wimsy_linux"},
{"ScarletNX-linux-loongarch64.AppImage", "Linux AppImage (loongarch64)", "Linux", "LoongArch64", "", "wimsy_linux"},
{"ScarletNX-windows-x86_64.zip", "Windows (Clang + LLVM)", "Windows", "x86-64", "", "wimsy_windows"},
{"ScarletNX-android-universal.apk", "Android APK", "Android", "ARM64, x86-64", "", "wimsy_android"},
{"ScarletNX-macos-arm64.zip", "macOS and iOS (arm64)", "macOS", "ARM64", "", "wimsy_macos"},
{"ScarletNX-ios-arm64.ipa", "macOS and iOS (arm64)", "iOS", "ARM64", "", "wimsy_ios"},
"wimsy_linux", 0},
{"ScarletNX-linux-riscv64.AppImage", "Linux AppImage (riscv64)", "Linux", "RISC-V 64", "", "wimsy_linux", 1},
{"ScarletNX-linux-loongarch64.AppImage", "Linux AppImage (loongarch64)", "Linux", "LoongArch64", "", "wimsy_linux",
1},
{"ScarletNX-windows-x86_64.zip", "Windows (Clang + LLVM)", "Windows", "x86-64", "", "wimsy_windows", 0},
{"ScarletNX-android-universal.apk", "Android APK", "Android", "ARM64, x86-64", "", "wimsy_android", 0},
{"ScarletNX-macos-arm64.zip", "macOS and iOS (arm64)", "macOS", "ARM64", "", "wimsy_macos", 0},
{"ScarletNX-ios-arm64.ipa", "macOS and iOS (arm64)", "iOS", "ARM64", "", "wimsy_ios", 0},
};
#define NPACKAGES (int)(sizeof PACKAGES / sizeof *PACKAGES)
/* a field's value Discord takes, in letters */
Expand All @@ -52,12 +56,6 @@ static const struct {
#define GO_ON "\xe2\x80\x8b"
/* each package's emoji as a message writes it, <:name:id>; "" until cd_icons found it */
static char g_icons[NPACKAGES][64];
/* Build's jobs that make no release file whose state Tests always says: each job, as build.yml names it, and what it
tests. The others are said when they fail */
static const struct {
const char *job, *label;
} CHECKS[] = {{"Linux (ppc64, cross)", "Linux PowerPC64 BE ELFv1"}};
#define NCHECKS (int)(sizeof CHECKS / sizeof *CHECKS)

static const char* S(const char* s) { return s ? s : ""; }
/* FNV-1a of text, as 16 hex digits */
Expand Down Expand Up @@ -347,8 +345,7 @@ void cd_icons(const cJSON* emojis) {
PACKAGES[i].icon, PACKAGES[i].system);
}
}
/* the emoji cd_icons found for the system name names first (Linux, Windows...), as a job's name or a check's;
"" for none */
/* the emoji cd_icons found for the system a job's name names first (Linux, Windows...); "" for none */
static const char* icon_of(const char* name) {
const char *first = NULL, *icon = "";
int i;
Expand All @@ -365,6 +362,17 @@ static const char* icon_of(const char* name) {
static int failure(const char* conclusion) {
return !strcmp(conclusion, "failure") || !strcmp(conclusion, "timed_out") || !strcmp(conclusion, "startup_failure");
}
/* a run that ended failed: GitHub says so, or it was cancelled once one of its jobs had failed (ScarletNX's
scripts/fail-fast.py cancels the rest of a run at its first failed job) */
static int run_failed(const cJSON* run, const cJSON* jobs) {
const char* ended = S(jstr(run, "conclusion"));
const cJSON* job;
if (failure(ended)) return 1;
if (strcmp(ended, "cancelled")) return 0;
cJSON_ArrayForEach(job, jobs) if (!strcmp(S(jstr(job, "status")), "completed") &&
failure(S(jstr(job, "conclusion")))) return 1;
return 0;
}
/* package i's line: its icon, its system and its architecture where it has one, then what */
static void line_of(Buf* b, int i, const char* what) {
if (*g_icons[i]) buf_printf(b, "%s ", g_icons[i]);
Expand Down Expand Up @@ -393,9 +401,9 @@ int cd_downloads(Buf* b, const cJSON* release) {
}
char* cd_mascot(const char* repo) { return rei_format(WIMSY, repo); }
/* a line per release file in Downloads: published, its extension linked; else what its job does; built: what a built
one waits for. Then in Tests a line per job of CHECKS, what its tests did, and one per other job that makes no file
and failed */
static void packages(cJSON* fields, const cJSON* jobs, const cJSON* release, const char* built) {
one waits for; pr: a pull request's card, which leaves out a nightly's file its run and release have nothing of.
Then in Tests a line per job that makes no file and failed */
static void packages(cJSON* fields, const cJSON* jobs, const cJSON* release, const char* built, int pr) {
Lines downloads = {fields, "Downloads", {0}}, tests = {fields, "Tests", {0}};
const cJSON* job;
int i;
Expand All @@ -404,6 +412,7 @@ static void packages(cJSON* fields, const cJSON* jobs, const cJSON* release, con
const char *status, *conclusion;
Buf v = {0}, one = {0};
job = named(jobs, "name", PACKAGES[i].job);
if (pr && PACKAGES[i].nightly && !asset && !job) continue;
status = S(jstr(job, "status"));
conclusion = S(jstr(job, "conclusion"));
if (asset)
Expand All @@ -425,34 +434,11 @@ static void packages(cJSON* fields, const cJSON* jobs, const cJSON* release, con
buf_free(&v);
}
lines_end(&downloads);
for (i = 0; i < NCHECKS; ++i) {
const char *status, *conclusion, *icon = icon_of(CHECKS[i].label);
Buf one = {0};
job = named(jobs, "name", CHECKS[i].job);
status = S(jstr(job, "status"));
conclusion = S(jstr(job, "conclusion"));
if (*icon) buf_printf(&one, "%s ", icon);
buf_printf(&one, "%s: ", CHECKS[i].label);
if (!job || !strcmp(status, "queued") || !strcmp(status, "waiting") || !strcmp(status, "pending") ||
!strcmp(status, "requested"))
buf_add(&one, "Waiting");
else if (strcmp(status, "completed"))
buf_printf(&one, "Testing ([log](%s))", S(jstr(job, "html_url")));
else if (!strcmp(conclusion, "success"))
buf_add(&one, "Passed");
else if (!strcmp(conclusion, "cancelled") || !strcmp(conclusion, "skipped"))
capitalized(&one, conclusion);
else
buf_printf(&one, "Failed ([log](%s))", S(jstr(job, "html_url")));
lines_add(&tests, one.text);
buf_free(&one);
}
cJSON_ArrayForEach(job, jobs) {
const char* name = S(jstr(job, "name"));
int listed = 0;
Buf one = {0};
for (i = 0; i < NPACKAGES; ++i) listed |= !strcmp(name, PACKAGES[i].job);
for (i = 0; i < NCHECKS; ++i) listed |= !strcmp(name, CHECKS[i].job);
if (listed || strcmp(S(jstr(job, "status")), "completed") || !failure(S(jstr(job, "conclusion")))) continue;
if (*icon_of(name)) buf_printf(&one, "%s ", icon_of(name));
buf_printf(&one, "%s: Failed ([log](%s))", name, S(jstr(job, "html_url")));
Expand Down Expand Up @@ -606,14 +592,12 @@ cJSON* cd_pr(Cards* c, int number, int* open, double* closed_at) {
fork_name = rei_strdup(S(jstr(cJSON_GetObjectItemCaseSensitive(head_obj, "repo"), "full_name")));
built = rei_strdup(strcmp(fork_name, c->gh->repo) && !labeled(pr, LABEL) ? "waits for the team's label"
: "being published");
packages(fields, jobs, current, built);
packages(fields, jobs, current, built, 1);
/* the outcome that moves the card: published or failed, kept while its push's builds run again or are
cancelled */
if (current)
snprintf(c->builds, sizeof c->builds, "published %s", head);
else if (run && !strcmp(S(jstr(run, "status")), "completed") &&
(!strcmp(S(jstr(run, "conclusion")), "failure") || !strcmp(S(jstr(run, "conclusion")), "timed_out") ||
!strcmp(S(jstr(run, "conclusion")), "startup_failure")))
else if (run && !strcmp(S(jstr(run, "status")), "completed") && run_failed(run, jobs))
snprintf(c->builds, sizeof c->builds, "failed %s", head);
else {
char* mine = rei_format(" %s", head);
Expand Down Expand Up @@ -892,7 +876,8 @@ cJSON* cd_nightly(Cards* c, const char* sha) {
buf_printf(&b, "Building main at [`%.7s`](%s), committed %s.", sha, commit, date);
else if (strcmp(S(jstr(run, "conclusion")), "success")) {
const char* ended = S(jstr(run, "conclusion"));
char* how = !strcmp(ended, "failure") ? rei_strdup("failed")
char* how = !strcmp(ended, "failure") || (!strcmp(ended, "cancelled") && run_failed(run, jobs))
? rei_strdup("failed")
: !strcmp(ended, "cancelled") ? rei_strdup("was cancelled")
: rei_format("ended as %s", *ended ? ended : "nothing GitHub said");
buf_printf(&b, "Not published: the build of [`%.7s`](%s) %s ([run](%s)).", sha, commit, how,
Expand Down Expand Up @@ -925,7 +910,7 @@ cJSON* cd_nightly(Cards* c, const char* sha) {
}
for (i = 0; i < n; ++i) free(lines[i]);
if (n >= 0) free(lines);
packages(fields, jobs, own, built);
packages(fields, jobs, own, built, 0);
{
char *source = rei_format("[`%.7s`](%s)", sha, commit),
*every = rei_format("[%s](" SERVER "/%s/releases)", c->gh->nightly, c->gh->nightly);
Expand Down
45 changes: 35 additions & 10 deletions rei/tests/test_rei.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,19 @@ static void fix_cards(void) {
cJSON_Delete(drawn);
free(run);
}
/* cancelled once a job of it had failed (ScarletNX's fail-fast): failed */
gh_shas("repos/o/r/actions/workflows/build.yml/runs?head_sha=@c&per_page=100&page=1",
"{\"workflow_runs\":[{\"id\":71,\"event\":\"push\",\"status\":\"completed\",\"conclusion\":"
"\"cancelled\",\"created_at\":\"2026-11-04T22:00:05Z\"}]}");
gh("repos/o/r/actions/runs/71/jobs?per_page=100&page=1",
"{\"jobs\":[{\"name\":\"Linux (aarch64)\",\"status\":\"completed\",\"conclusion\":\"failure\"},"
"{\"name\":\"Android APK\",\"status\":\"completed\",\"conclusion\":\"cancelled\"}]}");
{
cJSON* drawn = cd_nightly(&c, head);
HAS(jstr(drawn, "description"), "failed ([run]");
cJSON_Delete(drawn);
}
gh("repos/o/r/actions/runs/71/jobs?per_page=100&page=1", "{\"jobs\":[]}");
/* built, and older than the oldest nightly kept: none of it is kept now, which is all the card can know */
gh_shas("repos/o/r/actions/workflows/build.yml/runs?head_sha=@c&per_page=100&page=1",
"{\"workflow_runs\":[{\"id\":71,\"event\":\"push\",\"status\":\"completed\",\"conclusion\":"
Expand All @@ -982,7 +995,13 @@ static void fix_cards(void) {
c.nightlies = NULL;
{
cJSON* drawn = cd_nightly(&c, head);
char* all = cJSON_PrintUnformatted(drawn);
HAS(jstr(drawn, "description"), "; no nightly of it is kept now: o/nightly keeps the newest 30.");
/* a nightly's card lists every package, those only a nightly builds too */
HAS(all, "Linux PowerPC64 LE: ");
HAS(all, "Linux RISC-V 64: ");
HAS(all, "Linux LoongArch64: ");
free(all);
cJSON_Delete(drawn);
}
free(head);
Expand Down Expand Up @@ -1089,8 +1108,6 @@ static void pr_card(void) {
"{\"name\":\"Android APK\",\"status\":\"completed\",\"conclusion\":\"failure\",\"html_url\":\"https://j/2\"},"
"{\"name\":\"Linux AppImage (aarch64)\",\"status\":\"completed\",\"conclusion\":\"success\"},"
"{\"name\":\"macOS and iOS (arm64)\",\"status\":\"queued\",\"html_url\":\"https://j/3\"},"
"{\"name\":\"Linux (ppc64, cross)\",\"status\":\"completed\",\"conclusion\":\"failure\","
"\"html_url\":\"https://j/4\"},"
"{\"name\":\"Linux (x86_64, ASan + UBSan)\",\"status\":\"completed\",\"conclusion\":\"failure\","
"\"html_url\":\"https://j/5\"},"
"{\"name\":\"Linux (x86_64)\",\"status\":\"completed\",\"conclusion\":\"success\",\"html_url\":\"https://j/6\"},"
Expand All @@ -1114,20 +1131,19 @@ static void pr_card(void) {
"on main at [`3333333`](https://github.com/o/r/commit/3333333333333333333333333333333333333333) "
"([its nightly](https://n/1)).");
HAS(text, "**2 commits**, the newest first\\n- \\\\[gpu\\\\] Second \\\\*one\\\\*\\n- \\\\[gpu\\\\] First");
/* a line a package in one Downloads field, its icon, then its link or its job's state; then in Tests the jobs
of CHECKS, what their tests did, and the other jobs that make no file and failed, not those running or passed,
each with the icon of the system its name names.
/* a line a package in one Downloads field, its icon, then its link or its job's state, but a nightly's package
its run has no job for and its release no file; then in Tests the other jobs that make no file and failed, not
those running or passed, each with the icon of the system its name names.
No Build field (each job has its line) and no Builds while this push's are published (each has its link) */
HAS(text,
"{\"name\":\"Downloads\",\"value\":\"<:wimsy_linux:11> Linux x86-64: Building ([log](https://j/1))\\n"
"<:wimsy_linux:11> Linux ARM64: Built, being published\\n<:wimsy_linux:11> Linux PowerPC64 LE: Waiting\\n"
"<:wimsy_linux:11> Linux ARM64: Built, being published\\n"
"<:wimsy_linux:11> Linux PowerPC64 BE: [.AppImage](https://n/p) (Linux programs)\\n"
"<:wimsy_linux:11> Linux RISC-V 64: Waiting\\n<:wimsy_linux:11> Linux LoongArch64: Waiting\\n"
"<:wimsy_windows:22> Windows x86-64: [.zip](https://n/w)\\n"
"<:wimsy_android:33> Android: Failed ([log](https://j/2))\\n"
"<:wimsy_macos:44> macOS ARM64: Waiting\\n<:wimsy_ios:55> iOS ARM64: Waiting\",\"inline\":false},"
"{\"name\":\"Tests\",\"value\":\"<:wimsy_linux:11> Linux PowerPC64 BE ELFv1: Failed ([log](https://j/4))\\n"
"<:wimsy_linux:11> Linux (x86_64, ASan + UBSan): Failed ([log](https://j/5))\",\"inline\":false}");
"{\"name\":\"Tests\",\"value\":\"<:wimsy_linux:11> Linux (x86_64, ASan + UBSan): Failed ([log](https://j/5))\","
"\"inline\":false}");
CHECK(!strstr(text, " MB") && !strstr(text, "https://j/6") && !strstr(text, "https://j/7"));
CHECK(!strstr(text, "\"name\":\"Build\"") && !strstr(text, "\"name\":\"Builds\""));
HAS(text, "\"color\":2066493"); /* GitHub's green: open */
Expand Down Expand Up @@ -1177,13 +1193,14 @@ static void pr_card(void) {
CHECK(first && second && n == 2);
CHECK(rei_letters(cJSON_GetObjectItemCaseSensitive(first, "value")->valuestring) <= 1024);
CHECK(rei_letters(cJSON_GetObjectItemCaseSensitive(second, "value")->valuestring) <= 1024);
/* a nightly's package its run has a job for: listed on a pull request's card too */
CHECK(strstr(cJSON_GetObjectItemCaseSensitive(first, "value")->valuestring, "Linux LoongArch64: Building"));
{
const char* windows = "<:wimsy_windows:1563256573802057808> Windows x86-64: Building ([log](";
CHECK(!strncmp(cJSON_GetObjectItemCaseSensitive(second, "value")->valuestring, windows, strlen(windows)));
}
text = cJSON_PrintUnformatted(e);
HAS(text, "<:wimsy_linux:1563256571297923183> Linux PowerPC64 BE ELFv1: Waiting");
CHECK(!strstr(text, "ELFv1") && !strstr(text, "\"Tests\""));
HAS(text, "{\"name\":\"Builds\",\"value\":\"[The push before](https://n/pr-7)\",\"inline\":true}");
free(text);
cJSON_Delete(e);
Expand Down Expand Up @@ -1213,6 +1230,14 @@ static void pr_card(void) {
SAME(c.activity, was); /* a job done */
run_is(&c, "\"completed\",\"conclusion\":\"cancelled\"");
SAME(c.activity, was); /* cancelled, none failed before */
gh("repos/o/r/actions/runs/9/jobs?per_page=100&page=1",
"{\"jobs\":[{\"name\":\"Linux AppImage (x86_64)\",\"status\":\"completed\",\"conclusion\":\"success\"},"
"{\"name\":\"Linux (aarch64)\",\"status\":\"completed\",\"conclusion\":\"failure\"}]}");
run_is(&c, "\"completed\",\"conclusion\":\"cancelled\"");
CHECK(strcmp(c.activity, was)); /* cancelled once a job had failed (ScarletNX's fail-fast): failed */
SAME(c.builds, "failed 1111111111111111111111111111111111111111");
gh("repos/o/r/actions/runs/9/jobs?per_page=100&page=1",
"{\"jobs\":[{\"name\":\"Linux AppImage (x86_64)\",\"status\":\"completed\",\"conclusion\":\"success\"}]}");
run_is(&c, "\"completed\",\"conclusion\":\"failure\"");
CHECK(strcmp(c.activity, was)); /* failed */
SAME(c.builds, "failed 1111111111111111111111111111111111111111");
Expand Down