@alchemy.run/pkg 2.0.0-beta.84 → 2.0.0-beta.86

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.
Files changed (52) hide show
  1. package/README.md +4 -2
  2. package/dist/Manifest.d.ts.map +1 -1
  3. package/dist/Manifest.js.map +1 -1
  4. package/dist/Protocol.d.ts.map +1 -1
  5. package/dist/Protocol.js.map +1 -1
  6. package/dist/Registry/Bindings.d.ts +13 -0
  7. package/dist/Registry/Bindings.d.ts.map +1 -1
  8. package/dist/Registry/Bindings.js +6 -0
  9. package/dist/Registry/Bindings.js.map +1 -1
  10. package/dist/Registry/GitHub.d.ts +6 -8
  11. package/dist/Registry/GitHub.d.ts.map +1 -1
  12. package/dist/Registry/GitHub.js +6 -2
  13. package/dist/Registry/GitHub.js.map +1 -1
  14. package/dist/Registry/Handler.d.ts +8 -2
  15. package/dist/Registry/Handler.d.ts.map +1 -1
  16. package/dist/Registry/Handler.js +28 -3
  17. package/dist/Registry/Handler.js.map +1 -1
  18. package/dist/Registry/KVCache.d.ts +1 -1
  19. package/dist/Registry/KVCache.d.ts.map +1 -1
  20. package/dist/Registry/KVCache.js +2 -2
  21. package/dist/Registry/KVCache.js.map +1 -1
  22. package/dist/Registry/Sweep.d.ts +1 -1
  23. package/dist/Registry/Sweep.d.ts.map +1 -1
  24. package/dist/Registry/Sweep.js.map +1 -1
  25. package/dist/Registry/Tags.d.ts +24 -3
  26. package/dist/Registry/Tags.d.ts.map +1 -1
  27. package/dist/Registry/Tags.js +27 -6
  28. package/dist/Registry/Tags.js.map +1 -1
  29. package/dist/Registry.d.ts +98 -69
  30. package/dist/Registry.d.ts.map +1 -1
  31. package/dist/Registry.js +3 -0
  32. package/dist/Registry.js.map +1 -1
  33. package/dist/cli/bin.d.ts.map +1 -1
  34. package/dist/cli/bin.js.map +1 -1
  35. package/dist/cli/pack.d.ts.map +1 -1
  36. package/dist/cli/pack.js +7 -8
  37. package/dist/cli/pack.js.map +1 -1
  38. package/dist/cli/publish.d.ts.map +1 -1
  39. package/dist/cli/publish.js +23 -10
  40. package/dist/cli/publish.js.map +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/migrations/0002_head_of.sql +6 -0
  44. package/package.json +10 -10
  45. package/src/Registry/Bindings.ts +6 -0
  46. package/src/Registry/GitHub.ts +8 -2
  47. package/src/Registry/Handler.ts +38 -3
  48. package/src/Registry/KVCache.ts +3 -3
  49. package/src/Registry/Tags.ts +34 -6
  50. package/src/Registry.ts +10 -0
  51. package/src/cli/pack.ts +7 -8
  52. package/src/cli/publish.ts +40 -14
@@ -1,10 +1,10 @@
1
1
  import * as Config from "effect/Config";
2
- import * as Console from "effect/Console";
3
2
  import * as Data from "effect/Data";
4
3
  import * as Effect from "effect/Effect";
5
4
  import * as FileSystem from "effect/FileSystem";
6
5
  import * as HttpApiClient from "effect/http-api/HttpApiClient";
7
6
  import * as Path from "effect/Path";
7
+ import * as Schedule from "effect/Schedule";
8
8
  import * as Schema from "effect/Schema";
9
9
  import { MANIFEST_FILE, ManifestJson, type Manifest } from "../Manifest.ts";
10
10
  import { PkgApi, type TarballRef } from "../Protocol.ts";
@@ -42,6 +42,28 @@ const failed = (what: string) => (e: { readonly _tag: string; readonly message?:
42
42
  message: `${what}: ${e.message ? `${e._tag}: ${e.message}` : e._tag}`,
43
43
  });
44
44
 
45
+ /**
46
+ * GitHub reports a run as queued, or as its previous attempt, for a few
47
+ * seconds after a job starts, and for minutes while Actions is degraded.
48
+ * The registry answers `RunNotInProgress` until GitHub catches up, so a
49
+ * request from inside the job waits that out, for up to three minutes.
50
+ */
51
+ const whileRunCatchesUp = <A, E extends { readonly _tag: string }, R>(
52
+ effect: Effect.Effect<A, E, R>,
53
+ ) =>
54
+ effect.pipe(
55
+ Effect.tapError((e) =>
56
+ e._tag === "RunNotInProgress"
57
+ ? Effect.logInfo("GitHub does not report this run as in progress yet; retrying")
58
+ : Effect.void,
59
+ ),
60
+ Effect.retry({
61
+ while: (e) => e._tag === "RunNotInProgress",
62
+ schedule: Schedule.spaced("5 seconds"),
63
+ times: 36,
64
+ }),
65
+ );
66
+
45
67
  /**
46
68
  * Publish a `pkg pack` directory from the current GitHub Actions job. The
47
69
  * workflow must first have uploaded the manifest as an artifact of the run
@@ -58,7 +80,7 @@ export const publish = Effect.fn("publish")(function* (options: PublishOptions)
58
80
 
59
81
  const dir = path.resolve(options.cwd, options.dir);
60
82
  const manifestText = yield* fs.readFileString(path.join(dir, MANIFEST_FILE));
61
- const manifest = yield* Schema.decodeUnknownEffect(ManifestJson)(manifestText);
83
+ const manifest = yield* Schema.decodeEffect(ManifestJson)(manifestText);
62
84
  if (manifest.registry !== registry) {
63
85
  return yield* new PublishError({
64
86
  message: `artifact was packed for ${manifest.registry}, not ${registry}`,
@@ -66,26 +88,28 @@ export const publish = Effect.fn("publish")(function* (options: PublishOptions)
66
88
  }
67
89
 
68
90
  if (manifest.packages.length === 0) {
69
- yield* Console.log("No affected packages to publish.");
91
+ yield* Effect.logInfo("No affected packages to publish.");
70
92
  return { packages: [] };
71
93
  }
72
94
 
73
95
  const upload = (pkg: Manifest["packages"][number]) =>
74
96
  Effect.gen(function* () {
75
97
  const bytes = yield* fs.readFile(path.join(dir, pkg.file));
76
- const result = yield* client.Registry.uploadTarball({
77
- params: { name: pkg.name, sha256: pkg.sha256 },
78
- query: run,
79
- payload: bytes,
80
- }).pipe(Effect.mapError(failed(`upload ${pkg.name}`)));
81
- yield* Console.log(
98
+ const result = yield* whileRunCatchesUp(
99
+ client.Registry.uploadTarball({
100
+ params: { name: pkg.name, sha256: pkg.sha256 },
101
+ query: run,
102
+ payload: bytes,
103
+ }),
104
+ ).pipe(Effect.mapError(failed(`upload ${pkg.name}`)));
105
+ yield* Effect.logInfo(
82
106
  `${result.uploaded ? "Uploaded" : "Reused"} ${pkg.name} (${pkg.sha256.slice(0, 12)}, ${pkg.size} bytes)`,
83
107
  );
84
108
  });
85
109
 
86
110
  const uploadMissing = (missing: ReadonlyArray<TarballRef>) => {
87
111
  const wanted = new Set(missing.map((ref) => `${ref.name}@${ref.sha256}`));
88
- return Console.log(
112
+ return Effect.logInfo(
89
113
  `${missing.length} of ${manifest.packages.length} tarball(s) to upload`,
90
114
  ).pipe(
91
115
  Effect.andThen(
@@ -98,9 +122,11 @@ export const publish = Effect.fn("publish")(function* (options: PublishOptions)
98
122
  );
99
123
  };
100
124
 
101
- const attempt = client.Registry.publish({
102
- payload: { run, manifest: manifestText },
103
- });
125
+ const attempt = whileRunCatchesUp(
126
+ client.Registry.publish({
127
+ payload: { run, manifest: manifestText },
128
+ }),
129
+ );
104
130
  const published = yield* attempt.pipe(
105
131
  // The first answer is usually the tarballs to upload; publish once more
106
132
  // after uploading them.
@@ -116,7 +142,7 @@ export const publish = Effect.fn("publish")(function* (options: PublishOptions)
116
142
  );
117
143
 
118
144
  for (const pkg of published.packages) {
119
- yield* Console.log(`${pkg.name}: ${pkg.url} [${pkg.tags.join(", ")}]`);
145
+ yield* Effect.logInfo(`${pkg.name}: ${pkg.url} [${pkg.tags.join(", ")}]`);
120
146
  }
121
147
  return published;
122
148
  });