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 から competitive-verifier へ移行した(競プロのライブラリを自動で verify するツール)

0
Posted at

競プロ用のライブラリを自動でテストできるツールとして online-judge-verify-helper(以下 oj-verify)が知られていますが、更新が途絶えており使用時に不便な点も見られます。
そこで筆者は最近 competitive-verifier というツールに移行しました。

competitive-verifier には oj-verify と同様 GitHub Actions ワークフローを設定できるページが用意されていますが、筆者の場合テンプレートをそのまま使うことはできなかったので変更した点を記録しておきます。

gcc:15.2.0-trixie イメージを使用する

jobs:
  setup:
    runs-on: ubuntu-latest
+   container: gcc:15.2.0-trixie

現在の AtCoder ジャッジ環境と同じ GCC 15.2.0 をローカルで使えるようにしているので、verify 時にも使えるようにしたいです。
Ubuntu 25.04 などでも GCC 15.2.0 を簡単にインストールできそうですが、初めからインストールされているのが最も簡単なので gcc:15.2.0-trixie を使います。
(ところでコンテナを使用することで諸々の困難が引き起こされている説があります)

${{ github.workspace }} ではなく $GITHUB_WORKSPACE を使う

コンテナを使っている場合は github.workspace コンテキストが作業ディレクトリを正しく指しません。
GITHUB_WORKSPACE 環境変数は正しいのでそちらを使うようにします。

git の safe.directory にディレクトリを追加する

- name: Set safe directory
  run: git config --global --add safe.directory $GITHUB_WORKSPACE

actions/checkout でクローンしてきた後 git 操作をするためにこの設定が必要になります。
competitive-verifier/actions/oj-resolve の内部で git ls-files が使用されています。

pipx をインストールして pip のフリをさせる

- name: Setup pipx as pip
  run: |
    apt-get update
    apt-get install -y pipx
    mkdir -p /github/home/.local/bin
    echo "/github/home/.local/bin" >> $GITHUB_PATH
    ln -s $(which pipx) /github/home/.local/bin/pip

pipx をインストールして PATH を通し、シンボリックリンクを作って pip で起動するようにします。

competitive-verifier/actions/setup の内部で pip install competitive-verifier が走るのですが、その際 PEP 668 の externally-managed-environment エラーを回避する必要があります。
おそらく actions/setup-python を使用するのが最も簡単ですが、コンテナを使用しているせいかうまく動きませんでした。(具体的には /__t/Python/3.14.2/x64/bin/pip の存在と実行権限が確認できるのに not found になる)
これを解決したり、あるいは自力で別の Python(仮想)環境をセットアップするのは大変そうなので pipx を使うことにしました。pipx install がたまたま存在していて助かりました。

PowerShell をインストールする

- name: Set up PowerShell
  run: |
    apt-get update
    wget https://github.com/PowerShell/PowerShell/releases/download/v7.6.0-preview.6/powershell_7.6.0-preview.6-1.deb_amd64.deb
    dpkg -i powershell_7.6.0-preview.6-1.deb_amd64.deb
    apt-get install -f
    rm powershell_7.6.0-preview.6-1.deb_amd64.deb

PowerShell は competitive-verifier/actions/oj-resolve などで使われます。
以下のページに従えば OK です。

Debian 13 に対応しているバージョンが 7.6.0-preview.5 以降であることと、上記ページの「Debian 用 PowerShell 7.6-preview ユニバーサル パッケージ」のリンクが間違っていることに注意します。

jq をインストールする

- name: Set up jq
  run: |
    apt-get update
    apt-get install -y jq

jq は competitive-verifier/actions/upload-verify-artifact などで使われます。

AtCoder Library をインストールする

- name: Clone AC-Library
  uses: actions/checkout@v6
  with:
    repository: atcoder/ac-library
    path: ac-library
    sparse-checkout: atcoder
 - name: Verify
   uses: competitive-verifier/actions/verify@v2
   (中略)
   env:
+    CPLUS_INCLUDE_PATH: ${{ env.WORKSPACE }}/ac-library
     YUKICODER_TOKEN: ${{ secrets.YUKICODER_TOKEN }}

ライブラリが ACL に依存しているので必要です。
WORKSPACE 環境変数の値は GITHUB_WORKSPACE 環境変数と同じです。

- name: Set workspace environment variable
  run: echo "WORKSPACE=$GITHUB_WORKSPACE" >> $GITHUB_ENV

runner.temp ではなく GITHUB_WORKSPACE 以下のディレクトリを使用する

    - name: Verify
      uses: competitive-verifier/actions/verify@v2
      with:
-       destination: ${{runner.temp}}/result.json
+       destination: ${{ env.WORKSPACE }}/result.json
        split-size: ${{ env.SPLIT_SIZE }}
        split-index: ${{ matrix.index }}
        timeout: 1800
        prev-result: ${{ steps.restore-cached-results.outputs.cache-hit && 'merged-result.json' || ''}}
      env:
        CPLUS_INCLUDE_PATH: ${{ env.WORKSPACE }}/ac-library
        YUKICODER_TOKEN: ${{ secrets.YUKICODER_TOKEN }}
    
    - name: Upload result artifact
      uses: actions/upload-artifact@v4
      with:
        name: Result-${{ runner.os }}-${{ matrix.index }}
-       path: ${{runner.temp}}/result.json
+       path: ${{ env.WORKSPACE }}/result.json
        retention-days: 1

コンテナを使用している影響なのか runner.temp のディレクトリにあるファイルを actions/upload-artifact で扱えないためディレクトリを変更します。
上記の ACL もそうですが ${{ env.WORKSPACE }}/tmp/ を作ってその中でやるとより安全かもしれません。

その他

GitHub Actions 関連以外に competitive-verifier migrate を実行したり .verify-helper/ を .competitive-verifier/ にリネームしたりしました。

おわり

以上です。今後 competitive-verifier を使いたい方の参考になれば幸いです。

最終的な YAML ファイルはこちら

参考文献

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?