Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach Hydrogen Version Metadata to Deployment #2645

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benwolfram
Copy link
Contributor

WHY are these changes introduced?

We are looking to attach metadata to each deployment containing the Hydrogen version number. This would allow us to show this data in the Admin, and also encourage things like upgrades to merchants in order to gain new and exciting features released in Hydrogen if they are behind on versions.

WHAT is this pull request doing?

  • Moving getHydrogenVersion to a shared location and out of update.ts

  • Consuming that command in deploy.ts and attaching the metadata

  • Need to ship to Oxygen-CLI first

HOW to test your changes?

I logged out the version number in the deploy command to see before the metadata was sent.

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@benwolfram benwolfram self-assigned this Nov 15, 2024
Copy link
Contributor

shopify bot commented Nov 15, 2024

Oxygen deployed a preview of your deploy-include-h2-version branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment November 18, 2024 4:43 PM
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment November 18, 2024 4:43 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment November 18, 2024 4:43 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment November 18, 2024 4:43 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment November 18, 2024 4:43 PM

Learn more about Hydrogen's GitHub integration.

},
);
});

it('exists when run over a prerelease "next" version', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test still made sense to leave in this file.


const currentDependencies = Object.fromEntries(
Object.entries(currentDependenciesWithEmptyValues).filter(([_, value]) => value)
) as Record<string, string>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add this type safety to ensure Record<string, string>. currentDependenciesWithEmptyValues can have undefined values, and upgrade.ts was having a hard time after.

@benwolfram benwolfram marked this pull request as ready for review November 15, 2024 16:56
Copy link
Contributor

We detected some changes in packages/*/package.json or packages/*/src, and there are no updates in the .changeset.
If the changes are user-facing and should cause a version bump, run npm run changeset add to track your changes and include them in the next release CHANGELOG.
If you are making simple updates to examples or documentation, you do not need to add a changeset.

@benwolfram
Copy link
Contributor Author

Moving back to draft to fix a couple things:

  • Not sharing the method with upgrade, we cant throw errors in the deploy one since it is not as critical to have and we don't want to block deploys
  • Reading from node_modules/@shopify/hydrogen/package.json -> version first, and then looking at root/package.json as a fallback -- as we want the actual version, not including characters that allow for multiple versions like > if possible.

@@ -631,6 +724,33 @@ describe('deploy', () => {
});

it('writes a file with JSON content in CI environments', async () => {
const ciDeployParams = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked this test to not use writeFile, as I can't mock it since it's needed inside the test now.

};

await runDeploy(ciDeployParams);
await removeFile('h2_deploy_log.json');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out why, but this had a file created already when running, I am not sure if temporary folder stuff is bleeding over? But this will make the test safe.

Copy link
Contributor Author

@benwolfram benwolfram Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the actual deploy command is creating the file for real in the test since I am not mocking writeFile anymore 🤔. This has been a pain 😞.

Very open to input here 😅, is there a way we have to create a temporary directory that will cleanup the files after?

@benwolfram benwolfram marked this pull request as ready for review November 18, 2024 16:37
@benwolfram
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @benwolfram! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20241118174207",
"@shopify/hydrogen": "0.0.0-snapshot-20241118174207"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

Comment on lines +690 to +695
const nodeModulesHydrogenPath = joinPath(
root,
'node_modules',
'@shopify',
'hydrogen',
'package.json',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do a more in depth review, but I'm not sure this will work in some package managers like yarn >2 and pnpm. Could you try testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks like the node_modules look a lot different in yarn@latest. pnpm works, and I think my approach is here is trying to do the best we can and fall back to different options. But open to more ideas.

For example below , if they have ^ or > in package.json for @shopify/hydrogen it can be slightly less accurate too, but we're trying to get the best data we can basically.

We can also rely on parsing the working bundle and crawling it as a fallback too if we don't like any of these. This is being used to backfill data too.

Copy link
Contributor

@wizardlyhel wizardlyhel Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benwolfram I think we can use importLocal that's being used within the Hydrogen CLI repo to get the Hydrogen lib version accurate to the node package itself.

  1. Export the LIB_VERSION in hydrogen package - This lib version will be updated on every release including if someone is using a next tag (which won't have a proper version tag and we can ignore showing banner in admin)
  2. Then in CLI, we can local import hydrogen to get the lib version like this
import {importLocal} from '../../lib/import-utils.js';

export async function getHydrogenVersion({appPath}: {appPath: string}) {
  const {root} = getProjectPaths(appPath);

  type HydrogenType = typeof import('@shopify/hydrogen');
  const {LIB_VERSION} = await importLocal<HydrogenType>(
    '@shopify/hydrogen',
    root,
  ).catch(() => {
    return '1.0.0';
  });

  return LIB_VERSION;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants