Google 操作用户指南

本指南介绍了如何在常见使用场景中使用 gactions 命令行界面 (CLI) 工具。如需了解如何端到端构建 Action,请参阅对话型 Action 构建文档。

项目同步

使用 Actions SDK 时,gactions 就是用于在 Actions 控制台和本地文件系统之间同步 Action 项目的工具。

gactions pull 操作会将项目从 Actions 控制台导出到本地文件系统,gactions push 操作会将项目从本地文件系统推送到 Actions 控制台。

从 Actions 控制台下载 Action

运行 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

上面的代码段展示了如何从项目草稿中提取 Action。此外,您还可以从 Action 的特定版本中提取数据。版本代表所提交的 Actions 项目副本,该副本可以部署到发布渠道。

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

将 Action 推送到 Actions 控制台项目草稿

运行 gactions push,将本地文件系统中的更改推送到控制台中的 Action 草稿。此过程在开发期间非常有用,可让您查看在 Actions 控制台中反映的更改,而不会影响为测试提供的版本。

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 以查看有关 Action 版本的详细信息。如需详细了解版本状态,请参阅状态参考文档。

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 模拟器中进行测试,也可以部署到 Alpha/Beta/正式版渠道。

在模拟器中预览

运行 gactions deploy preview 以将您的 Action 部署到“预览”,这样您无需实际更新 Action 项目的版本或影响其他开发者,就可以在控制台中测试 Action。换言之,您在本地文件系统中所做的任何更改都不会传播到 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 渠道测试 Action 的候选版本,并在对反馈满意后将候选版本转至正式版。

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 以查看有关 Action 的发布渠道的详细信息。您可以使用此命令来识别每个渠道中已部署或待处理的版本。

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