使用 Cookiecutter 创建脚手架资源库
This GitHub action 可让您通过 Port Actions 使用任何选定的Cookiecutter Template 快速构建软件源。
此外,由于 cookiecutter 是一个开源项目,您可以制作自己的项目模板,了解更多信息请访问here 。
示例 - golang 模板脚手架
请按照以下步骤开始使用 Golang 模板:
- 创建以下 GitHub 操作secret:
ORG_TOKEN
- 具有创建版本库权限的fine-grained PAT 。PORT_CLIENT_ID
- Port客户端 IDlearn more 。PORT_CLIENT_SECRET
- Port客户端secretlearn more 。 2.点击here 安装 Port 的 GitHub 应用程序。 3.创建具有以下属性的 Port 蓝图:
请记住,这可以是你想要的任何蓝图,这只是一个例子。
{
"identifier": "microservice",
"title": "Microservice",
"icon": "Microservice",
"schema": {
"properties": {
"description": {
"title": "Description",
"type": "string"
},
"url": {
"title": "URL",
"format": "url",
"type": "string"
},
"readme": {
"title": "README",
"type": "string",
"format": "markdown",
"icon": "Book"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
4.使用以下 JSON 定义创建 Port 操作:
请记住,任何以
cookiecutter_
开头的输入都会自动作为变量注入 cookiecutter 操作中。我们正在使用Golang Template 的 cookiecutter_app_name
输入。[
{
"identifier": "scaffold",
"title": "Scaffold Golang Microservice",
"icon": "Go",
"userInputs": {
"properties": {
"name": {
"title": "Repo Name",
"type": "string"
},
"cookiecutter_app_name": {
"type": "string",
"title": "Application Name"
}
},
"required": ["name"]
},
"invocationMethod": {
"type": "GITHUB",
"org": "port-cookiecutter-example",
"repo": "gha-templater",
"workflow": "scaffold-golang.yml",
"omitUserInputs": true
},
"trigger": "CREATE",
"description": "Scaffold a new Microservice from a Cookiecutter teplate"
}
]
5.在.github/workflows/scaffold-golang.yml
下创建一个工作流程文件,内容如下:
on:
workflow_dispatch:
inputs:
port_payload:
required: true
description: "Port's payload, including details for who triggered the action and general context (blueprint, run id, etc...)"
type: string
secrets:
ORG_TOKEN:
required: true
PORT_CLIENT_ID:
required: true
PORT_CLIENT_SECRET:
required: true
jobs:
scaffold:
runs-on: ubuntu-latest
steps:
- uses: port-labs/cookiecutter-[email protected]
with:
portClientId: ${{ secrets.PORT_CLIENT_ID }}
portClientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
token: ${{ secrets.ORG_TOKEN }}
portRunId: ${{ fromJson(inputs.port_payload).context.runId }}
repositoryName: ${{ fromJson(inputs.port_payload).payload.properties.name }}
portUserInputs: ${{ fromJson(inputs.port_payload).payload.properties }}
cookiecutterTemplate: https://github.com/lacion/cookiecutter-golang
blueprintIdentifier: "microservice"
organizationName: INSERT_ORG_NAME
6.从 Port 的用户界面触发操作。
下一步
- Connect Port's GitHub exporter 以确保从 GitHub 自动获取所有属性(如 URL、readme 等)。