GitHub Actions の actions/checkout とは?
actions/checkout はリポジトリを runner にクローンします。ほとんどの場合、workflow の最初の step になります。
runner は空の状態で始まります。build やテストの前に、コードをマシン上に置く必要があります。actions/checkout は、正しい commit で repo をクローンする公式 action です。
概要
実行の commit を使ってリポジトリを runner にチェックアウトする GitHub 公式の action です。内部で自動トークンによる認証を処理します。
Checking out code
steps:
- uses: actions/checkout@v4
- run: ls -la仕組み
デフォルトでは、実行をトリガーした commit の shallow クローン(depth 1)を runner の workspace に行います。後続の step はそれらのファイルを操作します。
よく使うオプション
fetch-depth: 0で完全な履歴を取得(tag や diff 用)。ref:で特定の branch や tag をチェックアウト。submodules: trueでサブモジュールを含める。
なぜ重要か
checkout がなければ、workflow は操作するコードを持ちません。オプション、特に fetch depth を理解しておくと、バージョニングや変更ファイル検出での予期しない挙動を避けられます。
関連する概念
Marketplace で最もよく使われる action であり、GITHUB_TOKEN を使って自動的に認証します。
重要なポイント
actions/checkoutは repo を runner にクローンします。- デフォルトでは、実行をトリガーした commit の shallow クローンを行います。
- 完全な履歴が必要なときは
fetch-depth: 0を使います。
関連ガイド
What Is an Action in GitHub Actions?An action is a reusable, packaged unit of work you invoke from a step with uses. Actions can be JavaScript, D…
What Is actions/cache in GitHub Actions?actions/cache stores and restores files like dependencies between runs using a key, speeding up workflows by…
What Is GITHUB_TOKEN in GitHub Actions?GITHUB_TOKEN is an automatic, short-lived credential GitHub injects into each workflow run so steps can call…
What Is a GitHub Actions Runner?A runner is the machine that executes a GitHub Actions job. It can be GitHub-hosted, self-hosted, or a manage…