Shopify / hydrogen

Hydrogen lets you build faster headless storefronts in less time, on Shopify.
https://hydrogen.shop
MIT License
1.36k stars 262 forks source link

[Bug]: Hydrogen CLI Deploy Deployment Tokens Not Supported #2515

Open lembn opened 1 week ago

lembn commented 1 week ago

Please confirm that you have:

In which of these areas are you experiencing a problem?

Hydrogen custom storefront

Expected behavior

I expected the command shopify hydrogen deploy to deploy my branch to Oxygen when running the command with the SHOPIFY_HYDROGEN_DEPLOYMENT_TOKEN environment variable presented and populated without needing any user interaction.

Actual behavior

Even when providing a deployment token, the CLI prompts the user to log in to their Shopify account both from my local machine and my deployment CI in Gihub Actions, which is making my deployment CI fail. I tried instead to provide the token using the -t option but was given the error "Nonexistent flag: -t". The same happened with the long-form version of the option.

Verbose output

2024-09-10T00:42:33.048Z: Obtaining the dependency manager in directory ... 2024-09-10T00:42:33.051Z: Running system process: · Command: ruby -v · Working directory:

2024-09-10T00:42:33.055Z: Obtaining the dependency manager in directory ... 2024-09-10T00:42:33.056Z: Running system process: · Command: ruby -v · Working directory:

2024-09-10T00:42:33.290Z: Request to https://monorail-edge.shopifysvc.com/v1/produce completed in 226 ms With response headers:

2024-09-10T00:42:33.291Z: Analytics event sent: { "command": "hydrogen deploy", "time_start": 1725928953027, "time_end": 1725928953042, "total_time": 15, "success": false, "cli_version": "3.49.2", "ruby_version": "2.6.10", "node_version": "22.8.0", "is_employee": false, "uname": "darwin arm64", "env_ci": false, "env_plugin_installed_any_custom": false, "env_plugin_installed_shopify": "[\"@shopify/cli\",\"@shopify/cli-hydrogen\",\"@shopify/plugin-did-you-mean\"]", "env_shell": "zsh", "env_device_id": "87f2f3705d95aa1c5cfcdc33516e543d7399bffe", "env_cloud": "localhost", "env_package_manager": "npm", "cmd_all_launcher": "npm", "cmd_all_topic": "hydrogen", "cmd_all_plugin": "@shopify/cli-hydrogen", "args": "--token *** --verbose", "error_message": "Nonexistent flags: --token, --verbose\nSee more help with --help", "env_plugin_installed_all": "[\"@shopify/cli\",\"@shopify/cli-hydrogen\",\"@shopify/plugin-did-you-mean\"]", "metadata": "{\"extraPublic\":{},\"extraSensitive\":{}}" }

Reproduction steps

Unfortunately, I cannot publicize my repository to provide a clone for reproduction but I'm simply running npx shopify hydrogen deploy. I have also tried installing the CLI with no change in result

Operating System

Mac OS Sonoma

Shopify CLI version (check your project's package.json if you're not sure)

3.66.1

Shell

zsh

Node version (run node -v if you're not sure)

v22.8.0

What language and version are you using in your application?

Node 22

lembn commented 1 week ago

Here is my GH Workflow:

name: Storefront 1000023762
on: [push]

permissions:
  contents: read
  deployments: write

jobs:
  deploy:
    name: Deploy to Oxygen
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup node.js
        uses: actions/setup-node@v4
        with:
          node-version: 'lts/*'
          check-latest: true

      - name: Cache node modules
        id: cache-npm
        uses: actions/cache@v4
        env:
          cache-name: cache-node-modules
        with:
          path: ~/.npm
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install dependencies
        run: npm ci

      - name: Build and Publish to Oxygen
        run: npx shopify hydrogen deploy
        env:
          SHOPIFY_HYDROGEN_DEPLOYMENT_TOKEN: ${{ secrets.SHOPIFY_HYDROGEN_DEPLOYMENT_TOKEN }}
isaacroldan commented 6 days ago

I transfered this issue to the Hydrogen repo from the CLI repo, as this is the correct place for it :)

lembn commented 4 days ago

Thanks!

graygilmore commented 1 day ago

Hi @lembn! There might be some version mismatches happening here. Before going any further can you try the following in your package.json:

- "@shopify/cli": "3.49.2",
+ "@shopify/cli": "3.66.1", // update to the latest version
- "@shopify/cli-hydrogen": "<VERSION>", // remove this entirely

After updating shopify/cli and removing cli-hydrogen try running again. We should never prompt to login in a CI environment but it's expected to happen in local development.