@yunuseon/kayra 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ import { statusRequest } from "./forge.js";
13
13
  import { json, send } from "./http.js";
14
14
  import { spawnLines } from "./process.js";
15
15
  import { empty, enqueue, finish } from "./queue.js";
16
- import { expired, releaseName } from "./records.js";
16
+ import { expired, moved, releaseName, releases } from "./records.js";
17
17
  import { deploy, renovate } from "./run.js";
18
18
  import { runsOf } from "./store.js";
19
19
  const token = (name) => {
@@ -195,12 +195,14 @@ const deployRequest = (app, ref, why) => ({
195
195
  work: { kind: "deploy", app: app.name, ref, why },
196
196
  });
197
197
  const jobRequest = (job, dryRun) => ({ owner: jobOwner(job), work: { kind: "job", job, dryRun } });
198
- /** The webhook's fallback: an app whose ref moved to a commit no run has tried yet. */
198
+ /** The webhook's fallback: an app whose ref moved to a commit no run has tried yet and no release runs (one migrated from Jenkins has releases but no runs). */
199
199
  const poll = async (s) => {
200
200
  await Promise.all(registeredApps(s).map(async (app) => {
201
201
  const commit = await builderResolve(s, app, app.ref);
202
- const last = runsOf(runsDir(s), appOwner(app.name)).find((run) => run.sha !== undefined);
203
- if (commit.ok && commit.value !== last?.sha)
202
+ const lastRun = runsOf(runsDir(s), appOwner(app.name)).find((run) => run.sha !== undefined);
203
+ const releasesDir = join(s.platformDir, "releases", app.name);
204
+ const lastRelease = releases(existsSync(releasesDir) ? readdirSync(releasesDir) : [])[0];
205
+ if (commit.ok && moved(commit.value, lastRun?.sha, lastRelease?.sha))
204
206
  swap(s, (queue) => enqueue(queue, deployRequest(app, app.ref, "poll")));
205
207
  }));
206
208
  };
@@ -12,6 +12,8 @@ export const releases = (names) => names
12
12
  return match?.[1] === undefined || !commit.ok ? [] : [{ sha: commit.value, time: match[1] }];
13
13
  })
14
14
  .filter((release, i, all) => all.findIndex((other) => other.sha === release.sha) === i);
15
+ /** The poll's question: has the ref moved to a commit neither the newest run tried nor the newest release runs? */
16
+ export const moved = (resolved, lastRun, lastRelease) => resolved !== lastRun && resolved !== lastRelease;
15
17
  const whys = ["push", "poll", "deploy", "rollback", "schedule", "manual"];
16
18
  const states = ["running", "success", "failure"];
17
19
  const isWhy = (value) => whys.some((why) => why === value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yunuseon/kayra",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "A self-hosted app platform and the CLI that runs it: Traefik, Authelia, a registry, rootless BuildKit and a small deployer per server, set up with OpenTofu and Ansible.",
5
5
  "license": "MIT",
6
6
  "author": "Yunus Öztürk",