Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions bin/create-homebrew-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ program
switch (templateVersion) {
case "stable":
files["shopify-cli.rb"] = (await readFile(path.join(outputDirectory, "shopify-cli.rb"))).toString()
// Only keep the @3 versioned formula up to date while we are on major version 3.
// Once we move to v4+, shopify-cli@3.rb stays frozen at the last 3.x release.
if (majorVersion === 3) {
files["shopify-cli@3.rb"] = (await readFile(path.join(outputDirectory, "shopify-cli@3.rb"))).toString()
}
// Always keep the versioned formula for the current major up to date.
// When we bump to the next major, the previous major's formula naturally
// freezes at its last release since we stop updating it.
files[`shopify-cli@${majorVersion}.rb`] = await renderVersionedFormula(majorVersion, homebrewVariables)
break
case "pre":
files["shopify-cli-pre.rb"] = (await readFile(path.join(outputDirectory, "shopify-cli-pre.rb"))).toString()
Expand Down Expand Up @@ -115,6 +114,13 @@ function getTemplateVersion(version) {
throw `Unrecognized version string ${version}`
}

async function renderVersionedFormula(majorVersion, variables) {
const engine = new Liquid({root: packagingDirectory})
const templatePath = path.join(packagingDirectory, "stable/src/shopify-cli.rb.liquid")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that liquid file still has references to version 3
like

if formulaVersion != '3

Do we need to update that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated already in the original PR. My question here would be whether we really want to this and keep generating formulas for previous versions or not.

const content = (await readFile(templatePath)).toString()
return engine.render(engine.parse(content), {...variables, formulaVersion: String(majorVersion)})
}

async function getHomebrewVariables(cliVersion) {
const [cliTarball, cliSha] = await getTarballAndShaForPackage('@shopify/cli', cliVersion)
return {cliTarball, cliSha}
Expand Down
6 changes: 3 additions & 3 deletions packaging/stable/src/shopify-cli.rb.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "formula"
require "language/node"
require "fileutils"

class ShopifyCli{% if formulaVersion %}{% if formulaVersion == '3' %}AT3{% else %}{{ formulaVersion | capitalize }}{% endif %}{% endif %} < Formula
class ShopifyCli{% if formulaVersion %}{% if formulaVersion == 'nightly' or formulaVersion == 'pre' %}{{ formulaVersion | capitalize }}{% else %}AT{{ formulaVersion }}{% endif %}{% endif %} < Formula
desc "A CLI tool to build for the Shopify platform"
homepage "https://github.com/shopify/cli#readme"
url "{{ cliTarball }}"
Expand All @@ -31,13 +31,13 @@ class ShopifyCli{% if formulaVersion %}{% if formulaVersion == '3' %}AT3{% else
system "npm", "install", *Language::Node.std_npm_install_args(libexec)

original_executable_path = "#{libexec}/bin/shopify"
executable_path = "#{original_executable_path}{% if formulaVersion %}{% if formulaVersion != '3' %}-{% endif %}{{formulaVersion}}{% endif %}"
executable_path = "#{original_executable_path}{% if formulaVersion %}{% if formulaVersion == 'nightly' or formulaVersion == 'pre' %}-{% endif %}{{formulaVersion}}{% endif %}"
new_original_executable_path = "#{executable_path}-original"
FileUtils.move(original_executable_path, new_original_executable_path)
executable_content = <<~SCRIPT
#!/usr/bin/env #{Formula["node"].opt_bin}/node

process.env.SHOPIFY_HOMEBREW_FORMULA = "shopify-cli{% if formulaVersion %}{% if formulaVersion == '3' %}@{% else %}-{% endif %}{{formulaVersion}}{% endif %}"
process.env.SHOPIFY_HOMEBREW_FORMULA = "shopify-cli{% if formulaVersion %}{% if formulaVersion == 'nightly' or formulaVersion == 'pre' %}-{% else %}@{% endif %}{{formulaVersion}}{% endif %}"

import("#{new_original_executable_path}")
SCRIPT
Expand Down
5 changes: 0 additions & 5 deletions packaging/stable/src/shopify-cli@3.rb.liquid

This file was deleted.

Loading