Google 操作用户指南

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

项目同步

使用 Actions SDK 时,gactions 是同步 Action 项目的工具 Actions 控制台与本地文件系统之间的直接连接。

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

将操作推送到 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 部署到“preview”, 您在控制台中测试您的 Action,而不必实际更新 或影响其他开发者也就是说, 您在本地文件系统中所做的更改会传播到已部署的版本 但可在预览版中测试它们。

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 版/正式版渠道的版本 您可以通过 Actions 控制台中的 Deploy 部分进行管理。 使用该 API 通过 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 可查看有关发布渠道的详细信息 。您可以使用此命令来标识 已部署或待处理

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

账号关联

gactions encryptgactions decrypt 命令可用于管理 OAuth2 客户端密钥。这些命令专门用于账号关联

加密 OAuth2 账号关联客户端密钥

运行 gactions encrypt 以安全地为身份验证代码 OAuth2 账号添加客户端密钥 关联流,或者使用新的加密密钥对现有 Secret 进行加密。

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