ノート: GitHubホストランナーは、現在GitHub Enterprise Serverでサポートされていません。 GitHubパブリックロードマップで、計画されている将来のサポートに関する詳しい情� �を見ることができます。
ワークフローコマンドについて
アクションは、 環境変数を設定する、他のアクションに利用される値を出力する、デバッグメッセージを出力ログに追� するなどのタスクを行うため、ランナーマシンとやりとりできます。
ほとんどのワークフローコマンドは特定の形式で echo コマンドを使用しますが、他のワークフローコマンドはファイルへの書き込みによって呼び出されます。 詳しい情� �については、「環境ファイル」を参照してく� さい。
echo "::workflow-command parameter1={data},parameter2={data}::{command value}" ノート: ワークフローコマンドおよびパラメータ名では、大文字と小文字は区別されません。
警告: コマンドプロンプトを使っているなら、ワークフローコマンドを使う際にダブルクォート文字(")は省いてく� さい。
ワークフローコマンドを使ったツールキット関数へのアクセス
actions/toolkitには、ワークフローコマンドとして実行できる多くの関数があります。 ::構文を使って、YAMLファイル内でワークフローコマンドを実行してく� さい。それらのコマンドはstdoutを通じてランナーに送信されます。 たとえば、コードを使用して出力を設定する代わりに、以下のようにします。
core.setOutput('SELECTED_COLOR', 'green'); ワークフローで set-output コマンドを使用して、同じ値を設定できます。
 - name: Set selected color run: echo '::set-output name=SELECTED_COLOR::green' id: random-color-generator - name: Get color run: echo "The selected color is ${{ steps.random-color-generator.outputs.SELECTED_COLOR }}" 以下の表は、ワークフロー内で使えるツールキット関数を示しています。
| ツールキット関数 | 等価なワークフローのコマンド | 
|---|---|
| core.addPath | Accessible using environment file GITHUB_PATH | 
| core.debug | debug | 
| core.error | error | 
| core.endGroup | endgroup | 
| core.exportVariable | Accessible using environment file GITHUB_ENV | 
| core.getInput | 環境変数の INPUT_{NAME}を使ってアクセス可能 | 
| core.getState | 環境変数の STATE_{NAME}を使ってアクセス可能 | 
| core.isDebug | 環境変数の RUNNER_DEBUGを使ってアクセス可能 | 
| core.saveState | save-state | 
| core.setCommandEcho | echo | 
| core.setFailed | ::error及びexit 1のショートカットとして使われる | 
| core.setOutput | set-output | 
| core.setSecret | add-mask | 
| core.startGroup | group | 
| core.warning | 警告 | 
出力パラメータの設定
::set-output name={name}::{value} アクションの出力パラメータを設定します。
あるいは、出力パラメータをアクションのメタデータファイル中で宣言することもできます。 For more information, see "Metadata syntax for GitHub Actions."
サンプル
echo "::set-output name=action_fruit::strawberry" デバッグメッセージの設定
::debug::{message} デバッグメッセージをログに出力します。 ログでこのコマンドにより設定されたデバッグメッセージを表示するには、ACTIONS_STEP_DEBUG という名前のシークレットを作成し、値を true に設定する必要があります。 詳しい情� �については、「デバッグログの有効化」を参照してく� さい。
サンプル
echo "::debug::Set the Octocat variable" 警告メッセージの設定
::warning file={name},line={line},endLine={endLine},title={title}::{message} 警告メッセージを作成し、ログにそのメッセージを出力します。 This message will create an annotation, which can associate the message with a particular file in your repository. Optionally, your message can specify a position within the file.
| Parameter | Value | | :- | :- | | file | Filename | | col | Column number, starting at 1 | | line | Line number, starting at 1 |
サンプル
echo "::warning file=app.js,line=1,col=5,endColumn=7::Missing semicolon" エラーメッセージの設定
::error file={name},line={line},endLine={endLine},title={title}::{message} エラーメッセージを作成し、ログにそのメッセージを出力します。 This message will create an annotation, which can associate the message with a particular file in your repository. Optionally, your message can specify a position within the file.
| Parameter | Value | | :- | :- | | file | Filename | | col | Column number, starting at 1 | | line | Line number, starting at 1 |
サンプル
echo "::error file=app.js,line=1,col=5,endColumn=7::Missing semicolon" ログの行のグループ化
::group::{title} ::endgroup:: 展開可能なグループをログ中に作成します。 グループを作成するには、groupコマンドを使ってtitleを指定してく� さい。 groupとendgroupコマンド間でログに出力したすべての内容は、ログ中の展開可能なエントリ内にネストされます。
サンプル
echo "::group::My title" echo "Inside group" echo "::endgroup::" 
ログ中での値のマスク
::add-mask::{value} 値をマスクすることにより、文字列または値がログに出力されることを防ぎます。 空白で分離された、マスクされた各語は "*" という文字で置き換えられます。 マスクの value には、環境変数または文字列を用いることができます。
文字列をマスクするサンプル
ログに "Mona The Octocat" を出力すると、"***" が表示されます。
echo "::add-mask::Mona The Octocat" 環境変数をマスクするサンプル
変数 MY_NAME または値 "Mona The Octocat" をログに出力すると、"Mona The Octocat" の代わりに "***" が表示されます。
MY_NAME="Mona The Octocat" echo "::add-mask::$MY_NAME" ワークフローコマンドの停止と開始
::stop-commands::{endtoken}
ワークフローコマンドの処理を停止します。 この特殊コマンドを使うと、意図せずワークフローコマンドを実行することなくいかなるログも取れます。 たとえば、コメントがあるスクリプト全体を出力するためにログ取得を停止できます。
To stop the processing of workflow commands, pass a unique token to stop-commands. To resume processing workflow commands, pass the same token that you used to stop workflow commands.
Warning: Make sure the token you're using is randomly generated and unique for each run. As demonstrated in the example below, you can generate a unique hash of your github.token for each run.
::{endtoken}:: Example stopping and starting workflow commands
jobs: workflow-command-job: runs-on: ubuntu-latest steps: - name: disable workflow commands run: | echo '::warning:: this is a warning' echo "::stop-commands::`echo -n ${{ github.token }} | sha256sum | head -c 64`" echo '::warning:: this will NOT be a warning' echo "::`echo -n ${{ github.token }} | sha256sum | head -c 64`::" echo '::warning:: this is a warning again' Echoing command outputs
::echo::on ::echo::off Enables or disables echoing of workflow commands. For example, if you use the set-output command in a workflow, it sets an output parameter but the workflow run's log does not show the command itself. If you enable command echoing, then the log shows the command, such as ::set-output name={name}::{value}.
Command echoing is disabled by default. However, a workflow command is echoed if there are any errors processing the command.
The add-mask, debug, warning, and error commands do not support echoing because their outputs are already echoed to the log.
You can also enable command echoing globally by turning on step debug logging using the ACTIONS_STEP_DEBUG secret. For more information, see "Enabling debug logging". In contrast, the echo workflow command lets you enable command echoing at a more granular level, rather than enabling it for every workflow in a repository.
Example toggling command echoing
jobs: workflow-command-job: runs-on: ubuntu-latest steps: - name: toggle workflow command echoing run: | echo '::set-output name=action_echo::disabled' echo '::echo::on' echo '::set-output name=action_echo::enabled' echo '::echo::off' echo '::set-output name=action_echo::disabled' The step above prints the following lines to the log:
::set-output name=action_echo::enabled ::echo::off Only the second set-output and echo workflow commands are included in the log because command echoing was only enabled when they were run. Even though it is not always echoed, the output parameter is set in all cases.
pre及びpostアクションへの値の送信
save-stateコマンドを使って、ワークフローのpre:あるいはpost:アクションと共有するための環境変数を作成できます。 たとえば、pre:アクションでファイルを作成し、そのファイルの� �所をmain:アクションに渡し、post:アクションを使ってそのファイルを削除できます。 あるいは、ファイルをmain:アクションで作成し、そのファイルの� �所をpost:アクションに渡し、post:アクションを使ってそのファイルを削除することもできます。
複数のpre:あるいはpost:アクションがある� �合、保存された値にアクセスできるのはsave-stateが使われたアクションの中でのみです。 post:アクションに関する詳しい情� �については「GitHub Actionsのためのメタデータ構文」を参照してく� さい。
save-stateコマンドはアクション内でしか実行できず、YAMLファイルでは利用できません。 保存された値は、STATE_プレフィックス付きで環境変数として保存されます。
以下の例はJavaScriptを使ってsave-stateコマンドを実行します。 結果の環境変数はSTATE_processIDという名前になり、12345という値を持ちます。
console.log('::save-state name=processID::12345') そして、STATE_processID変数はmainアクションの下で実行されるクリーンアップスクリプトからのみ利用できます。 以下の例はmainを実行し、JavaScriptを使って環境変数STATE_processIDに割り当てられた値を表示します。
console.log("The running PID from the main action is: " + process.env.STATE_processID); Environment files
ワークフローの実行中に、ランナーは特定のアクションを実行する際に使用できる一時ファイルを生成します。 これらのファイルへのパスは、環境変数を介して公開されます。 コマンドを適切に処理するには、これらのファイルに書き込むときに UTF-8 エンコーディングを使用する必要があります。 複数のコマンドを、改行で区切って同じファイルに書き込むことができます。
Warning: On Windows, legacy PowerShell (shell: powershell) does not use UTF-8 by default.
When using shell: powershell, you must specify UTF-8 encoding. 例:
jobs: legacy-powershell-example: uses: windows-2019 steps: - shell: powershell run: echo "mypath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append Alternatively, you can use PowerShell Core (shell: pwsh), which defaults to UTF-8.
環境変数の設定
echo "{environment_variable_name}={value}" >> $GITHUB_ENV You can make an environment variable available to any subsequent steps in a workflow job by defining or updating the environment variable and writing this to the GITHUB_ENV environment file. The step that creates or updates the environment variable does not have access to the new value, but all subsequent steps in a job will have access. The names of environment variables are case-sensitive, and you can include punctuation. 詳しい情� �については、「環境変数」を参照してく� さい。
サンプル
steps: - name: Set the value id: step_one run: | echo "action_state=yellow" >> $GITHUB_ENV - name: Use the value id: step_two run: | echo "${{ env.action_state }}" # This will output 'yellow' 複数行の文字列
複数行の文字列の� �合、次の構文で区切り文字を使用できます。
{name}<<{delimiter} {value} {delimiter} サンプル
この例では、区切り文字として EOF を使用し、JSON_RESPONSE 環境変数を cURL レスポンスの値に設定します。
steps: - name: Set the value id: step_one run: | echo 'JSON_RESPONSE<<EOF' >> $GITHUB_ENV curl https://httpbin.org/json >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV システ� パスの追�
echo "{path}" >> $GITHUB_PATH Prepends a directory to the system PATH variable and automatically makes it available to all subsequent actions in the current job; the currently running action cannot access the updated path variable. ジョブに現在定義されているパスを見るには、ステップもしくはアクション中でecho "$PATH"を使うことができます。
サンプル
この例は、ユーザの$HOME/.local/binディレクトリをPATHに追� する方法を示しています。
echo "$HOME/.local/bin" >> $GITHUB_PATH