GitHub 工作流程
我们的GitHub action 允许您直接从 GitHub 工作流中创建/更新和查询 Port 中的实体。
公共仓库 我们的 GitHub action是开源的,请参见here
💡 常见的 Github 工作流程 Usage
例如,Port 的 GitHub 操作提供了将 Port 与 GitHub 工作流集成的原生方式:
- 报告正在运行的CI任务的状态;
- 更新软件目录中有关微服务新**构建版本的信息;
- 获取现有实体。
安装
要安装 Port 的 GitHub 操作,请按照以下步骤操作:
- 在 GitHub 工作流程中添加以下一行作为一个步骤:
- uses: port-labs/port-github-action@v1
2.将您的 Port CLIENT_ID
和 CLIENT_SECRET
添加为GitHub secrets ;
1.此步骤不是强制性的,但为了避免在工作流程中以明文传递 CLIENT_ID
和 CLIENT_SECRET
,建议使用此步骤;
3. 确保您的 Port 安装中已有蓝图,以便使用 GitHub 操作创建/更新实体。
Usage
Port 的 GitHub 操作支持以下方法:
- 创建/更新目录实体--使用 "UPSERT "操作调用,接收新实体或需要更新的实体的标识符和其他属性;
- 批量创建/更新目录实体--使用 "BULK_UPSERT "操作调用,接收一些新实体或需 要更新的实体的实体定义;
- 获取目录实体--使用 "GET "操作调用,接收现有实体的标识符并将其检索出来供 CI 使用;
- 搜索目录实体 - 使用
SEARCH
操作调用,接收查询并检索实体供 CI 使用; - 删除目录实体--使用
DELETE
操作调用,接收现有实体的标识符并将其删除; - 更新正在运行的操作 - 使用
PATCH_RUN
操作调用,接收现有操作运行的标识符以及需要更新的运行的其他属性。 - 创建一个正在运行的操作 - 使用
CREATE_RUN
操作调用,接收现有蓝图、操作和实体(可选)的标识符,以及要运行操作的输入属性。
- Create/Update Entity
- Bulk Create/Update Entities
- Get Entity
- Search Entities
- Delete Entity
- Update Running Action
- Create Action Run
- uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: UPSERT
identifier: myEntity
icon: myIcon
blueprint: myBlueprint
team: "['myTeam']"
properties: |-
{
"myStringProp": "My value",
"myNumberProp": 1,
"myBooleanProp": true,
"myArrayProp": ["myVal1", "myVal2"],
"myObjectProp": {"myKey": "myVal", "myExtraKey": "myExtraVal"}
}
- uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: BULK_UPSERT
runId: myRunId
entities: |-
[
{
"identifier": "myEntity",
"icon": "myIcon",
"blueprint": "myBlueprint",
"team": [
"myTeam"
],
"properties": {
"myStringProp": "My value",
"myNumberProp": 1,
"myBooleanProp": true,
"myArrayProp": [
"myVal1",
"myVal2"
],
"myObjectProp": {
"myKey": "myVal",
"myExtraKey": "myExtraVal"
}
}
}
]
get-entity:
runs-on: ubuntu-latest
outputs:
entity: ${{ steps.port-github-action.outputs.entity }}
steps:
- id: port-github-action
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: GET
identifier: myEntity
blueprint: myBlueprint
use-entity:
runs-on: ubuntu-latest
needs: get-entity
steps:
- run: echo '${{needs.get-entity.outputs.entity}}' | jq .properties.myProp
search-entities:
runs-on: ubuntu-latest
outputs:
entities: ${{ steps.port-github-action.outputs.entities }}
steps:
- id: port-github-action
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: SEARCH
query: |-
{
"rules": [
{
"operator": "=",
"value": "myEntity",
"property": "$identifier"
}
],
"combinator": "and"
}
use-entities:
runs-on: ubuntu-latest
needs: search-entities
steps:
- run: echo '${{needs.search-entities.outputs.entities}}' | jq .[0].myProp
- uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: DELETE
identifier: myEntity
blueprint: myBlueprint
- uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: PATCH_RUN
runId: myRunId
status: "SUCCESS"
logMessage: "My log message"
summary: "My summary"
link: `["https://mylink.com"]`
- uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.CLIENT_ID }}
clientSecret: ${{ secrets.CLIENT_SECRET }}
operation: CREATE_RUN
icon: GithubActions
blueprint: myBlueprint
action: myAction
identifier: myEntity
properties: |-
{
"text": "test",
"number": 1,
"boolean": true
}
示例
有关 Port 在 GitHub 上的实际操作示例,请参阅examples 页面。