LoginSignup
2
1

More than 1 year has passed since last update.

OSSで気持ちよくContributeしてもらうためのGitHub Actionsの設定

Posted at

GitHub上のOSSにContributeする際はリポジトリをforkし、forkしたリポジトリにpushしたブランチで元リポジトリにPRを作成するという手順を踏みます。
この際、forkしたリポジトリを考慮したGitHub Actionsの設定になっていないと、権限不足等の問題でCIが落ち、Contributeの意欲を削ぐ結果になりかねません。
これを防ぐため、以下の表を参考に、forkしたリポジトリから元リポジトリへのPRやforkしたリポジトリでのPR (元リポジトリにPRを出す前の動作確認を想定) で実行してほしくないGitHub Actionsのjob・stepには適切な実行条件 ( if ) をつけてあげると良いでしょう。
なお、 X は条件の否定を表しています。

動作させたい条件 github.repository == github.event.pull_request.head.repo.full_name github.repository == '元リポジトリ (org/repository)'
forkしたリポジトリでのPR O X
forkしたリポジトリから元リポジトリへのPR X O
元リポジトリでのPR O O

例: forkしたリポジトリでのPRと元リポジトリでのPRのみ、GitHub Container Registryへのpushを行うjobの実行を許可する

.github/workflows/push.yml
---
name: Push GitHub Container Registry

on:
  pull_request:

jobs:
  push:
    runs-on: ubuntu-latest
    # (github.repository == github.event.pull_request.head.repo.full_name && github.repository != '元リポジトリ (org/repository)')
    # || (github.repository == github.event.pull_request.head.repo.full_name && github.repository == '元リポジトリ (org/repository)')
    # をまとめた条件
    if: github.repository == github.event.pull_request.head.repo.full_name
    steps:
      ...

なお、この設定を行うPRは動作確認を兼ねてあえてforkしたリポジトリから出すようにすると良いと思います。

2
1
1

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