@akash-chowdhury-24/deployhub 1.0.8 → 1.0.10

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": "@akash-chowdhury-24/deployhub",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Zero-configuration deployment and artifact manager",
5
5
  "type": "module",
6
6
  "main": "./src/cli/index.js",
@@ -17,6 +17,8 @@ import {
17
17
  generateEnvExampleContent,
18
18
  guessCliGithubRepo,
19
19
  addDeployhubToPackageJson,
20
+ isGithubCliSource,
21
+ normalizeGithubCliSource,
20
22
  } from '../utils/github-actions.js';
21
23
  import {
22
24
  promptPlatformQuestions,
@@ -452,6 +454,7 @@ export function registerInitCommand(program) {
452
454
  message:
453
455
  'DeployHub CLI source for GitHub Actions (github:user/repo or npm:@akash-chowdhury-24/deployhub):',
454
456
  default: defaultCliRepo,
457
+ filter: (value) => normalizeGithubCliSource(value),
455
458
  },
456
459
  ]);
457
460
 
@@ -781,7 +784,17 @@ export function registerInitCommand(program) {
781
784
  console.log(' • .env.example');
782
785
  console.log('');
783
786
  console.log(chalk.bold('Next steps:'));
784
- console.log(' 1. Push the DeployHub CLI repo to GitHub (if using github: source)');
787
+ if (isGithubCliSource(answers.cliSource)) {
788
+ console.log(
789
+ ' 1. For a private DeployHub CLI repo, create a GitHub PAT with repo read access'
790
+ );
791
+ console.log(
792
+ ` and add it as ${chalk.cyan('DEPLOYHUB_GITHUB_TOKEN')} in your demo project secrets`
793
+ );
794
+ console.log(' (public CLI repos can skip this — HTTPS is used automatically)');
795
+ } else {
796
+ console.log(' 1. Push the DeployHub CLI repo to GitHub (if using github: source)');
797
+ }
785
798
  console.log(' 2. Copy .env.example to .env and fill in credentials');
786
799
  if (secrets.length > 0) {
787
800
  console.log(' 3. Add these secrets to GitHub (Settings → Secrets):');
@@ -61,6 +61,44 @@ const ENV_VAR_DEFAULTS = {
61
61
 
62
62
  const NPM_PACKAGE = '@akash-chowdhury-24/deployhub';
63
63
  const DEFAULT_NPM_CLI_SOURCE = `npm:${NPM_PACKAGE}`;
64
+ export const GITHUB_CLI_TOKEN_SECRET = 'DEPLOYHUB_GITHUB_TOKEN';
65
+
66
+ /**
67
+ * @param {string} [cliSource]
68
+ * @returns {boolean}
69
+ */
70
+ export function isGithubCliSource(cliSource) {
71
+ const normalized = normalizeCliSource(cliSource);
72
+ return normalized.startsWith('github:');
73
+ }
74
+
75
+ /**
76
+ * Normalizes common GitHub remote formats to github:user/repo.
77
+ * @param {string} cliSource
78
+ * @returns {string}
79
+ */
80
+ export function normalizeGithubCliSource(cliSource) {
81
+ if (!cliSource) return cliSource;
82
+
83
+ const trimmed = cliSource.trim();
84
+ const httpsMatch = trimmed.match(
85
+ /^https?:\/\/github\.com\/([^/]+)\/([^/#?]+?)(?:\.git)?(?:[/?#].*)?$/
86
+ );
87
+ if (httpsMatch) {
88
+ return `github:${httpsMatch[1]}/${httpsMatch[2]}`;
89
+ }
90
+
91
+ const sshMatch = trimmed.match(/^git@github\.com:([^/]+)\/([^/#?]+?)(?:\.git)?$/);
92
+ if (sshMatch) {
93
+ return `github:${sshMatch[1]}/${sshMatch[2]}`;
94
+ }
95
+
96
+ if (trimmed.startsWith('github:')) {
97
+ return trimmed.replace(/^github:/, 'github:').replace(/\.git$/, '');
98
+ }
99
+
100
+ return trimmed;
101
+ }
64
102
 
65
103
  /** @param {string} [cliSource] */
66
104
  function normalizeCliSource(cliSource) {
@@ -68,7 +106,7 @@ function normalizeCliSource(cliSource) {
68
106
  if (/^npm:(deployhub-cli|deploy-hub-cli|deployhub)$/.test(cliSource)) {
69
107
  return DEFAULT_NPM_CLI_SOURCE;
70
108
  }
71
- return cliSource;
109
+ return normalizeGithubCliSource(cliSource);
72
110
  }
73
111
 
74
112
  /**
@@ -89,6 +127,34 @@ export function getCliInstallSpec(cliSource) {
89
127
  return normalized;
90
128
  }
91
129
 
130
+ /**
131
+ * npm/npx command to run deployhub build using the installed scoped package.
132
+ * @returns {string}
133
+ */
134
+ export function getCliBuildCommand() {
135
+ return `npx --no-install ${NPM_PACKAGE} build`;
136
+ }
137
+
138
+ /**
139
+ * @returns {string}
140
+ */
141
+ function getGithubGitConfigStep() {
142
+ return ` - name: Configure GitHub access for DeployHub CLI
143
+ env:
144
+ ${GITHUB_CLI_TOKEN_SECRET}: \${{ secrets.${GITHUB_CLI_TOKEN_SECRET} }}
145
+ GITHUB_TOKEN: \${{ github.token }}
146
+ run: |
147
+ TOKEN="\${${GITHUB_CLI_TOKEN_SECRET}:-$GITHUB_TOKEN}"
148
+ if [ -n "$TOKEN" ]; then
149
+ git config --global url."https://oauth2:\${TOKEN}@github.com/".insteadOf "https://github.com/"
150
+ git config --global url."https://oauth2:\${TOKEN}@github.com/".insteadOf "git@github.com:"
151
+ git config --global url."https://oauth2:\${TOKEN}@github.com/".insteadOf "ssh://git@github.com/"
152
+ else
153
+ git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
154
+ git config --global url."https://github.com/".insteadOf "git@github.com:"
155
+ fi`;
156
+ }
157
+
92
158
  /**
93
159
  * @param {import('../core/config.js').DeployHubConfig} [config]
94
160
  * @returns {string[]}
@@ -246,6 +312,9 @@ export function generateWorkflowYaml(
246
312
  const installSpec = getCliInstallSpec(cliSource);
247
313
  const backendSteps = getBackendSetupSteps(config);
248
314
  const uniqueBackendSteps = [...new Set(backendSteps)].join('\n');
315
+ const githubGitConfigStep = isGithubCliSource(cliSource)
316
+ ? `${getGithubGitConfigStep()}\n`
317
+ : '';
249
318
 
250
319
  const envList = deployEnvironments
251
320
  .map((name) => environments[name])
@@ -270,11 +339,11 @@ jobs:
270
339
  ${uniqueBackendSteps ? `${uniqueBackendSteps}\n` : ''} - uses: actions/setup-node@v4
271
340
  with:
272
341
  node-version: '20'
273
- - name: Install project dependencies
342
+ ${githubGitConfigStep} - name: Install project dependencies
274
343
  run: ${installDepsCommand}
275
344
  ${platformSteps ? `${platformSteps}\n` : ''} - name: Install DeployHub CLI
276
345
  run: npm install ${installSpec} --no-save
277
- - run: npx deployhub build
346
+ - run: ${getCliBuildCommand()}
278
347
  env:
279
348
  ${envBlock}
280
349
  `;
@@ -391,11 +460,17 @@ export function getRequiredSecrets(
391
460
  storageProviders,
392
461
  deployEnvironments,
393
462
  environments,
394
- config = null
463
+ config = null,
464
+ cliSource = null
395
465
  ) {
396
466
  /** @type {Set<string>} */
397
467
  const secrets = new Set();
398
468
 
469
+ const resolvedCliSource = cliSource || config?.cli?.source;
470
+ if (isGithubCliSource(resolvedCliSource)) {
471
+ secrets.add(GITHUB_CLI_TOKEN_SECRET);
472
+ }
473
+
399
474
  for (const provider of storageProviders) {
400
475
  const keys = PROVIDER_ENV_MAP[provider] || [];
401
476
  keys.forEach((k) => secrets.add(k));