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?

GitHub Action - WSL x Self-hosted runner

Last updated at Posted at 2025-12-04

解決したい課題

PR作成の際は、ローカルのWSLを利用し、Buildを実施することで、GitHub Runnerのコストを最小限に抑えたい。

解決するための要件

  • WSL2起動時に、ServiceとしてSelf-hosted runnerが起動する
  • 自分自身のPRのテストのみ、ローカルのWSLでGitHub Actionを実施する

Self-hosted runner のインストール

GitHubのリポジトリを開き、 Actions > Runners > [New self-hosted runner]ボタンを押下すると下記のようにコマンドが表示されるので、実行していく。

image.png

POINT1:

ファイル展開の場所は、今後のサービス登録を視野に /opt 以下に配置した。

sudo mkdir -p /opt/github-runner/runner1
sudo chown $USER:$USER /opt/github-runner/runner1

POINT2:

./config.sh 実行時に下記のようにLabel設定を登録するので GitHub AccountのLabelとして登録した

This runner will have the following labels: 'self-hosted', 'Linux', 'X64'
Enter any additional labels (ex. label-1,label-2): [press Enter to skip] xxxxxx

Service 登録

systemd を有効化

/etc/wsl.conf を編集し、WSLの再起動を実行

[boot]
systemd=true
powershell
wsl --shutdown

systemd サービスを作成

# systemdのconfigを作成
sudo tee /etc/systemd/system/github-runner.service > /dev/null <<EOF
[Unit]
Description=GitHub Actions Runner 1
After=network.target

[Service]
ExecStart=/opt/github-runner/run.sh
WorkingDirectory=/opt/github-runner
User=$USER
Restart=always

[Install]
WantedBy=multi-user.target
EOF

# systemctlの読み込みと起動
sudo systemctl daemon-reload
sudo systemctl enable --now github-runner1

# 登録の確認
$ systemctl list-units --type=service | grep git
#  github-runner.service                    loaded active running GitHub Actions Runner 1

Workflow ファイルの作成

.github/workflows/pr-build.yml
name: PR Build

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  build:
    name: Build on PR author's runner
    runs-on: 
      - ${{ github.event.pull_request.user.login }}

    steps:
      - name: Show PR Author
        run: echo "PR author is [${{ github.event.pull_request.user.login }}]"

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?