From a56711ad2c1eb880d0016b3d4850af03c5f47122 Mon Sep 17 00:00:00 2001 From: xRain Date: Wed, 21 Oct 2026 17:07:42 +0800 Subject: [PATCH] first --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++ action.yml | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 README.md create mode 100644 action.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..b24f2df --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# dp-report + +把镜像记录到部署平台:下载并执行平台的 `scripts/push-image` 脚本。 + +`server` 只填域名,action 会补上 `/api/sdp`,实际执行: + +``` +curl -fsSL /api/sdp/scripts/push-image | bash -s -- --token --image / --server /api/sdp +``` + +## 参数 + +| 参数 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `server` | 否 | `https://auth.coce.cc` | 部署平台地址,只填域名 | +| `token` | 否 | `${{ secrets.DEPLOY_PLATFORM_TOKEN }}` | 部署平台 TOKEN | +| `registry` | 否 | `${{ vars.DOCKER_REGISTRY }}` | 镜像 registry,可替换 | +| `image` | 否 | `${{ github.repository }}` | 镜像名,不含 registry | + +最终传给脚本的镜像是 `/`;如果 `registry` 留空,则直接使用 `image`。`image` 里可以带 tag。 + +> `token` 默认取 `secrets.DEPLOY_PLATFORM_TOKEN`;如果你的 runner 不支持在 composite action 的 input 默认值里使用 `secrets`,调用时显式传 `token: ${{ secrets.DEPLOY_PLATFORM_TOKEN }}` 即可。 + +## 示例 + +```yaml +- uses: actions/dp-report@main +``` + +替换 registry / image: + +```yaml +- uses: actions/dp-report@main + with: + registry: registry.example.com + image: simcu/web +``` + +替换服务器地址: + +```yaml +- uses: actions/dp-report@main + with: + server: https://auth.example.com +``` + +显式传 token(默认值不可用时): + +```yaml +- uses: actions/dp-report@main + with: + token: ${{ secrets.DEPLOY_PLATFORM_TOKEN }} +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1cf0dfe --- /dev/null +++ b/action.yml @@ -0,0 +1,64 @@ +# action.yml +name: "dp report" +description: "调用部署平台记录镜像(push-image 脚本)" + +inputs: + server: + description: "部署平台地址,只填域名(脚本和 API 在 /api/sdp 下)" + required: false + default: "https://auth.coce.cc" + token: + description: "部署平台 TOKEN,默认取 secrets.DEPLOY_PLATFORM_TOKEN" + required: false + default: "${{ secrets.DEPLOY_PLATFORM_TOKEN }}" + registry: + description: "镜像 registry,默认 vars.DOCKER_REGISTRY,可替换" + required: false + default: "${{ vars.DOCKER_REGISTRY }}" + image: + description: "镜像名,不含 registry(默认 github.repository)" + required: false + default: "${{ github.repository }}" + +runs: + using: "composite" + steps: + - name: push image record + shell: bash + env: + SERVER: ${{ inputs.server }} + TOKEN: ${{ inputs.token }} + REGISTRY: ${{ inputs.registry }} + IMAGE_NAME: ${{ inputs.image }} + run: | + set -euo pipefail + + server="${SERVER%/}" + if [ -z "$server" ]; then + echo "缺少 server(部署平台地址)" + exit 1 + fi + # 平台脚本和 API 都在 /api/sdp 下 + api="$server/api/sdp" + if [ -z "${TOKEN:-}" ]; then + echo "缺少 token(部署平台 TOKEN)" + exit 1 + fi + if [ -z "${IMAGE_NAME:-}" ]; then + echo "缺少 image(镜像名)" + exit 1 + fi + + if [ -n "${REGISTRY:-}" ]; then + image="${REGISTRY%/}/${IMAGE_NAME}" + else + image="$IMAGE_NAME" + fi + + echo "server: $api" + echo "image: $image" + + curl -fsSL "$api/scripts/push-image" | bash -s -- \ + --token "$TOKEN" \ + --image "$image" \ + --server "$api"