jive-abstract-app-github-pages 0.2.0-latest-darwin-x64 → 0.2.0

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 (115) hide show
  1. package/README.md +155 -0
  2. package/bin/jive-app-github-pages +34 -0
  3. package/bin/package.json +1 -0
  4. package/dist/entrypoints/jive-app-github-pages.js +18 -0
  5. package/dist/entrypoints/jive-app-github-pages.js.map +1 -0
  6. package/dist/index.js +8 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/internal/commands/cicd/audit.js +10 -0
  9. package/dist/internal/commands/cicd/audit.js.map +1 -0
  10. package/dist/internal/commands/cicd/build.js +8 -0
  11. package/dist/internal/commands/cicd/build.js.map +1 -0
  12. package/dist/internal/commands/cicd/deploy-plan.js +19 -0
  13. package/dist/internal/commands/cicd/deploy-plan.js.map +1 -0
  14. package/dist/internal/commands/cicd/deploy.js +8 -0
  15. package/dist/internal/commands/cicd/deploy.js.map +1 -0
  16. package/dist/internal/commands/cicd/get-config.js +9 -0
  17. package/dist/internal/commands/cicd/get-config.js.map +1 -0
  18. package/dist/internal/commands/cicd/index.js +16 -0
  19. package/dist/internal/commands/cicd/index.js.map +1 -0
  20. package/dist/internal/commands/cicd/upload-artifacts.js +6 -0
  21. package/dist/internal/commands/cicd/upload-artifacts.js.map +1 -0
  22. package/dist/internal/commands/create.js +32 -0
  23. package/dist/internal/commands/create.js.map +1 -0
  24. package/dist/internal/commands/dev.js +11 -0
  25. package/dist/internal/commands/dev.js.map +1 -0
  26. package/dist/internal/common/command.js +5 -0
  27. package/dist/internal/common/command.js.map +1 -0
  28. package/dist/internal/common/constants.js +30 -0
  29. package/dist/internal/common/constants.js.map +1 -0
  30. package/dist/internal/common/deploy-token.js +17 -0
  31. package/dist/internal/common/deploy-token.js.map +1 -0
  32. package/dist/internal/common/layer.js +14 -0
  33. package/dist/internal/common/layer.js.map +1 -0
  34. package/dist/internal/modules/deployer/impl.js +111 -0
  35. package/dist/internal/modules/deployer/impl.js.map +1 -0
  36. package/dist/internal/modules/deployer/interface.js +1 -0
  37. package/dist/internal/modules/deployer/interface.js.map +1 -0
  38. package/dist/internal/modules/https-probe/impl.js +15 -0
  39. package/dist/internal/modules/https-probe/impl.js.map +1 -0
  40. package/dist/internal/modules/https-probe/interface.js +1 -0
  41. package/dist/internal/modules/https-probe/interface.js.map +1 -0
  42. package/dist/internal/modules/index.js +13 -0
  43. package/dist/internal/modules/index.js.map +1 -0
  44. package/dist/internal/modules/package/impl.js +16 -0
  45. package/dist/internal/modules/package/impl.js.map +1 -0
  46. package/dist/internal/modules/package/interface.js +1 -0
  47. package/dist/internal/modules/package/interface.js.map +1 -0
  48. package/dist/internal/modules/pages-api/impl.js +61 -0
  49. package/dist/internal/modules/pages-api/impl.js.map +1 -0
  50. package/dist/internal/modules/pages-api/interface.js +1 -0
  51. package/dist/internal/modules/pages-api/interface.js.map +1 -0
  52. package/dist/internal/modules/pages-api/recorded/README.md +11 -0
  53. package/dist/internal/modules/pages-api/recorded/build-built.json +1 -0
  54. package/dist/internal/modules/pages-api/recorded/build-errored.json +1 -0
  55. package/dist/internal/modules/pages-api/recorded/site-legacy-gh-pages.json +1 -0
  56. package/dist/internal/modules/pages-api/recorded/site-none.json +5 -0
  57. package/dist/internal/modules/publishing-branch/impl.js +83 -0
  58. package/dist/internal/modules/publishing-branch/impl.js.map +1 -0
  59. package/dist/internal/modules/publishing-branch/interface.js +1 -0
  60. package/dist/internal/modules/publishing-branch/interface.js.map +1 -0
  61. package/dist/internal/modules/scaffold/impl.js +37 -0
  62. package/dist/internal/modules/scaffold/impl.js.map +1 -0
  63. package/dist/internal/modules/scaffold/interface.js +1 -0
  64. package/dist/internal/modules/scaffold/interface.js.map +1 -0
  65. package/dist/internal/modules/site/impl.js +71 -0
  66. package/dist/internal/modules/site/impl.js.map +1 -0
  67. package/dist/internal/modules/site/interface.js +1 -0
  68. package/dist/internal/modules/site/interface.js.map +1 -0
  69. package/dist/internal/public/manifest.js +95 -0
  70. package/dist/internal/public/manifest.js.map +1 -0
  71. package/dist/internal/public/scaffold.js +62 -0
  72. package/dist/internal/public/scaffold.js.map +1 -0
  73. package/dist/internal/public/site-url.js +16 -0
  74. package/dist/internal/public/site-url.js.map +1 -0
  75. package/package.json +47 -11
  76. package/postinstall.cjs +663 -0
  77. package/src/entrypoints/jive-app-github-pages.ts +19 -0
  78. package/src/index.ts +18 -0
  79. package/src/internal/commands/cicd/audit.ts +14 -0
  80. package/src/internal/commands/cicd/build.ts +12 -0
  81. package/src/internal/commands/cicd/deploy-plan.ts +23 -0
  82. package/src/internal/commands/cicd/deploy.ts +12 -0
  83. package/src/internal/commands/cicd/get-config.ts +13 -0
  84. package/src/internal/commands/cicd/index.ts +16 -0
  85. package/src/internal/commands/cicd/upload-artifacts.ts +10 -0
  86. package/src/internal/commands/create.ts +36 -0
  87. package/src/internal/commands/dev.ts +11 -0
  88. package/src/internal/common/command.ts +7 -0
  89. package/src/internal/common/constants.ts +34 -0
  90. package/src/internal/common/deploy-token.ts +20 -0
  91. package/src/internal/common/layer.ts +25 -0
  92. package/src/internal/modules/deployer/impl.ts +119 -0
  93. package/src/internal/modules/deployer/interface.ts +20 -0
  94. package/src/internal/modules/https-probe/impl.ts +22 -0
  95. package/src/internal/modules/https-probe/interface.ts +10 -0
  96. package/src/internal/modules/index.ts +28 -0
  97. package/src/internal/modules/package/impl.ts +20 -0
  98. package/src/internal/modules/package/interface.ts +10 -0
  99. package/src/internal/modules/pages-api/impl.ts +86 -0
  100. package/src/internal/modules/pages-api/interface.ts +40 -0
  101. package/src/internal/modules/pages-api/recorded/README.md +11 -0
  102. package/src/internal/modules/pages-api/recorded/build-built.json +1 -0
  103. package/src/internal/modules/pages-api/recorded/build-errored.json +1 -0
  104. package/src/internal/modules/pages-api/recorded/site-legacy-gh-pages.json +1 -0
  105. package/src/internal/modules/pages-api/recorded/site-none.json +5 -0
  106. package/src/internal/modules/publishing-branch/impl.ts +95 -0
  107. package/src/internal/modules/publishing-branch/interface.ts +37 -0
  108. package/src/internal/modules/scaffold/impl.ts +42 -0
  109. package/src/internal/modules/scaffold/interface.ts +15 -0
  110. package/src/internal/modules/site/impl.ts +74 -0
  111. package/src/internal/modules/site/interface.ts +14 -0
  112. package/src/internal/public/manifest.ts +117 -0
  113. package/src/internal/public/scaffold.ts +129 -0
  114. package/src/internal/public/site-url.ts +18 -0
  115. package/multi-call-binary +0 -4
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # jive-abstract-app-github-pages
2
+
3
+ A [Jive](https://github.com/jive-sh/jive) abstract for static sites served by [GitHub Pages](https://pages.github.com).
4
+ A site whose `package.json` extends it gets a full CI/CD pipeline with no pipeline code of its own: every push to
5
+ its deploy branch builds the site with whatever generator it uses (Astro, Vite, Bun's HTML bundler, plain files),
6
+ publishes the result to the repository's `gh-pages` branch, and waits until GitHub Pages reports it built.
7
+
8
+ Its CLI is `jive-app-github-pages`, so the target command for a new site is `jive create app github pages`. Today
9
+ the same thing is `jive-app-github-pages create <directory>`.
10
+
11
+ ## Vocabulary
12
+
13
+ - **Site**: the folder the package's own build script writes, `outputDir`. Its contents are exactly what GitHub
14
+ Pages serves.
15
+ - **Publishing branch**: `gh-pages`. Each deploy adds one commit to it whose tree is the site, so its history is
16
+ the history of deploys. GitHub Pages serves it when the repository's Pages source is "Deploy from a branch",
17
+ `gh-pages`, `/`
18
+ ([publishing source](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)).
19
+ - **Custom domain**: the hostname GitHub Pages serves the site at instead of `https://<owner>.github.io/<repository>/`.
20
+ A branch-published site's custom domain is whatever its `CNAME` file names
21
+ ([custom domains](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site)),
22
+ so the build writes that file from `domain`.
23
+
24
+ ## Extending it
25
+
26
+ ```jsonc
27
+ {
28
+ "$schema": "./package.schema.json",
29
+ "name": "@acme/docs",
30
+ "version": "0.1.0",
31
+ "license": "MIT",
32
+ "type": "module",
33
+ "scripts": {
34
+ "jive:cicd:get-config": "jive-app-github-pages cicd get-config",
35
+ "jive:cicd:build": "jive-app-github-pages cicd build",
36
+ "jive:cicd:audit": "jive-app-github-pages cicd audit",
37
+ "jive:cicd:deploy:plan": "jive-app-github-pages cicd deploy-plan",
38
+ "jive:cicd:upload-artifacts": "jive-app-github-pages cicd upload-artifacts",
39
+ "jive:cicd:deploy": "jive-app-github-pages cicd deploy",
40
+ "build": "astro build",
41
+ "dev": "jive-app-github-pages dev"
42
+ },
43
+ "devDependencies": { "jive-abstract-app-github-pages": "^0.1.0" },
44
+ "jive": {
45
+ "cicd": {
46
+ "deploy": { "verb": "Deploy to", "branches": { "main": ["Production"] }, "previews": false, "sequentially": true },
47
+ "runsOnPullRequests": true,
48
+ "runsOn": "ubuntu-latest",
49
+ "requiredSecrets": ["GH_PAGES_DEPLOY_TOKEN"]
50
+ },
51
+ "app-github-pages": {
52
+ "buildScript": "build",
53
+ "outputDir": "dist",
54
+ "domain": "docs.acme.com"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ | Field | Meaning |
61
+ | --- | --- |
62
+ | `buildScript` | The `package.json` script that writes the site into `outputDir`; the build hook runs `bun run <buildScript>`. |
63
+ | `outputDir` | The folder, relative to the package, holding the built site. Never the package itself, never outside it. |
64
+ | `domain` | A bare lowercase hostname (`docs.acme.com`, never `https://…`), or `null` for `https://<owner>.github.io/<repository>/`. |
65
+
66
+ Every field is required, so the schema shows everything you can configure. `jive-app-github-pages dev` keeps
67
+ `package.schema.json` current, so your editor checks the block as you type it. The hooks also enforce rules that
68
+ span fields:
69
+
70
+ - `cicd.deploy.previews` is false, and `cicd.deploy.branches` deploys at most one environment from one branch: a
71
+ repository has one GitHub Pages site, so there is nowhere else to deploy to.
72
+ - `cicd.requiredSecrets` includes `GH_PAGES_DEPLOY_TOKEN`, the token the deploy pushes with (see
73
+ [The deploy token](#the-deploy-token)). The pipeline passes the hooks only the secrets listed.
74
+ - `buildScript` names a script in `package.json`, and not a `jive:cicd:*` hook, which would loop.
75
+
76
+ `jive-app-github-pages create <directory> [--name <package>] [--domain <hostname>] [--skip-install]` writes a package
77
+ in this shape, with a one-page site in `src/index.html` built by Bun's HTML bundler, its `.gitignore`, a README and
78
+ its `.github/workflows/pipeline.yml`.
79
+
80
+ ## What each hook does
81
+
82
+ | Hook | Behavior |
83
+ | --- | --- |
84
+ | `get-config` | Prints the validated `jive` block as JSON. |
85
+ | `build` | Runs `bun run <buildScript>` and checks it wrote `<outputDir>/index.html`. Then writes `CNAME` naming `domain`, or removes one when `domain` is null (with a warning naming what it replaced or removed), and writes an empty `.nojekyll`, which tells GitHub Pages the branch needs no Jekyll build. Jekyll would otherwise leave out every file and folder starting with `_`, such as Astro's `_astro/` ([Jekyll](https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll)). |
86
+ | `audit` | Checks the site has `index.html`, `.nojekyll`, and a `CNAME` exactly when `domain` is set, naming it. Replace this script to run the site's own checks as well. |
87
+ | `deploy:plan` | Plans a deploy (`{"deploy":true,"url":…}`) to where the site is served: `https://<domain>/` once the domain answers over https with a valid certificate, `http://<domain>/` before (GitHub Pages issues the certificate only after the domain's DNS points at it), or `https://<owner>.github.io/<repository>/` without a domain. |
88
+ | `upload-artifacts` | Nothing; the pipeline's artifact already carries `outputDir`. |
89
+ | `deploy` | Checks the site again, then publishes it to `gh-pages` as one commit on top of the branch (none when the branch already holds exactly this site), never force-pushed: a deploy that loses a race with another fails and changes nothing. Then it checks the repository's Pages source is `gh-pages` at `/`, and polls every 5 seconds until GitHub reports the build its push started `built` (success) or `errored` (failure, with GitHub's reason), for at most 10 minutes. When the branch already held this site, nothing is pushed: a build of it that is built ends the deploy, one still running is awaited, and otherwise (its build failed, or none ran) the deploy pushes the same site again as a new commit, which starts a new build. |
90
+
91
+ ## The deploy token
92
+
93
+ Jive's shared pipeline gives its jobs an ID token and the checkout's read access (`id-token: write`, `contents:
94
+ read`), and nothing more. The Jive server is to read that ID token to decide what the pipeline may reach, so the
95
+ shared pipeline's permissions are never widened: a wider grant would apply to every package's pipeline at once. Until that
96
+ server can grant the push, a package extending this abstract pushes with its own narrowly scoped token instead of the
97
+ job's `GITHUB_TOKEN`.
98
+
99
+ That token is the repository's `GH_PAGES_DEPLOY_TOKEN` GitHub Actions secret: a
100
+ [fine-grained personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#fine-grained-personal-access-tokens)
101
+ limited to that one repository, with these permissions
102
+ ([permissions for fine-grained tokens](https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens)):
103
+
104
+ | Call | Permission |
105
+ | --- | --- |
106
+ | `git push` to `gh-pages` | Contents: read and write |
107
+ | `GET /repos/{owner}/{repo}/pages` and `.../pages/builds/latest` | Pages: read |
108
+
109
+ It needs no Pages write, because the deploy never requests a build: it waits for the one its push starts. GitHub
110
+ builds a branch-published site on every push to its source branch, except a push made with the job's `GITHUB_TOKEN`
111
+ ("Commits pushed by a GitHub Actions workflow that uses the GITHUB_TOKEN do not trigger a GitHub Pages build",
112
+ [GITHUB_TOKEN](https://docs.github.com/en/actions/concepts/security/github_token)). The Pages API also needs a token
113
+ for a public repository: an unauthenticated `GET /repos/{owner}/{repo}/pages` answers 404.
114
+
115
+ A repository secret reaches every pull request opened from a branch of the same repository, and not those from forks
116
+ ([using secrets](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets#using-secrets-in-a-workflow)).
117
+ So only people who can already push branches to the repository can open a pull request whose build sees it. The
118
+ token is scaffolding with a removal date, its expiry: it goes once the Jive server grants the push from the
119
+ pipeline's ID token. The `pipeline.yml` that `create` writes is Jive's standard caller, granting only `contents:
120
+ read` and `id-token: write`.
121
+
122
+ ## Limitations and open questions
123
+
124
+ - **Pages must already be set up on the repository.** Creating a Pages site or changing its source needs the
125
+ repository's Administration permission, which the deploy token does not have, so a repository without Pages, or whose
126
+ source is not `gh-pages` at `/`, fails its deploy with the settings page to change. The site is published first,
127
+ so the branch is there to choose. Provisioning it belongs to a GitHub resource connector holding that permission
128
+ on Jive's server, which does not exist yet.
129
+ - **https is not enforced.** "Enforce HTTPS" is a Pages setting needing the same Administration permission.
130
+ - **The DNS record is not created.** `domain` makes GitHub Pages serve the site there; the record pointing the
131
+ domain at GitHub Pages is yours to create at your DNS provider.
132
+ - **No previews.** A repository has one Pages site, so a pull request has nowhere of its own to deploy to.
133
+ - **One owner's site.** A repository named `<owner>.github.io` is the owner's own site and is served at its root;
134
+ every other repository is served under `/<repository>/`, so a site without a domain must be built for that base
135
+ path (Astro's `base`, Vite's `base`).
136
+
137
+ ## How it is tested
138
+
139
+ This repository is a library: its own pipeline publishes it to npm and never deploys a site. `bun run
140
+ jive:cicd:audit` runs `tsc` and every test. Nothing in them reaches GitHub:
141
+
142
+ - Unit tests (`src/**/*.test.ts`) cover the manifest's rules, the site URLs, the scaffold (its `package.json`
143
+ passes every rule), the deploy's sequence against fake modules and a test clock (an already built commit, a
144
+ build still running, a rerun after a failed build pushing the site again, a failing build, a push that starts no
145
+ build, a timeout, a repository without Pages or with another source), the Pages API client
146
+ against GitHub responses recorded from jive-sh/docs (`src/internal/modules/pages-api/recorded/`), and the
147
+ publishing branch with real git against a bare repository on disk: the first commit, an unchanged site, a new
148
+ commit of an unchanged site, removed files, a race with another deploy, and that the token travels only in the
149
+ environment, never in arguments.
150
+ - `test/hooks.test.ts` runs `get-config`, `build`, `audit`, `deploy:plan`, `upload-artifacts` and `deploy`'s token
151
+ check through the CLI from source against the fixture site in `test/fixture`, and `create` followed by the new
152
+ package's own build and audit.
153
+
154
+ What only a consumer's pipeline can test, against its real repository: that GitHub accepts the deploy token for the
155
+ push and the Pages reads with the permissions above, that its push starts a build, and how long a real build takes.
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Every command's file in a built package's bin/, the same for every command: it is the command its own file name says.
5
+ *
6
+ * On macOS and Linux it runs once. It has the package's postinstall.cjs replace it (and every other command's file)
7
+ * with a hard link to the real program, which the package manager skips when it does not run postinstall (Bun, for a
8
+ * package it does not trust), then runs the program with what was typed. On Windows a command starts through its .cmd
9
+ * shim, which always runs this file, so it runs the program every time and sets up again only when the commands are
10
+ * stale.
11
+ *
12
+ * CommonJS for the reason postinstall.cjs gives: bin/package.json makes this extensionless file CommonJS.
13
+ */
14
+ const { spawnSync } = require("child_process");
15
+ const { realpathSync } = require("fs");
16
+ const { basename, dirname, join } = require("path");
17
+
18
+ // The real path: reached through a link in a bin directory, the package is wherever the link points.
19
+ const launcherPath = realpathSync(__filename);
20
+ const packageDir = dirname(dirname(launcherPath));
21
+ const postinstall = require(join(packageDir, "postinstall.cjs"));
22
+
23
+ if (process.platform !== "win32" || !postinstall.commandsAreCurrent({ packageDir })) {
24
+ // A shell's, a launcher's or the user's own call to the completion code is left to do its job alone.
25
+ const setUpCompletion = !postinstall.COMPLETION_FLAGS.includes(process.argv[2]);
26
+ postinstall.setUp({ packageDir, repairOnly: false, setUpCompletion });
27
+ }
28
+
29
+ const result = spawnSync(postinstall.commandTarget({ packageDir, command: basename(launcherPath) }), process.argv.slice(2), { stdio: "inherit" });
30
+ if (result.error) {
31
+ console.error(result.error.message);
32
+ process.exit(1);
33
+ }
34
+ process.exit(result.status === null ? 1 : result.status);
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,18 @@
1
+ import { Effect, Runtime, pipe } from "effect";
2
+ import { BunRuntime, BunServices } from "@effect/platform-bun";
3
+ import { Cli } from "jive-abstract-library";
4
+ import { version } from "../../package.json";
5
+ import { cicd } from "../internal/commands/cicd";
6
+ import { create } from "../internal/commands/create";
7
+ import { dev } from "../internal/commands/dev";
8
+ import { CLI_CMD_NAME } from "../internal/common/constants";
9
+ const cli = Cli.make(CLI_CMD_NAME, { cicd, create, dev });
10
+ BunRuntime.runMain(pipe(Cli.run(cli, { version }), Effect.provide(Cli.terminalLogger), Effect.provide(BunServices.layer)), {
11
+ // Exit as soon as the command is done, whatever it leaves open (an HTTP client's idle connections): a pipeline
12
+ // step waits for the process, not for the command.
13
+ teardown: (exit, onExit) => Runtime.defaultTeardown(exit, (code) => {
14
+ onExit(code);
15
+ process.exit(code);
16
+ }),
17
+ });
18
+ //# sourceMappingURL=jive-app-github-pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jive-app-github-pages.js","sourceRoot":"","sources":["../../../../src/entrypoints/jive-app-github-pages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAE1D,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE;IACzH,+GAA+G;IAC/G,mDAAmD;IACnD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;QACjE,MAAM,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;CACH,CAAC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The public surface of this abstract: the package.json shape a site extending it must have, and its scaffold. The
3
+ * hooks themselves ship as the `jive-app-github-pages` command.
4
+ */
5
+ export { ABSTRACT_KEY, AppGithubPagesSchema, DEPLOY_TOKEN_SECRET, JivePackageConfig, PackageJsonSchema, crossFieldErrors, siteDeployTarget, } from "./internal/public/manifest";
6
+ export { scaffoldFiles } from "./internal/public/scaffold";
7
+ export { customDomainUrl, githubIoUrl } from "./internal/public/site-url";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GAIjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAA0C,MAAM,4BAA4B,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Effect } from "effect";
2
+ import { makeCicdCommand } from "../../common/command";
3
+ import { appGithubPagesModules } from "../../modules";
4
+ import { ABSTRACT_KEY } from "../../public/manifest";
5
+ export const audit = makeCicdCommand("audit", "check the build left a site ready to publish: index.html, .nojekyll and the CNAME file the config asks for", function* () {
6
+ const config = (yield* (yield* appGithubPagesModules.Package).load()).jive[ABSTRACT_KEY];
7
+ yield* (yield* appGithubPagesModules.Site).check(config);
8
+ yield* Effect.log(`${config.outputDir} is ready to publish`);
9
+ });
10
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../../../../src/internal/commands/cicd/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,MAAM,KAAK,GAAG,eAAe,CAClC,OAAO,EACP,4GAA4G,EAC5G,QAAQ,CAAC;IACP,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzF,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACzD,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,SAAS,sBAAsB,CAAC,CAAC;AAC/D,CAAC,CACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { makeCicdCommand } from "../../common/command";
2
+ import { appGithubPagesModules } from "../../modules";
3
+ import { ABSTRACT_KEY } from "../../public/manifest";
4
+ export const build = makeCicdCommand("build", "run the package's build script, then add the CNAME and .nojekyll files GitHub Pages reads", function* () {
5
+ const config = (yield* (yield* appGithubPagesModules.Package).load()).jive[ABSTRACT_KEY];
6
+ yield* (yield* appGithubPagesModules.Site).build(config);
7
+ });
8
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../../../src/internal/commands/cicd/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,MAAM,KAAK,GAAG,eAAe,CAClC,OAAO,EACP,2FAA2F,EAC3F,QAAQ,CAAC;IACP,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzF,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC,CACF,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { Effect, Option } from "effect";
2
+ import { makeDeployPlanCommand } from "../../common/command";
3
+ import { appGithubPagesModules } from "../../modules";
4
+ import { ABSTRACT_KEY, siteDeployTarget } from "../../public/manifest";
5
+ import { customDomainUrl, githubIoUrl } from "../../public/site-url";
6
+ export const deployPlan = makeDeployPlanCommand("deploy-plan", "plan a deploy to the URL GitHub Pages serves this site at", function* ({ environment, context }) {
7
+ const { jive } = yield* (yield* appGithubPagesModules.Package).load();
8
+ const target = siteDeployTarget(jive.cicd);
9
+ if (Option.isNone(target) || target.value.environment !== environment) {
10
+ return yield* Effect.fail(`"${environment}" is not the environment this package deploys its site to`);
11
+ }
12
+ const { domain } = jive[ABSTRACT_KEY];
13
+ const url = Option.isSome(domain)
14
+ ? customDomainUrl({ domain: domain.value, servesHttps: yield* (yield* appGithubPagesModules.HttpsProbe).servesHttps(domain.value) })
15
+ : githubIoUrl(context.repository);
16
+ yield* Effect.log(`${environment} is served at ${url}`);
17
+ return { deploy: true, url };
18
+ });
19
+ //# sourceMappingURL=deploy-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy-plan.js","sourceRoot":"","sources":["../../../../../../src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AO,CAAC,UAAU,CAAC,CAAC;IACpC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,iBAAiB,GAAG,EAAE,CAAC,CAAC;IACxD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAW,CAAC;AACxC,CAAC,CACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { makeDeployCommand } from "../../common/command";
2
+ import { readDeployToken } from "../../common/deploy-token";
3
+ import { appGithubPagesModules } from "../../modules";
4
+ export const deploy = makeDeployCommand("deploy", "publish the built site to the gh-pages branch and wait for GitHub Pages to build it", function* ({ environment, context }) {
5
+ const token = yield* readDeployToken();
6
+ yield* (yield* appGithubPagesModules.Deployer).deploy({ environment, context, token });
7
+ });
8
+ //# sourceMappingURL=deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../../../../src/internal/commands/cicd/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,CAAC,MAAM,MAAM,GAAG,iBAAiB,CACrC,QAAQ,EACR,qFAAqF,EACrF,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,eAAe,EAAE,CAAC;IACvC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AACzF,CAAC,CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Schema } from "effect";
2
+ import { makeCicdCommand } from "../../common/command";
3
+ import { appGithubPagesModules } from "../../modules";
4
+ import { JivePackageConfig } from "../../public/manifest";
5
+ export const getConfig = makeCicdCommand("get-config", "print this package's validated jive config as JSON for the pipeline's context job", function* () {
6
+ const { jive } = yield* (yield* appGithubPagesModules.Package).load();
7
+ process.stdout.write(`${JSON.stringify(Schema.encodeUnknownSync(JivePackageConfig)(jive))}\n`);
8
+ });
9
+ //# sourceMappingURL=get-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-config.js","sourceRoot":"","sources":["../../../../../../src/internal/commands/cicd/get-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CACtC,YAAY,EACZ,mFAAmF,EACnF,QAAQ,CAAC;IACP,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACtE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AACjG,CAAC,CACF,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { audit } from "./audit";
2
+ import { build } from "./build";
3
+ import { deploy } from "./deploy";
4
+ import { deployPlan } from "./deploy-plan";
5
+ import { getConfig } from "./get-config";
6
+ import { uploadArtifacts } from "./upload-artifacts";
7
+ /** The hooks invoked by Jive's reusable CI/CD pipeline, by the names `CICD_API.md` gives them. */
8
+ export const cicd = {
9
+ "get-config": getConfig,
10
+ build,
11
+ audit,
12
+ "deploy-plan": deployPlan,
13
+ "upload-artifacts": uploadArtifacts,
14
+ deploy,
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/internal/commands/cicd/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,kGAAkG;AAClG,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,YAAY,EAAE,SAAS;IACvB,KAAK;IACL,KAAK;IACL,aAAa,EAAE,UAAU;IACzB,kBAAkB,EAAE,eAAe;IACnC,MAAM;CACP,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Effect } from "effect";
2
+ import { makePipelineCommand } from "../../common/command";
3
+ export const uploadArtifacts = makePipelineCommand("upload-artifacts", "no-op: the pipeline's own artifact carries the built site to the deploy job", function* (context) {
4
+ yield* Effect.log(`Nothing to upload for ${context.repository.owner}/${context.repository.name}`);
5
+ });
6
+ //# sourceMappingURL=upload-artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-artifacts.js","sourceRoot":"","sources":["../../../../../../src/internal/commands/cicd/upload-artifacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAChD,kBAAkB,EAClB,6EAA6E,EAC7E,QAAQ,CAAC,EAAE,OAAO;IAChB,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,OAAO,CAAC,UAAU,CAAC,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;AACpG,CAAC,CACF,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { Effect, Option, pipe } from "effect";
2
+ import { effunct } from "effective-modules";
3
+ import { Cli } from "jive-abstract-library";
4
+ import { basename, resolve } from "node:path";
5
+ import { version } from "../../../package.json";
6
+ import { layerLive } from "../common/layer";
7
+ import { appGithubPagesModules } from "../modules";
8
+ const USAGE = "usage: jive-app-github-pages create <directory> [--name <package>] [--domain <hostname>] [--skip-install]";
9
+ /** `jive-app-github-pages create <directory>`: scaffolds a new package extending this abstract. */
10
+ export const create = Cli.command({
11
+ description: "create a new static site package served by GitHub Pages",
12
+ flags: {
13
+ name: Cli.flag.string({ description: "the package's npm name (default: the directory's name)" }),
14
+ domain: Cli.flag.string({ description: 'the custom domain to serve it at, e.g. "docs.example.com" (default: none, served at <owner>.github.io/<repository>)' }),
15
+ "skip-install": Cli.flag.boolean({ description: "only write the files; skip bun install" }),
16
+ },
17
+ *run({ flags, args }) {
18
+ const directoryArg = args[0];
19
+ if (directoryArg === undefined || args.length > 1) {
20
+ return yield* Effect.andThen(Effect.logError(USAGE), Effect.fail(new Cli.CliError({ message: USAGE, exitCode: 2 })));
21
+ }
22
+ const directory = resolve(directoryArg);
23
+ const scaffold = { packageName: Option.getOrElse(flags.name, () => basename(directory)), domain: flags.domain, abstractVersion: version };
24
+ yield* pipe(effunct(function* () {
25
+ const written = yield* (yield* appGithubPagesModules.Scaffold).create({ directory, scaffold, install: !flags["skip-install"] });
26
+ yield* Effect.log(`Wrote ${written.length} files into ${directory}:\n ${written.join("\n ")}`);
27
+ })(), Effect.provide(layerLive),
28
+ // Cli.run leaves printing a command's own failure to the command, as the hooks do.
29
+ Effect.catch((failure) => Effect.andThen(Effect.logError(`✗ ${failure}`), Effect.fail(new Cli.CliError({ message: failure, exitCode: 1 })))));
30
+ },
31
+ });
32
+ //# sourceMappingURL=create.js.map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ect } from "effect";
2
+ import { Cli, runDevServer } from "jive-abstract-library";
3
+ import { PackageJsonSchema } from "../public/manifest";
4
+ /** `jive-app-github-pages dev`: keeps the package's package.schema.json current while its package.json is edited. */
5
+ export const dev = Cli.command({
6
+ description: "watch this package and keep its generated package.schema.json current while you work",
7
+ *run() {
8
+ yield* Effect.promise(() => runDevServer({ genPackageJsonSchema: Effect.succeed(PackageJsonSchema), watchPaths: ["package.json"] }));
9
+ },
10
+ });
11
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../../src/internal/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,qHAAqH;AACrH,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;IAC7B,WAAW,EAAE,sFAAsF;IACnG,CAAC,GAAG;QACF,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;IACvI,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { makeCicdCommandFactory } from "jive-abstract-library";
2
+ import { layerLive } from "./layer";
3
+ /** Every hook runs against this abstract's whole module graph, platform services included. */
4
+ export const { makeCicdCommand, makePipelineCommand, makeDeployCommand, makeDeployPlanCommand } = makeCicdCommandFactory(layerLive);
5
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../../src/internal/common/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAA2B,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,8FAA8F;AAC9F,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,GAC7F,sBAAsB,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ export const CLI_CMD_NAME = "jive-app-github-pages";
2
+ /** The package this abstract ships as, which a scaffolded package gets as a dev dependency. */
3
+ export const ABSTRACT_PACKAGE_NAME = "jive-abstract-app-github-pages";
4
+ /**
5
+ * The branch the deploy publishes the site to, at its root. GitHub Pages serves it when the repository's Pages
6
+ * source is this branch and `/`
7
+ * (https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site).
8
+ */
9
+ export const PUBLISHING_BRANCH = "gh-pages";
10
+ export const PUBLISHING_PATH = "/";
11
+ /**
12
+ * Where the deploy keeps the git repository it publishes the site from, relative to the package. Under
13
+ * `node_modules/.cache`, so no package has to ignore it, and rebuilt by every deploy.
14
+ */
15
+ export const PUBLISHING_GIT_DIR = "node_modules/.cache/jive-app-github-pages/publishing.git";
16
+ /** Files the build adds to the site, which GitHub Pages reads rather than serves as pages. */
17
+ export const SITE_FILES = {
18
+ /** Holds the custom domain; a branch-published site's domain is whatever this file names. */
19
+ customDomain: "CNAME",
20
+ /**
21
+ * Tells GitHub Pages the branch needs no Jekyll build
22
+ * (https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site).
23
+ * Jekyll would otherwise leave out every file and folder starting with `_`, such as Astro's `_astro/`
24
+ * (https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll).
25
+ */
26
+ disableJekyll: ".nojekyll",
27
+ };
28
+ /** The page every built site must have, since GitHub Pages serves it at the site's root. */
29
+ export const SITE_INDEX_FILE = "index.html";
30
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/internal/common/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAEpD,+FAA+F;AAC/F,MAAM,CAAC,MAAM,qBAAqB,GAAG,gCAAgC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,0DAA0D,CAAC;AAE7F,8FAA8F;AAC9F,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,6FAA6F;IAC7F,YAAY,EAAE,OAAO;IACrB;;;;;OAKG;IACH,aAAa,EAAE,WAAW;CAClB,CAAC;AAEX,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { Effect, Redacted } from "effect";
2
+ import { DEPLOY_TOKEN_SECRET } from "../public/manifest";
3
+ /**
4
+ * The deploy token, which the pipeline exports into the environment because the package lists it in
5
+ * `cicd.requiredSecrets`. Read once, at the hook's boundary, and passed on as a `Redacted` value so it never
6
+ * reaches a log.
7
+ */
8
+ export function* readDeployToken() {
9
+ const token = process.env[DEPLOY_TOKEN_SECRET];
10
+ if (token === undefined || token === "") {
11
+ return yield* Effect.fail(`${DEPLOY_TOKEN_SECRET} is not set. Jive's pipeline exports it for this hook when package.json lists it in `
12
+ + `jive.cicd.requiredSecrets and the repository has a GitHub Actions secret of that name: a fine-grained token `
13
+ + `limited to the repository, with Contents read and write and Pages read`);
14
+ }
15
+ return Redacted.make(token);
16
+ }
17
+ //# sourceMappingURL=deploy-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy-token.js","sourceRoot":"","sources":["../../../../../src/internal/common/deploy-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,SAAS,CAAC,CAAC,eAAe;IAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC/C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CACvB,GAAG,mBAAmB,sFAAsF;cAC1G,8GAA8G;cAC9G,wEAAwE,CAC3E,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Layer, pipe } from "effect";
2
+ import { FetchHttpClient } from "effect/http";
3
+ import { BunFileSystem } from "@effect/platform-bun";
4
+ import { OSPlatformImpl } from "jive-abstract-library";
5
+ import { DeployerImpl } from "../modules/deployer/impl";
6
+ import { HttpsProbeImpl } from "../modules/https-probe/impl";
7
+ import { PackageImpl } from "../modules/package/impl";
8
+ import { PagesApiImpl } from "../modules/pages-api/impl";
9
+ import { PublishingBranchImpl } from "../modules/publishing-branch/impl";
10
+ import { ScaffoldImpl } from "../modules/scaffold/impl";
11
+ import { SiteImpl } from "../modules/site/impl";
12
+ /** Every module this abstract owns, composed most-dependent first. */
13
+ export const layerLive = pipe(DeployerImpl.Layer, Layer.provideMerge(ScaffoldImpl.Layer), Layer.provideMerge(PublishingBranchImpl.Layer), Layer.provideMerge(PagesApiImpl.Layer), Layer.provideMerge(HttpsProbeImpl.Layer), Layer.provideMerge(SiteImpl.Layer), Layer.provideMerge(PackageImpl.Layer), Layer.provideMerge(OSPlatformImpl.Layer), Layer.provideMerge(FetchHttpClient.layer), Layer.provideMerge(BunFileSystem.layer));
14
+ //# sourceM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,CAAC,KAAK,CAAC,CACD,CAAC"}
@@ -0,0 +1,111 @@
1
+ import { Duration, Effect, Option } from "effect";
2
+ import { implementing } from "effective-modules";
3
+ import { PUBLISHING_BRANCH, PUBLISHING_PATH } from "../../common/constants";
4
+ import { ABSTRACT_KEY, DEPLOY_TOKEN_SECRET, siteDeployTarget } from "../../public/manifest";
5
+ import { appGithubPagesModules } from "../index";
6
+ /** How often the deploy reads the latest build while waiting, and how long it waits in all. */
7
+ export const BUILD_POLL_INTERVAL = Duration.seconds(5);
8
+ export const BUILD_TIMEOUT = Duration.minutes(10);
9
+ const FINAL_BUILD_STATUSES = ["built", "errored"];
10
+ /** Why a repository's Pages settings would not serve the publishing branch, or nothing when they would. */
11
+ function sourceProblem(site) {
12
+ const source = Option.getOrUndefined(site.source);
13
+ const buildType = Option.getOrUndefined(site.buildType);
14
+ if (buildType === "legacy" && source?.branch === PUBLISHING_BRANCH && source.path === PUBLISHING_PATH)
15
+ return Option.none();
16
+ return Option.some(`its Pages source is ${buildType === "workflow"
17
+ ? "GitHub Actions"
18
+ : source === undefined ? "not set" : `the branch ${source.branch} at ${source.path}`}, not the branch ${PUBLISHING_BRANCH} at ${PUBLISHING_PATH}`);
19
+ }
20
+ export class DeployerImpl extends implementing(appGithubPagesModules.Deployer)
21
+ .uses(appGithubPagesModules.Package, appGithubPagesModules.Site, appGithubPagesModules.PublishingBranch, appGithubPagesModules.PagesApi) {
22
+ *deploy(input) {
23
+ const { Package, Site, PublishingBranch, PagesApi } = this.dependencies;
24
+ const { context, environment, token } = input;
25
+ const packageJson = yield* Package.load();
26
+ const config = packageJson.jive[ABSTRACT_KEY];
27
+ const target = siteDeployTarget(packageJson.jive.cicd);
28
+ if (Option.isNone(target) || target.value.environment !== environment) {
29
+ return yield* Effect.fail(`"${environment}" is not the environment this package deploys its site to${Option.isSome(target) ? ` ("${target.value.environment}")` : "; cicd.deploy.branches deploys nothing"}`);
30
+ }
31
+ yield* Site.check(config);
32
+ const { owner, name } = context.repository;
33
+ const repositoryName = `${owner}/${name}`;
34
+ const api = { repository: context.repository, token };
35
+ const publishInput = {
36
+ siteDir: config.outputDir,
37
+ remote: { url: `https://github.com/${repositoryName}.git`, token: Option.some(token) },
38
+ branch: PUBLISHING_BRANCH,
39
+ message: `Deploy ${repositoryName}@${context.sourceCommitSha} to ${environment}`,
40
+ newCommitWhenUnchanged: false,
41
+ };
42
+ yield* Effect.log(`Publishing ${config.outputDir} to ${repositoryName}'s ${PUBLISHING_BRANCH} branch for ${environment}`);
43
+ const publication = yield* PublishingBranch.publish(publishInput);
44
+ const site = yield* PagesApi.getSite(api);
45
+ const settings = `https://github.com/${repositoryName}/settings/pages`;
46
+ if (Option.isNone(site)) {
47
+ return yield* Effect.fail(`${repositoryName} has no GitHub Pages site, so GitHub serves nothing from ${PUBLISHING_BRANCH}. Enabling one needs a repository administrator, which the deploy token is not: at ${settings}, set the source to "Deploy from a branch", ${PUBLISHING_BRANCH}, ${PUBLISHING_PATH}`);
48
+ }
49
+ const problem = sourceProblem(site.value);
50
+ if (Option.isSome(problem)) {
51
+ return yield* Effect.fail(`${repositoryName}'s GitHub Pages would not serve what this deploy published: ${problem.value}. Changing it needs a repository administrator, which the deploy token is not: at ${settings}, set the source to "Deploy from a branch", ${PUBLISHING_BRANCH}, ${PUBLISHING_PATH}`);
52
+ }
53
+ const awaited = yield* this.commitToAwait({ api, publication, publishInput });
54
+ if (Option.isNone(awaited)) {
55
+ yield* Effect.log(`GitHub Pages has already built ${publication.commitSha}; ${site.value.htmlUrl} serves it`);
56
+ return;
57
+ }
58
+ const build = yield* this.awaitBuild({ api, commitSha: awaited.value });
59
+ if (build.status !== "built") {
60
+ return yield* Effect.fail(`GitHub Pages could not build ${awaited.value}: ${Option.getOrElse(build.errorMessage, () => `its build ended "${build.status}"`)}`);
61
+ }
62
+ yield* Effect.log(`GitHub Pages built ${awaited.value}; ${site.value.htmlUrl} serves it`);
63
+ }
64
+ /**
65
+ * The commit whose Pages build the deploy waits for, or none when GitHub has already built the site. A push starts
66
+ * the build, so a new commit is awaited as it is. When the branch already held this site, nothing was pushed: a
67
+ * build of it that is built or still running is the one, and otherwise (its build failed, or none ever ran) the
68
+ * deploy pushes the same site again as a new commit, which starts a new build.
69
+ */
70
+ *commitToAwait(input) {
71
+ const { PagesApi, PublishingBranch } = this.dependencies;
72
+ const { commitSha, changed } = input.publication;
73
+ if (changed)
74
+ return Option.some(commitSha);
75
+ const latest = yield* PagesApi.latestBuild(input.api);
76
+ if (Option.isSome(latest) && latest.value.commit === commitSha) {
77
+ if (latest.value.status === "built")
78
+ return Option.none();
79
+ if (latest.value.status !== "errored")
80
+ return Option.some(commitSha);
81
+ }
82
+ yield* Effect.log(`${PUBLISHING_BRANCH} already holds this site at ${commitSha}, but GitHub Pages ${Option.match(latest, {
83
+ onNone: () => "has never built it",
84
+ onSome: (build) => build.commit === commitSha ? "failed to build it" : `last built ${build.commit}`,
85
+ })}; pushing it again to start a new build`);
86
+ const republished = yield* PublishingBranch.publish({ ...input.publishInput, newCommitWhenUnchanged: true });
87
+ return Option.some(republished.commitSha);
88
+ }
89
+ *awaitBuild(input) {
90
+ const { PagesApi } = this.dependencies;
91
+ const deadline = Duration.toMillis(BUILD_TIMEOUT);
92
+ let waited = 0;
93
+ for (;;) {
94
+ const latest = yield* PagesApi.latestBuild(input.api);
95
+ if (Option.isSome(latest) && latest.value.commit === input.commitSha && FINAL_BUILD_STATUSES.includes(latest.value.status)) {
96
+ return latest.value;
97
+ }
98
+ if (waited >= deadline) {
99
+ return yield* Effect.fail(Option.isSome(latest) && latest.value.commit === input.commitSha
100
+ ? `GitHub Pages had not finished building ${input.commitSha} after ${Duration.format(BUILD_TIMEOUT)}; its build is ${latest.value.status}`
101
+ : `GitHub Pages started no build of ${input.commitSha} in ${Duration.format(BUILD_TIMEOUT)}; the latest build is ${Option.match(latest, {
102
+ onNone: () => "none",
103
+ onSome: (build) => `of ${build.commit}, ${build.status}`,
104
+ })}. A push starts a build only when ${DEPLOY_TOKEN_SECRET} is a token other than the job's GITHUB_TOKEN`);
105
+ }
106
+ yield* Effect.sleep(BUILD_POLL_INTERVAL);
107
+ waited += Duration.toMillis(BUILD_POLL_INTERVAL);
108
+ }
109
+ }
110
+ }
111
+ //# sourceMappingURL=impl.js.map