Shopify CLI 2.0 Documentation

repository·main·Indexed 21 days ago

https://github.com/shopify/shopify-cli

A Ruby-based command line tool used to build and manage Shopify apps, themes, and storefronts. This version is deprecated as of May 31, 2023. The documentation covers installation, packaging for Debian, Homebrew, and RPM, migration from Theme Kit, and managing Shopify extensions via the 'extension' command.

Tokens
15.7K
Snippets
82
Records
96
Agent score
77%

What's inside Shopify CLI 2.0

  1. Install requirements for building RPM packages

    main

    To build RPM packages for the Shopify CLI, you must have the rpmbuild program installed on your system.

    • macOS: Install via Homebrew using brew install rpm.
    • Linux: Install via yum using yum install rpm-build.
    # macOS
    brew install rpm
    
    # Linux
    yum install rpm-build
  2. Build a Homebrew package of the CLI

    main

    The Homebrew package for the Shopify CLI acts as a proxy for the actual Ruby gem. It works by downloading the gem and installing the source code within the Homebrew environment.

    Note: This is not a metapackage. Users cannot switch between the Homebrew version and the Gem version without a complete reinstallation.

    rake package:homebrew
  3. Build a .deb package of the CLI manually

    main

    The Shopify CLI Debian package is a metapackage that installs the CLI gem via Ruby and manages non-ruby dependencies.

    To build the package manually:

    1. Prepare Metadata: Place the following files in packaging/debian/shopify-cli/DEBIAN:

      • control
      • preinst
      • prerm
    2. Set Version: The files use the SHOPIFY_CLI_VERSION variable. For manual builds, you must set this version manually in those files (the Rake task handles this automatically).

    3. Run Build Command: Execute dpkg-deb against the package directory.

    The resulting package will be named shopify-cli.deb.

    dpkg-deb -b shopify-cli
  4. Release Shopify CLI 2.0 using the automated process

    main

    The automated release process for CLI 2.0 uses a series of Rake tasks and PR-based checkpoints. Follow these steps in order:

    1. Export your GitHub access token: export GITHUB_ACCESS_TOKEN=$(dev github print-auth | grep Password | awk '{print $NF}')
    2. Prepare the release using Rake (replace 2.x.x with your target version): rake "release:prepare[2.x.x]"
    3. Sanity-check and merge the PR that opens in your browser.
    4. Trigger Shipit on your version commit to release to RubyGems.
    5. Package the release: rake release:package
    6. Sanity-check and merge the Homebrew PR that opens in your browser.
    7. Verify the GitHub release includes .deb and .rpm files.
    8. Complete any post-release steps found in PRs labeled includes-post-release-steps, then delete those labels.
    export GITHUB_ACCESS_TOKEN=$(dev github print-auth | grep Password | awk '{print $NF}')
    rake "release:prepare[2.x.x]"
    rake release:package
  5. Manual requirements for Homebrew formula creation

    main

    To manually create a Homebrew formula, you must first build the CLI gem. This is required because the formula is built on top of the actual CLI gem.

    Run the following command from the root directory to build the gem:

    gem build <root>/shopify-cli.gemspec
    gem build <root>/shopify-cli.gemspec
  6. Run acceptance tests with Cucumber

    main

    Acceptance tests verify the built shopify command against various fixtures. These tests are written in Cucumber and Ruby and are located in the features/ directory. They provide high coverage by testing complete scenarios for major features, though they are slower than unit tests.

    To run all acceptance tests, use bundle exec cucumber. To run a specific test scenario, specify the feature file and line number.

    bundle exec cucumber
    bundle exec cucumber features/theme.feature:3 # A specific test
  7. Build an RPM package of the CLI

    main

    The Shopify CLI RPM package is a metapackage that installs the CLI gem via Ruby.

    For new builds, it is recommended to use the provided Rake task, which automates versioning and metadata:

    rake package:rpm

    Manual Build Process

    If you need to build manually, follow these steps:

    1. Prepare the spec file: Copy the metadata .spec.base file into the .spec file.
    2. Set the version: Manually set the SHOPIFY_CLI_VERSION environment variable in the spec file (the Rake task does this automatically).
    3. Run rpmbuild: Navigate to the RPM directory and execute the build command.

    The resulting package will be located in build/noarch.

    cd packaging/rpm
    # Note: Ensure SHOPIFY_CLI_VERSION is set in the .spec file before running
    rpmbuild -bb rubygem-shopify.spec
  8. Release Shopify CLI 2.0 using the manual process

    main

    If automation fails, follow these manual steps to release CLI 2.0:

    1. Prepare the Release Branch

    1. Ensure you are on the latest main branch:
      git checkout main
      git pull
    2. Create a release branch named release_X_Y_Z (e.g., release_2_3_6):
      git checkout -b release_X_Y_Z
    3. Update the version in lib/shopify_cli/version.rb.
    4. Update the version at the top of Gemfile.lock (required for CI).
    5. Add the new release entry to CHANGELOG.md.
    6. Commit with the message "Packaging for release vX.Y.Z" and push:
      git commit -am "Packaging for release vX.Y.Z"
      git push -u origin release_X_Y_Z
    7. Open a PR, get approvals, and merge into main. Note: The PR title will serve as the Shipit release note.

    2. Deploy to RubyGems

    1. Deploy using Shipit.
    2. Update your local main branch:
      git checkout main
      git pull

    3. Package and Update Homebrew

    1. After the gem is published to RubyGems, run the packaging task:
      rake package
      This generates .deb, .rpm, and brew formula files in packaging/builds/X.Y.Z/.
    2. In the Shopify/homebrew-shopify repository:
      • Update master and create a new branch release_X_Y_Z_of_shopify-cli.
      • Update the brew formula in shopify-cli.rb using the generated formula from packaging/builds/X.Y.Z/.
      • Commit and create a PR to the Homebrew repository.

    4. Finalize GitHub Release

    1. Go to the Shopify/shopify-cli releases page.
    2. Create a new release using the Shipit tag (e.g., vX.Y.Z).
    3. Set the title to Version X.Y.Z and use the CHANGELOG.md section as the description.
    4. Upload the .deb and .rpm files from packaging/builds/X.Y.Z/.
    5. Check "This is a pre-release" if applicable, then click "Publish release".
    6. Complete any post-release steps from PRs labeled includes-post-release-steps and delete the labels.
    # Prepare branch
    git checkout main
    git pull
    git checkout -b release_X_Y_Z
    
    # Commit and push
    git commit -am "Packaging for release vX.Y.Z"
    git push -u origin release_X_Y_Z
    
    # Package after RubyGems deployment
    rake package