@akash-chowdhury-24/deployhub 1.0.8 → 1.0.9

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.9",
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,26 @@ export function getCliInstallSpec(cliSource) {
89
127
  return normalized;
90
128
  }
91
129
 
130
+ /**
131
+ * @returns {string}
132
+ */
133
+ function getGithubGitConfigStep() {
134
+ return ` - name: Configure GitHub access for DeployHub CLI
135
+ env:
136
+ ${GITHUB_CLI_TOKEN_SECRET}: \${{ secrets.${GITHUB_CLI_TOKEN_SECRET} }}
137
+ GITHUB_TOKEN: \${{ github.token }}
138
+ run: |
139
+ TOKEN="\${${GITHUB_CLI_TOKEN_SECRET}:-$GITHUB_TOKEN}"
140
+ if [ -n "$TOKEN" ]; then
141
+ git config --global url."https://oauth2:\${TOKEN}@github.com/".insteadOf "https://github.com/"
142
+ git config --global url."https://oauth2:\${TOKEN}@github.com/".insteadOf "git@github.com:"
143
+ git config --global url."https://oauth2:\${TOKEN}@github.com/".insteadOf "ssh://git@github.com/"
144
+ else
145
+ git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
146
+ git config --global url."https://github.com/".insteadOf "git@github.com:"
147
+ fi`;
148
+ }
149
+
92
150
  /**
93
151
  * @param {import('../core/config.js').DeployHubConfig} [config]
94
152
  * @returns {string[]}
@@ -246,6 +304,9 @@ export function generateWorkflowYaml(
246
304
  const installSpec = getCliInstallSpec(cliSource);
247
305
  const backendSteps = getBackendSetupSteps(config);
248
306
  const uniqueBackendSteps = [...new Set(backendSteps)].join('\n');
307
+ const githubGitConfigStep = isGithubCliSource(cliSource)
308
+ ? `${getGithubGitConfigStep()}\n`
309
+ : '';
249
310
 
250
311
  const envList = deployEnvironments
251
312
  .map((name) => environments[name])
@@ -270,7 +331,7 @@ jobs:
270
331
  ${uniqueBackendSteps ? `${uniqueBackendSteps}\n` : ''} - uses: actions/setup-node@v4
271
332
  with:
272
333
  node-version: '20'
273
- - name: Install project dependencies
334
+ ${githubGitConfigStep} - name: Install project dependencies
274
335
  run: ${installDepsCommand}
275
336
  ${platformSteps ? `${platformSteps}\n` : ''} - name: Install DeployHub CLI
276
337
  run: npm install ${installSpec} --no-save
@@ -391,11 +452,17 @@ export function getRequiredSecrets(
391
452
  storageProviders,
392
453
  deployEnvironments,
393
454
  environments,
394
- config = null
455
+ config = null,
456
+ cliSource = null
395
457
  ) {
396
458
  /** @type {Set<string>} */
397
459
  const secrets = new Set();
398
460
 
461
+ const resolvedCliSource = cliSource || config?.cli?.source;
462
+ if (isGithubCliSource(resolvedCliSource)) {
463
+ secrets.add(GITHUB_CLI_TOKEN_SECRET);
464
+ }
465
+
399
466
  for (const provider of storageProviders) {
400
467
  const keys = PROVIDER_ENV_MAP[provider] || [];
401
468
  keys.forEach((k) => secrets.add(k));