GitHub Actions のエクスプレッションとは?
エクスプレッションは ${{ }} の内側にあるコードで、GitHub がこれを評価して値の計算、文字列の組み立て、条件の判定を行います。
GitHub Actions の YAML は大部分が静的ですが、エクスプレッションがロジックを追加します。${{ と }} の間にあるものはすべて、step が実行される前に GitHub がコンテキスト、演算子、組み込み関数を使って評価します。
概要
エクスプレッションは ${{ }} で囲まれた小さな数式です。コンテキストのデータを読み取り、contains() や format() のような関数を呼び出し、==、&&、|| などの演算子を使えます。
Expressions in use
steps:
- if: ${{ github.ref == 'refs/heads/main' }}
run: ./deploy.sh
- run: echo "${{ format('Build {0}', github.run_number) }}"仕組み
GitHub は workflow を処理する際にエクスプレッションを評価し、その結果を YAML に埋め込みます。if: 条件では、値全体がエクスプレッションとして扱われるため、周囲の ${{ }} は省略できます。
関数と演算子
エクスプレッションは比較演算子や論理演算子に加えて、contains、startsWith、fromJSON などの関数、そしてステータスチェックの success() や failure() をサポートします。これらが条件付き step や動的な値を可能にします。
なぜ重要か
エクスプレッションは workflow を動的にします。誤った branch では step をスキップしたり、バージョン文字列を組み立てたり、以前の結果によって分岐したりできます。静的な YAML と runtime のデータをつなぐ接着剤です。
関連する概念
エクスプレッションはコンテキストから読み取り、if: 条件、matrix、concurrency キーで広く使われます。
重要なポイント
- エクスプレッションは
${{ }}の内側のロジックです。 - コンテキスト、演算子、関数を使います。
if:では${{ }}のラッパーは省略できます。
関連ガイド
What Is a Context in GitHub Actions?A context in GitHub Actions is a structured object of run data, like github, env, and secrets, that you read…
What Is continue-on-error in GitHub Actions?continue-on-error lets a failing step or job be treated as a non-blocking failure, so the workflow keeps goin…
What Is a Matrix Build in GitHub Actions?A matrix build runs the same job many times across combinations of variables, like multiple OS or language ve…
What Is a Step in GitHub Actions?A step in GitHub Actions is a single task in a job. It either runs a shell command with run or invokes a reus…