使用环境变量可以构建红宝石宝石吗?

发布于 2025-01-21 07:07:33 字数 1423 浏览 2 评论 0 原文

我想简化在我们的私人github ruby​​gems注册表中部署内部宝石。在大多数情况下,在GEMSpec文件中,该版本是硬编码或从另一个文件中读取的。意思是要发布新版本后,一旦准备好代码库,就必须创建一个拉动请求,修改版本,合并,然后最终发布。

此工作流与我们的MonorePo中的其他服务不符。对于最后的最后,一旦我们想发布,我们就会创建一个触发a REST/REFESS/REVERATIONS“ RER =“ Nofollow Noreferrer”> GitHub部署和专用的CI管道,我们可以在其中检索要发布的版本的名称。

因此,对于我们的宝石,我一直在考虑使用环境变量来设置该版本时,当调用GEM Build rubocop-xxxxx 喜欢这样

Gem::Specification.new do |spec|
  spec.platform = Gem::Platform::RUBY
  spec.name = 'rubocop-xxxxx'
  spec.metadata = {
    'github_repo' => 'ssh://github.com/xxxxx/monorepo',
    'allowed_push_host' => 'https://rubygems.pkg.github.com/xxxxx',
    'source_code_uri' => 'https://github.com/xxxxx/monorepo/tree/main/packages/common/rubocop'
  }
  spec.version = ENV['PACKAGE_RELEASE_VERSION'] || "0.0.0"
  spec.platform = Gem::Platform::RUBY
  spec.required_ruby_version = '>= 2.7'

  spec.files = Dir[
    'rubocop.yml',
    'conf/**/*',
    '*.gemspec',
    'Gemfile',
  ]

  spec.add_dependency('rubocop-performance', '~> 1.13.3')
  spec.add_dependency('rubocop-rails', '~> 2.14.2')
  spec.add_dependency('rubocop-rake', '~> 0.6.0')
  spec.add_dependency('rubocop-rspec', '~> 2.9.0')
  spec.add_dependency('rubocop-shopify', '~> 2.5.0')
end

:在运行 gemfile.lock 生成 Bundle bundle install 时发出问题。

拥有这样的Gemspec可以,还是可以看到以后再见?

I want to ease the deployment of an internal gem to our private Github rubygems registry. Most of the time, within the gemspec file, the version is hardcoded or read from another file. Meaning to publish a new release once your code base ready, you have to create a pull request, modified the version, merge, then finally publish.

This workflow does not match the other services in our monorepo. For these last, once we want to release, we create a branch release/service-name/v1.2 that trigger a Github Deployment and a dedicated CI pipeline where we can retrieve the name of the version to release.

So for our gem, I was thinking to use an environment variable to set the version when calling gem build rubocop-xxxxx like this:

Gem::Specification.new do |spec|
  spec.platform = Gem::Platform::RUBY
  spec.name = 'rubocop-xxxxx'
  spec.metadata = {
    'github_repo' => 'ssh://github.com/xxxxx/monorepo',
    'allowed_push_host' => 'https://rubygems.pkg.github.com/xxxxx',
    'source_code_uri' => 'https://github.com/xxxxx/monorepo/tree/main/packages/common/rubocop'
  }
  spec.version = ENV['PACKAGE_RELEASE_VERSION'] || "0.0.0"
  spec.platform = Gem::Platform::RUBY
  spec.required_ruby_version = '>= 2.7'

  spec.files = Dir[
    'rubocop.yml',
    'conf/**/*',
    '*.gemspec',
    'Gemfile',
  ]

  spec.add_dependency('rubocop-performance', '~> 1.13.3')
  spec.add_dependency('rubocop-rails', '~> 2.14.2')
  spec.add_dependency('rubocop-rake', '~> 0.6.0')
  spec.add_dependency('rubocop-rspec', '~> 2.9.0')
  spec.add_dependency('rubocop-shopify', '~> 2.5.0')
end

The 0.0.0 fallback is here to avoid issue when generating the Gemfile.lock when running bundle install.

Is it OK to have such gemspec, or can I see later some issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫烠⑼条掵仅有一顆心 2025-01-28 07:07:33

我会不是使用环境变量来设置宝石版本。

如果您的目标是测试 rubocop-xxxxx gem在您的一项服务中的释放候选者,然后才能使用 path 选项 gemfile 中,而不是释放每个更改。

示例

gemfile:

gem "rubocop-xxxxx", path: <path-to-the-gem>

当宝石的版本按预期工作时,释放它(使用硬编码版本编号),请从 gemfile < /code>再次指定已发布的版本

示例

gemfile:

gem "rubocop-xxxxx", "~> 1.1"

I would not use an environment variable for setting the gem version.

If your goal is to test a release candidate of rubocop-xxxxx gem in one of your service before you finally release it, you can use the path option in the Gemfile instead of releasing each change.

Example

Gemfile:

gem "rubocop-xxxxx", path: <path-to-the-gem>

When the version of the gem works as expected, release it (with a hard-coded version number), remove the path option from the Gemfile again and specify the released version instead.

Example

Gemfile:

gem "rubocop-xxxxx", "~> 1.1"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文