gactions ユーザーガイド

このガイドでは、一般的な使用シナリオで gactions コマンドライン インターフェース(CLI)ツールを使用する方法について説明します。エンドツーエンドでのアクションの作成については、会話型アクションのビルドのドキュメントをご覧ください。

プロジェクトの同期

Actions SDK を使用する場合、gactions は Actions Console とローカル ファイル システムの間でアクション プロジェクトを同期するツールです。

gactions pull オペレーションではプロジェクトを Actions Console からローカル ファイル システムにエクスポートし、gactions push オペレーションではプロジェクトをローカル ファイル システムから Actions Console にプッシュします。

Actions Console からアクションをダウンロードする

gactions pull を実行して、Actions プロジェクトの構成をローカル ファイル システムにコピーします。

コピーするプロジェクトの project-id は、コマンドラインで渡すか、settings/settings.yaml ファイルに記述できます。両方が存在する場合、CLI はオプションとして渡された値を優先します。

mkdir -p myAction/sdk
cd myAction/sdk
gactions pull --project-id my-project-id
Pulling your project files from Draft for a project id: "my-project-id"
✔ Done. You should see the files written in path/to/myAction/sdk
ls -l
total 8
drwxr-x---  3 user  primarygroup   96 May  7 10:00 actions
drwxr-x---  4 user  primarygroup  128 May  7 10:00 custom
-rw-r-----  1 user  primarygroup   15 May  7 10:00 manifest.yaml
drwxr-x---  3 user  primarygroup   96 May  7 10:00 settings
vi settings/settings.yaml
// change projectId to "my-other-project-id"
gactions pull
Pulling your project files from Draft for a project id: "my-other-project-id"
path/to/myAction/sdk/manifest.yaml already exists. Would you like to overwrite it?. [y/n]
...
✔ Done. You should see the files written in path/to/myAction/sdk

上のコード スニペットは、プロジェクトのドラフトからアクションを取得する方法を示しています。また、アクションの特定のバージョンから取得することもできます。バージョンは、送信された Actions プロジェクトのコピーを表し、リリース チャンネルにデプロイできます。

--version-id フラグには、pull するバージョンを指定します。

mkdir -p myAction/sdk
cd myAction/sdk
gactions pull --project-id my-project-id --version-id my-version-id
Pulling version "my-version-id" of the project "my-project-id" from Actions Console...
✔ Done. You should see the files written in path/to/myAction/sdk
ls -l
total 8
drwxr-x---  3 user  primarygroup   96 May  7 10:00 actions
drwxr-x---  4 user  primarygroup  128 May  7 10:00 custom
-rw-r-----  1 user  primarygroup   15 May  7 10:00 manifest.yaml
drwxr-x---  3 user  primarygroup   96 May  7 10:00 settings

確認メッセージを表示せずにファイルのローカルコピーを上書きする場合は、--force フラグを使用します。リモートのドラフトまたはバージョンに存在しないローカル ファイルを削除するには、--clean フラグを使用します。これらを組み合わせて使用すると、Actions Console プロジェクトの正確なコピーを取得できます。

touch local_file.txt
gactions pull --force
Pulling your project files from Draft for a project id: "my-project-id"
[WARNING] 2020/05/07 17:34:32 path/to/myAction/sdk/local_file.txt is not present in the draft of your Action. To remove, run pull with --clean flag.
✔ Done. You should see the files written in path/to/myAction/sdk
gactions pull --force --clean
Pulling your project files from Draft for a project id: "my-project-id"
[WARNING] 2020/05/07 17:43:44 path/to/myAction/sdk/local_file.txt is not present in the draft of your Action. Removing path/to/myAction/sdk/local_file.txt.
✔ Done. You should see the files written in path/to/myAction/sdk

Actions Console プロジェクトのドラフトにアクションをプッシュする

コンソールで gactions push を実行して、ローカル ファイル システムからアクションのドラフトに変更を push します。このプロセスは、開発中に Actions Console に反映された変更を、テスト対象のバージョンに影響を与えることなく確認するのに役立ちます。

gactions push
Pushing your project files to your Actions console draft for a project id: "my-project-id". This may take a few minutes.
Sending configuration files
Waiting for server to respond.
✔ Done. You can now navigate to the Actions Console: https://console.actions.google.com/project/my-project-id/overview to view your project. If you want to test your changes in the simulator, run "gactions deploy preview"

ソースコード管理システムから既存のプロジェクトをインポートする

バージョン管理システムのリビジョンから既存のプロジェクトを操作する場合は、次のようにします。

  1. ターゲット リビジョンを確認します(システムによって異なります)。
  2. プロジェクトの settings.yamlprojectId の値を置き換えます。
  3. 必要に応じて、gactions push を実行して、ローカル構成ファイルを Actions プロジェクトにコピーします。
git clone https://github.com/my/repo.git
Cloning into 'repo'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 51 (delta 3), reused 3 (delta 1), pack-reused 41
Receiving objects: 100% (51/51), 36.86 KiB | 3.69 MiB/s, done.
Resolving deltas: 100% (11/11), done.
cd repo/sdk/
vi settings/settings.yaml
// change the value of `projectId`
gactions push

バージョンの一覧表示

gactions versions list を実行して、アクションのバージョンの詳細を表示します。バージョン ステータスについて詳しくは、状態のリファレンスをご覧ください。

gactions versions list
Version         Status          Last Modified By        Modified On     
1           Created     your-email@your-domain.com  2020-09-28 20:22:04

デプロイのステータスが「作成に失敗しました」と表示されている場合は、コンソールの [リリース] セクションで詳細を確認できます。

プロジェクトをデプロイする

gactions deploy コマンドを使用すると、プロジェクトをデプロイし、Actions シミュレータでテストしたり、アルファ版/ベータ版/製品版のリリース チャンネルにデプロイしたりできます。

シミュレータでプレビュー

gactions deploy preview を実行してアクションをプレビューにデプロイできます。これにより、アクション プロジェクトのバージョンを実際に更新したり、他のデベロッパーに影響を与えたりすることなく、コンソールでアクションをテストできます。つまり、ローカル ファイル システムで行った変更は、Actions プロジェクトのデプロイ済みバージョンに伝播されませんが、プレビュー版ではテストできます。

gactions deploy preview
Deploying your project files to your Actions console preview for a project id: "my-project". This may take a few minutes.
Sending configuration files
Waiting for server to respond.
✔ Done. You can now navigate to the Actions Console simulator to test your changes: http://console.actions.google.com/project/my-project/simulator?disableAutoPreview

リリースを作成する

gactions deploy を実行して、アルファ版/ベータ版/prod チャンネルのバージョン リリースを作成します。これは、Actions Console の [デプロイ] セクションで管理できます。これを使用して、アルファ版やベータ版のチャンネルでアクションのリリース候補をテストし、フィードバックに問題がなければ、リリース候補を本番環境に移行します。

gactions deploy alpha
Deploying your project files to a actions.channels.Alpha channel for a project id: "my-project-id"
Sending configuration files
Waiting for server to respond.
✔ Done. Your Action was deployed to actions.channels.Alpha channel. You can check status of deployment in the Actions Console.

リリース チャンネルの一覧表示

gactions release-channels list を実行して、アクションのリリース チャンネルの詳細を表示します。このコマンドを使用して、各チャネルにデプロイされたバージョンまたは保留中のバージョンを特定できます。

gactions release-channels list
Release Channel             Current Version             Pending Version
alpha                   1                     N/A

アカウントのリンク

gactions encrypt コマンドと gactions decrypt コマンドを使用すると、OAuth2 クライアント シークレットを管理できます。以下のコマンドは、アカウントのリンクに固有のものです。

OAuth2 アカウント リンクのクライアント シークレットを暗号化する

gactions encrypt を実行して、認証コード OAuth2 アカウント リンク フロー用のクライアント シークレットを安全に追加するか、新しい暗号鍵で既存のシークレットを暗号化します。

gactions encrypt
Write your secret: *********************
Encrypting your client secret
path/to/myAction/sdk/settings/accountLinkingSecret.yaml already exists. Would you like to overwrite it?. [y/n]
y
✔ Done. Encrypted secret was written to path/to/myAction/sdk/settings/accountLinkingSecret.yaml

暗号化されたアカウント リンク シークレットの書式なしテキスト値にアクセスする。

プロジェクトのシークレットの書式なしテキスト値に一時的にアクセスする必要がある場合は、gactions decrypt を実行します。このコマンドにより、値が任意のテキスト ファイルに出力されます。書式なしテキスト値が誤って漏洩しないように、宛先ファイルはプロジェクトのルートフォルダの外部に配置することをおすすめします。

gactions decrypt ../../burn_after_read.txt
Decrypting your client secret
✔ Done. Check path/above/myActions/burn_after_read.txt to find decrypted client secret.
vi ../../burn_after_read.txt
rm ../../burn_after_read.txt