LoginSignup
1
0

More than 1 year has passed since last update.

[GitHubActions] procon-gardenerの自動化

Last updated at Posted at 2022-06-10

はじめに

AtCoderの提出から自動的にコードを取得して、ローカルリポジトリに保存するprocon-gardenerというツールを用いています。

このツールではACコードの自動取得とリポジトリへのコミットは行いますが、pushは行いませんので各自で行ってください。

とあるので、アーカイブ先のローカルリポジトリ内に以下のようなbatファイルを作成して、ログオン時にコードの自動取得 & commit & pushを行っていました。

auto_archive.bat
cd /d %~dp0
procon-gardener archive
git push origin master

これでも良いのですが、ローカルの環境に依存している状況を改善するためにGitHubActionsを使用しました。

workflowのyml定義

定義ファイルの紹介

workflow.yml
name: Auto Archive AC code

on:
  schedule:
    - cron: "0 5 * * *"

jobs:
  AutoArchive:
    runs-on: ubuntu-latest

    steps:
      - name: Check out code into the Archive directory
        uses: actions/checkout@v3
      - name: Setup Go environment
        uses: actions/setup-go@v3.2.0
      - name: install procon-gardener
        run: go install github.com/togatoga/procon-gardener@latest
      - name: procon-gardener init
        run: /home/runner/go/bin/procon-gardener init
      - name: Create config.json
        run: |
          echo -e "{\"atcoder\": {\"repository_path\": \"$GITHUB_WORKSPACE\", \"user_id\": \"${{secrets.ATCODER_USERNAME}}\", \"user_email\": \"${{secrets.EMAIL}}\"}}" \
            > /home/runner/.procon-gardener/config.json
      - name: Archive AC codes
        run: /home/runner/go/bin/procon-gardener archive
      - name: git setting
        run: |
          git config --local user.email ${{secrets.EMAIL}}
          git config --local user.name ${{github.actor}}
      - name: push files
        run: |
          git push origin master

workflowの流れ

  1. Archive先のディレクトリにチェックアウト
  2. Go の環境構築
  3. procon-gardener のインストール
  4. config.jsonの初期化(作成)
  5. config.jsonの設定
  6. AC code のアーカイブ
  7. git の設定
  8. リモートリポジトリにpush

これによりローカル環境に依存せず、AtCoderでACしたcodeをアーカイブすることができます。

secretsの設定

${{secrets.EMAIL}} # GitHubに登録しているメールアドレス
${{secrets.ATCODER_USERNAME}} # AtCoderのユーザー名

上記は各自設定してください。

スケジュール

on:
  schedule:
    - cron: "0 5 * * *"

上記で、毎日AM5:00に走らせるようにしています。

参考記事

AtCoderの提出を取得してGitHubの芝を生やすコマンドラインツールを作った

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