GITHUB_REF_NAMEとは?
GITHUB_REF_NAMEは、実行をトリガーしたbranchまたはtagの短く分かりやすい名前です。
GITHUB_REFが完全なrefであるのに対し、GITHUB_REF_NAMEはプレフィックスを取り除き、main、feature/login、v1.2.0だけを返します - 名前付けや条件分岐に通常欲しいものです。
よくある用途
- ref名が
mainのときだけdeployする - tagにちなんでreleaseに名前を付ける
- preview URL用にbranchをslug化する
例
branch名を条件にdeployのjobを制御する。
yaml
if: ${{ github.ref_name == 'main' }}重要なポイント
- GITHUB_REF_NAMEは短いbranch/tag名です。
- refs/headsやrefs/tagsのプレフィックスを取り除きます。
- 条件分岐や名前付けに最適です。
関連ガイド
What Is GITHUB_REF?GITHUB_REF is the fully-formed ref (branch or tag) that triggered a GitHub Actions run, like refs/heads/main.…
What Is GITHUB_REF_TYPE?GITHUB_REF_TYPE tells you whether a GitHub Actions run was triggered by a branch or a tag. Learn how to branc…
What Is a Git Branch?What is a Git branch? Learn how branches are lightweight movable pointers, how they enable parallel work, and…