{"meta":{"title":"サードパーティの CLI アクションの作成","intro":"GitHub Actions ランナーに CLI を設定するアクションを開発する方法について説明します。","product":"GitHub Actions","breadcrumbs":[{"href":"/ja/actions","title":"GitHub Actions"},{"href":"/ja/actions/how-tos","title":"方法"},{"href":"/ja/actions/how-tos/create-and-publish-actions","title":"アクションの作成と公開"},{"href":"/ja/actions/how-tos/create-and-publish-actions/create-a-cli-action","title":"CLI アクションの作成"}],"documentType":"article"},"body":"# サードパーティの CLI アクションの作成\n\nGitHub Actions ランナーに CLI を設定するアクションを開発する方法について説明します。\n\n## はじめに\n\nユーザーが、 GitHub Actions ランナー上の構成済みの CLI 環境を介してサーバーにアクセスする方法を提供するアクションを記述できます。\n\nアクションに求められること:\n\n* インストールする CLI のバージョンをユーザーが簡単に指定できるようにする\n* 複数のオペレーティング システムをサポートする\n* 効率的な方法で実行され、ランタイムと関連コストを最小限に抑える\n* GitHub がホストするランナーとセルフホストのランナーの両方で動作する\n* 可能であればコミュニティ ツールを活用する\n\nこの記事では、CLI の特定のバージョンを取得し、それをインストールし、それをパスに追加し、(任意で) それをキャッシュするアクションを記述する方法がわかります。 この種類のアクション (ツールをセットアップするアクション) の名前は多くの場合、`setup-$TOOL` です。\n\n## 前提条件\n\nカスタム アクションを記述する方法を理解している必要があります。 詳しくは、「[カスタム アクションの管理](/ja/actions/how-tos/create-and-publish-actions/manage-custom-actions)」をご覧ください。\n\n## 例\n\n次のスクリプトからは、ユーザー指定のバージョンを入力として取得し、特定のバージョンの CLI をダウンロードして抽出し、CLI をパスに追加する方法がわかります。\n\nGitHub には、アクションの作成に役立つパッケージのセットである [`actions/toolkit`](https://github.com/actions/toolkit)が用意されています。 この例では、[`actions/core`](https://github.com/actions/toolkit/tree/main/packages/core) および [`actions/tool-cache`](https://github.com/actions/toolkit/tree/main/packages/tool-cache) パッケージを使用します。\n\n```javascript copy\nconst core = require('@actions/core');\nconst tc = require('@actions/tool-cache');\n\nasync function setup() {\n  // Get version of tool to be installed\n  const version = core.getInput('version');\n\n  // Download the specific version of the tool, e.g. as a tarball\n  const pathToTarball = await tc.downloadTool(getDownloadURL());\n\n  // Extract the tarball onto the runner\n  const pathToCLI = await tc.extractTar(pathToTarball);\n\n  // Expose the tool by adding it to the PATH\n  core.addPath(pathToCLI)\n}\n\nmodule.exports = setup\n```\n\nこのスクリプトを使用するには、`getDownloadURL` を、CLI をダウンロードする関数に置き換えます。\n`action.yml` 入力を受け取り、このスクリプトを実行するアクション メタデータ ファイル (`version`) を作成する必要もあります。 アクションの作成方法の詳細については、「[JavaScript アクションを作成する](/ja/actions/tutorials/create-actions/create-a-javascript-action)」を参照してください。\n\n## 参考資料\n\nこのパターンはいくつかのアクションで使用されます。 他の例が必要であれば、次をご覧ください。\n\n* [`ruby/setup-ruby`](https://github.com/ruby/setup-ruby)\n* [`google-github-actions/setup-gcloud`](https://github.com/google-github-actions/setup-gcloud)\n* [`hashicorp/setup-terraform`](https://github.com/hashicorp/setup-terraform)"}