回應使用手冊

本指南說明如何在常見的使用情境下使用 gactions 指令列介面 (CLI) 工具。如要瞭解如何端對端建構動作,請參閱對話動作建構說明文件。

專案同步處理

使用 Actions SDK 時,gactions 工具可讓您同步處理 Actions 主控台和本機檔案系統之間的動作專案。

gactions pull 作業會將專案從 Actions 主控台匯出至本機檔案系統,而 gactions push 作業會將專案從本機檔案系統推送至 Actions 主控台。

從 Actions 控制台下載動作

執行 gactions pull,將動作專案的設定複製到本機檔案系統。

您要複製的專案 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

上方的程式碼片段說明如何從專案草稿提取動作。使用者也可以從特定動作版本提取。版本代表動作專案的提交副本,可以部署至發布版本。

--version-id 旗標會指定要提取的版本。

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 主控台專案的完整副本。

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 主控台專案草稿

執行 gactions push,將變更從本機檔案系統推送至主控台的動作草稿。這個程序在開發期間非常實用,可供您查看動作主控台中顯示的變更,而不會影響用於測試的版本。

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.yaml 中的 projectId 值。
  3. 或者,您也可以執行 gactions push,將本機設定檔複製到動作專案。
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

如果部署作業的狀態顯示「Creation failed」(建立失敗),您可以在控制台的「Release」(版本) 部分下方取得更多詳細資料。

部署專案

gactions deploy 指令可讓您在動作模擬工具中部署專案並進行測試,或是部署至 Alpha/Beta 版/正式版發布版本。

在模擬工具中預覽

執行 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 建立 Alpha/beta/prod 版本的版本。您可以透過 Actions 控制台的「Deploy」(部署) 部分進行管理。您可以使用這項功能透過 Alpha 版和/或 Beta 版測試動作的候選版本,並在您滿意各項意見回饋後,將候選版本移至正式版。

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 encryptgactions 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