7
1

More than 1 year has passed since last update.

OTP認証を有効にした際のgemリリースで、GEM_HOST_OTP_CODE環境変数を見てくれなかった原因

Last updated at Posted at 2022-03-05

はじめに

↑ の記事で GitHub Actions を使って Gem のリリースをやったが、OTP 認証を有効にした場合の Gem のリリースがうまくいっていなかった。

その原因がわかったので、記事にする。

原因

原因はgemのバージョンに問題があった。
gemのバージョンが3.2.22以降でなければ、GEM_HOST_OTP_CODEの環境変数を見てくれない。

https://github.com/rubygems/rubygems/blob/master/CHANGELOG.md#3222--2021-07-06

3.2.22 / 2021-07-06

Enhancements:
  • Allow setting --otp via GEM_HOST_OTP_CODE. Pull request #4697 by
    CGA1123

https://qiita.com/ohakutsu/items/14c76b0ab3ec626e842d の記事では、ruby/setup-ruby action を使って Ruby のセットアップをしていたのだが、ruby-version: 3.0.0ではgemのバージョンが3.2.3であった。

$ gem --version

3.2.3

そのため、gemのバージョンが3.2.22以降になるようにruby-version: 3.1.1にしたところ無事デプロイができた。

参考として GitHub Actions の workflow を貼っておく。

Secrets にRUBYGEMS_API_KEYとして API Key を登録しておき、リリースの際は OTP コードを入力し手動でリリースを行う workflow。

.github/workflows/release.yml
name: Release gem

on:
  workflow_dispatch:
    inputs:
      rubygems-otp-code:
        description: RubyGems OTP code
        required: true

permissions:
  contents: write

jobs:
  release-gem:
    runs-on: ubuntu-latest
    env:
      GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
      GEM_HOST_OTP_CODE: ${{ github.event.inputs.rubygems-otp-code }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0 # bundle exec rake release で git tag を見るため、tagをfetchするようにしている
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.1.1
      - name: Bundle install
        run: bundle install
      - name: Setup gitconfig # bundle exec rake release でgit tagが打たれていない場合、タグを打ってpushしてくれるため用意している
        run: |
          git config --global user.email "YOUR_EMAIL"
          git config --global user.name "${{ github.actor }}"
      - name: Release gem
        run: bundle exec rake release
7
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1