0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

oj-verifyでドキュメントがうまく更新できない問題を解決した

Posted at

問題

online-judge-tools/verification-helperをドキュメントの通りに導入した後あれこれしていた。
しかし、リポジトリをいじっているうちにどこかのタイミングでうまく動作しなくなってしまった。

Github Actionsのworkflowで oj-verify all が動き、その最中に自動で2回pushが行われる。

  • 1回目: mainブランチのタイムスタンプの更新
  • 2回目: gh-pagesブランチのドキュメントの更新

そのうちの2回目の方だけにエラーが起きていた。

エラー内容

To (リポジトリのリンク)
 ! [rejected]        HEAD -> main (fetch first)
error: failed to push some refs to (リポジトリのリンク)
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

これはworkflowのログ
解決法を見つけるためにあれこれしたものの結局hintの1~2行目が全てだった。

「リモートに、ローカルには存在しない作業が含まれているため、更新は拒否されました。」

すなわちoj-verifyが実行されている段階でgh-pagesブランチがないことになっているという状態だった。

結論

    - uses: actions/checkout@v3
      with:
        fetch-depth: 0

fetch-depth を足す

checkout@v2 以降はfetch-depthがデフォルトで1になっているため(参考: https://github.com/actions/checkout )、mainブランチの最新のコミットしか取得できず、gh-pagesの情報を得られていなかったことが原因だった。
fetch-depthを0にすると全履歴を取得することができる。
checkout@v1 に変更しても解決できると思う。(未検証)

試行錯誤

workflowのログとoj-verifyのソースコードを追っていた。人様のリポジトリもたくさん見た。大変だった。
checkoutの仕様を知ったときに、どのような情報を入手できていてどのような情報を入手できていないのかを確かめるために以下のstepを追加して出力を見ることにした。(「debugで取得したブランチの情報を知りたい。」でデバッグ内容をすぐ書いてくれたLLMくん優秀だね。)

    - name: Debug Git state
      run: |
        echo "=== Current branch ==="
        git branch -v
        echo "=== Remote branches ==="
        git branch -rv
        echo "=== All branches ==="
        git branch -av
        echo "=== Current HEAD ==="
        git log --oneline -5
        echo "=== Remote origin/main ==="
        git log --oneline origin/main -5
        echo "=== Remote origin/gh-pages (if exists) ==="
        git log --oneline origin/gh-pages -5 || echo "origin/gh-pages not found"
        echo "=== Local gh-pages (if exists) ==="
        git log --oneline gh-pages -5 || echo "local gh-pages not found"

これで fatal: ambiguous argument 'origin/gh-pages': unknown revision or path not in the working tree. と出力されたので上述の最終的な結論を予想するに至り、無事解決した。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?