首页 > 解决方案 > gem push 失败,控制台中的 HTML 输出

问题描述

我正在学习 Rails 课程,目前正在创建和发布一个 Ruby gem(名为kang_view_tool)。我一直无法将其推送到RubyGems

两种方法都导致控制台上的以下输出:

$ gem push kang_view_tool-0.1.0.gem
Pushing gem to https://github.com/nahuakang/kang_view_tool...
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'self'; connect-src 'self'; form-action 'self'; img-src 'self' data:; script-src 'self'; style-src 'unsafe-inline'">
    <meta content="origin" name="referrer">
    <title>Oh no &middot; GitHub</title>
    <meta name="viewport" content="width=device-width">
    <style type="text/css" media="screen">
      body {
        background-color: #f6f8fa;
        color: #24292e;
        font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
        font-size: 14px;
        line-height: 1.5;
        margin: 0;
      }

      .container { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; }

      a { color: #4183c4; text-decoration: none; }
      a:hover { text-decoration: underline; }

      h1 { letter-spacing: -1px; line-height: 60px; font-size: 60px; font-weight: 100; margin: 0px; text-shadow: 0 1px 0 #fff; }
      p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

      ul { list-style: none; margin: 25px 0; padding: 0; }
      li { display: table-cell; font-weight: bold; width: 1%; }

      .logo { display: inline-block; margin-top: 35px; }
      .logo-img-2x { display: none; }
      @media
      only screen and (-webkit-min-device-pixel-ratio: 2),
      only screen and (   min--moz-device-pixel-ratio: 2),
      only screen and (     -o-min-device-pixel-ratio: 2/1),
      only screen and (        min-device-pixel-ratio: 2),
      only screen and (                min-resolution: 192dpi),
      only screen and (                min-resolution: 2dppx) {
        .logo-img-1x { display: none; }
        .logo-img-2x { display: inline-block; }
      }

      #suggestions {
        margin-top: 35px;
        color: #ccc;
      }
      #suggestions a {
        color: #666666;
        font-weight: 200;
        font-size: 14px;
        margin: 0 10px;
      }

    </style>
  </head>
  <body>

    <div class="container">

      <h1>What&#8253;</h1>
      <p>Your browser did something unexpected. Please contact us if the problem persists.</p>
      <div id="suggestions">
        <a href="https://github.com/contact">Contact Support</a> &mdash;
        <a href="https://githubstatus.com">GitHub Status</a> &mdash;
        <a href="https://twitter.com/githubstatus">@githubstatus</a>
      </div>

      <a href="/" class="logo logo-img-1x">
        <img width="32" height="32" title="" alt="" src="data:image/png;base64,...">
      </a>

      <a href="/" class="logo logo-img-2x">
        <img width="32" height="32" title="" alt="" src="data:image/png;base64,...">
      </a>
    </div>
  </body>
</html>

这个问题似乎与 Github 有关,但我不知道如何解决它,也没有在 Stackoverflow 上找到有帮助的答案。有没有人有任何提示?谢谢!

标签: ruby

解决方案


原来是一个愚蠢的问题。我通读了 RubyGems.org 的文档:

RubyGems 2.2.0 和更新版本支持allowed_push_host元数据值以限制 gem 推送到单个主机。如果您要发布私有 gem,您应该设置此值以防止意外推送到 ruby​​gems.org...

原来我天真地指定了这个元数据值: spec.metadata["allowed_push_host"] = "https://github.com/nahuakang/kang_view_tool".

我将其注释掉,然后运行:

$ gem build kang_view_tool
  Successfully built RubyGem
  Name: kang_view_tool
  Version: 0.1.0
  File: kang_view_tool-0.1.0.gem
$ gem push kang_view_tool-0.1.0.gem
Pushing gem to https://rubygems.org...
Successfully registered gem: kang_view_tool (0.1.0)

然后它起作用了。


推荐阅读