Skip to content

Commit

Permalink
Attach Hydrogen Version Metadata to Deployment (#2645)
Browse files Browse the repository at this point in the history
* send hydrogen version metadata in deploy

* bump oxygen-cli version
  • Loading branch information
benwolfram authored Dec 5, 2024
1 parent 23a80f3 commit f88f4a0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-crabs-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Attach Hydrogen version metadata to deployments
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@ast-grep/napi": "0.11.0",
"@oclif/core": "3.26.5",
"@shopify/cli-kit": "3.69.3",
"@shopify/oxygen-cli": "4.5.3",
"@shopify/oxygen-cli": "4.6.0",
"@shopify/plugin-cloudflare": "3.69.3",
"ansi-escapes": "^6.2.0",
"chokidar": "3.5.3",
Expand Down
39 changes: 37 additions & 2 deletions packages/cli/src/commands/hydrogen/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ import {
getLatestGitCommit,
GitDirectoryNotCleanError,
} from '@shopify/cli-kit/node/git';
import {createRequire} from 'node:module';

import {deploymentLogger, runDeploy} from './deploy.js';
import {deploymentLogger, getHydrogenVersion, runDeploy} from './deploy.js';
import {getOxygenDeploymentData} from '../../lib/get-oxygen-deployment-data.js';
import {execAsync} from '../../lib/process.js';
import {createEnvironmentCliChoiceLabel} from '../../lib/common.js';
import {getSkeletonSourceDir} from '../../lib/build.js';
import {
CompletedDeployment,
createDeploy,
parseToken,
} from '@shopify/oxygen-cli/deploy';
import {ciPlatform} from '@shopify/cli-kit/node/context/local';
import {runBuild} from './build.js';
import {PackageJson} from 'type-fest';

vi.mock('@shopify/oxygen-cli/deploy');
vi.mock('@shopify/cli-kit/node/dot-env');
Expand Down Expand Up @@ -61,7 +64,21 @@ vi.mock('@shopify/cli-kit/node/git', async () => {
};
});

describe('deploy', () => {
async function createHydrogenDependencyPackageJson(version?: string) {
const require = createRequire(import.meta.url);
const packageJson: PackageJson = require(require.resolve(
'@shopify/hydrogen/package.json',
{paths: [getSkeletonSourceDir()]},
));

packageJson.version = version;

return packageJson;
}

describe('deploy', async () => {
await createHydrogenDependencyPackageJson('2000.1.1');

const ADMIN_SESSION: AdminSession = {
token: 'abc123',
storeFqdn: 'my-shop.myshopify.com',
Expand Down Expand Up @@ -119,6 +136,7 @@ describe('deploy', () => {
url: deployParams.metadataUrl,
user: deployParams.metadataUser,
version: deployParams.metadataVersion,
hydrogenVersion: '2000.1.1',
},
skipVerification: true,
rootPath: deployParams.path,
Expand Down Expand Up @@ -163,6 +181,7 @@ describe('deploy', () => {
oxygenDeploymentToken: 'some-encoded-token',
environments: [],
});

vi.mocked(parseToken).mockReturnValue(mockToken);
});

Expand Down Expand Up @@ -943,4 +962,20 @@ describe('deploy', () => {
});
});
});

describe('getHydrogenVersion', () => {
it('returns the version', async () => {
const version = await getHydrogenVersion({appPath: deployParams.path});
expect(version).toBe('2000.1.1');
});

describe('when there are no version is available', () => {
it('returns undefined', async () => {
await createHydrogenDependencyPackageJson(undefined);

const version = await getHydrogenVersion({appPath: deployParams.path});
expect(version).toBeUndefined();
});
});
});
});
26 changes: 23 additions & 3 deletions packages/cli/src/commands/hydrogen/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from '@shopify/cli-kit/node/output';
import {readAndParseDotEnv} from '@shopify/cli-kit/node/dot-env';
import {AbortError} from '@shopify/cli-kit/node/error';
import {writeFile} from '@shopify/cli-kit/node/fs';
import {readFile, writeFile} from '@shopify/cli-kit/node/fs';
import {
ensureIsClean,
getLatestGitCommit,
GitDirectoryNotCleanError,
} from '@shopify/cli-kit/node/git';
import {relativePath, resolvePath} from '@shopify/cli-kit/node/path';
import {joinPath, relativePath, resolvePath} from '@shopify/cli-kit/node/path';
import {
renderConfirmationPrompt,
renderSelectPrompt,
Expand All @@ -32,6 +32,7 @@ import {
DeploymentVerificationDetailsResponse,
parseToken,
} from '@shopify/oxygen-cli/deploy';
import {createRequire} from 'node:module';

import {
createEnvironmentCliChoiceLabel,
Expand All @@ -51,7 +52,7 @@ import {runClassicCompilerBuild} from '../../lib/classic-compiler/build.js';
import {runBuild} from './build.js';
import {getViteConfig} from '../../lib/vite-config.js';
import {prepareDiffDirectory} from '../../lib/template-diff.js';
import {isClassicProject} from '../../lib/remix-config.js';
import {getProjectPaths, isClassicProject} from '../../lib/remix-config.js';
import {packageManagers} from '../../lib/package-managers.js';
import {setupResourceCleanup} from '../../lib/resource-cleanup.js';

Expand Down Expand Up @@ -466,6 +467,8 @@ export async function runDeploy(
}
}

const metadataHydrogenVersion = await getHydrogenVersion({appPath: root});

const config: DeploymentConfig = {
assetsDir,
bugsnag: true,
Expand All @@ -484,6 +487,9 @@ export async function runDeploy(
...(metadataUrl ? {url: metadataUrl} : {}),
...(metadataUser ? {user: metadataUser} : {}),
...(metadataVersion ? {version: metadataVersion} : {}),
...(metadataHydrogenVersion
? {hydrogenVersion: metadataHydrogenVersion}
: {}),
},
skipVerification: noVerify,
rootPath: root,
Expand Down Expand Up @@ -673,3 +679,17 @@ Continue?`.value,

return deployPromise;
}

/**
* Gets the current @shopify/hydrogen version from the package's package.json
*/
export async function getHydrogenVersion({appPath}: {appPath: string}) {
const {root} = getProjectPaths(appPath);

const require = createRequire(import.meta.url);
const {version} = require(require.resolve('@shopify/hydrogen/package.json', {
paths: [root],
}));

return version;
}

0 comments on commit f88f4a0

Please sign in to comment.