@rathnasgala/cli 1.1.18 → 1.1.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rathnasgala/cli",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -83,24 +83,25 @@ export async function domain({ terminal, options, cwd = process.cwd() }) {
83
83
  }
84
84
 
85
85
  if (action === 'check') {
86
+ const site = await ownedSite(api, publication.siteId);
86
87
  if (pending.cname && pending.state === 'PREPARED') {
87
88
  let configured;
88
89
  try {
89
- configured = await api.configureTopologyChange(publication.siteId, pending.changeId);
90
+ configured = await configureWithRetry(api, publication.siteId, pending.changeId, terminal);
90
91
  } catch (failure) {
91
- if (!(failure instanceof HttpError)
92
- || failure.code !== 'GITHUB_PAGES_DOMAIN_VERIFICATION_REQUIRED') throw failure;
93
- const site = await ownedSite(api, publication.siteId);
94
- const owner = site.repository.split('/')[0];
95
- showVerificationSteps(terminal, pending.cname, owner, profile.metadata.githubLogin);
96
- throw new Error(`GitHub has not verified ${pending.cname} for @${owner} yet. Complete the steps above, then retry.`);
92
+ handleDomainFailure(failure, terminal, pending, site, profile.metadata.githubLogin);
97
93
  }
98
94
  terminal.done(`GitHub verified ${configured.cname}`);
99
95
  terminal.note(dnsInstruction(configured.cname, await providerHost(api, publication.siteId)));
100
96
  terminal.note(`After DNS propagates, run: ${cliCommand('domain check')}`);
101
97
  return configured;
102
98
  }
103
- const committed = await api.commitTopologyChange(publication.siteId, pending.changeId);
99
+ let committed;
100
+ try {
101
+ committed = await api.commitTopologyChange(publication.siteId, pending.changeId);
102
+ } catch (failure) {
103
+ handleDomainFailure(failure, terminal, pending, site, profile.metadata.githubLogin);
104
+ }
104
105
  terminal.done(committed.cname
105
106
  ? `${committed.cname} is live with enforced HTTPS`
106
107
  : 'The GitHub Pages address is live again');
@@ -113,6 +114,60 @@ export async function domain({ terminal, options, cwd = process.cwd() }) {
113
114
  throw new UsageError(`Unsupported domain action: ${action}`);
114
115
  }
115
116
 
117
+ async function configureWithRetry(api, siteId, changeId, terminal) {
118
+ const attempts = 5;
119
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
120
+ try {
121
+ return await api.configureTopologyChange(siteId, changeId);
122
+ } catch (failure) {
123
+ const waiting = failure instanceof HttpError && [
124
+ 'GITHUB_PAGES_DOMAIN_VERIFICATION_REQUIRED',
125
+ 'GITHUB_PAGES_DOMAIN_PROPAGATION_PENDING',
126
+ ].includes(failure.code);
127
+ if (!waiting || attempt === attempts) throw failure;
128
+ if (attempt === 1) terminal.step('Waiting for GitHub Pages to finish applying the domain');
129
+ await new Promise((resolve) => setTimeout(resolve, 500));
130
+ }
131
+ }
132
+ throw new Error('GitHub Pages domain check ended unexpectedly');
133
+ }
134
+
135
+ function handleDomainFailure(failure, terminal, pending, site, login) {
136
+ if (!(failure instanceof HttpError)) throw failure;
137
+ const [owner, repository] = site.repository.split('/');
138
+ const retry = cliCommand('domain check');
139
+ const address = pending.cname ?? 'the GitHub Pages address';
140
+ switch (failure.code) {
141
+ case 'GITHUB_PAGES_DOMAIN_VERIFICATION_REQUIRED':
142
+ showVerificationSteps(terminal, pending.cname, owner, login);
143
+ throw new Error(`GitHub still reports ${pending.cname} as unverified for @${owner}. If GitHub already shows “Verified”, wait for Pages to update, then run: ${retry}`);
144
+ case 'GITHUB_PAGES_DOMAIN_PROPAGATION_PENDING':
145
+ throw new Error(`GitHub accepted ${address} and is still updating Pages. Wait briefly, then run: ${retry}`);
146
+ case 'GITHUB_PAGES_DNS_PENDING':
147
+ terminal.note(dnsInstruction(pending.cname, `${owner.toLowerCase()}.github.io`));
148
+ throw new Error(`GitHub is still checking DNS for ${pending.cname}. After it propagates, run: ${retry}`);
149
+ case 'GITHUB_PAGES_DNS_INVALID':
150
+ terminal.note(dnsInstruction(pending.cname, `${owner.toLowerCase()}.github.io`));
151
+ throw new Error(`GitHub rejected the DNS records for ${pending.cname}. Correct them, then run: ${retry}`);
152
+ case 'GITHUB_PAGES_PERMISSION_REQUIRED':
153
+ terminal.openUrl(owner.toLowerCase() === login.toLowerCase()
154
+ ? 'https://github.com/settings/installations'
155
+ : `https://github.com/organizations/${encodeURIComponent(owner)}/settings/installations`);
156
+ throw new Error(`The Gala GitHub App needs Pages and Administration access to ${owner}/${repository}. Grant it, then run: ${retry}`);
157
+ case 'GITHUB_PAGES_DOMAIN_REJECTED':
158
+ terminal.openUrl(`https://github.com/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/settings/pages`);
159
+ throw new Error(`GitHub rejected ${address}. Review the repository’s Pages settings, then run: ${retry}`);
160
+ case 'GITHUB_PAGES_TOPOLOGY_NOT_READY':
161
+ throw new Error(`GitHub Pages has not finished applying ${address}. Wait briefly, then run: ${retry}`);
162
+ case 'GITHUB_PAGES_VERIFICATION_UNAVAILABLE':
163
+ throw new Error(`GitHub Pages is temporarily unavailable. Your pending change is preserved; run later: ${retry}`);
164
+ case 'SITE_TOPOLOGY_STATE_CONFLICT':
165
+ throw new Error(`This domain change is no longer in the expected state. Inspect it with: ${cliCommand('domain status')}`);
166
+ default:
167
+ throw failure;
168
+ }
169
+ }
170
+
116
171
  function showVerificationSteps(terminal, host, owner, login) {
117
172
  terminal.note(`GitHub owner @${owner} must verify ${host} once under Settings → Pages → Verified domains.`);
118
173
  terminal.openUrl(owner.toLowerCase() === login.toLowerCase()