Interpolating inputs straight into the JSON string let a quote in image or tag break the payload. Also replaces GNU-only head -n -1 so the action runs on BSD/macOS runners.
47 lines
1.7 KiB
YAML
47 lines
1.7 KiB
YAML
name: "Deploy via package-updater"
|
|
description: "Notifies package-updater to pull & restart a Docker Compose service"
|
|
inputs:
|
|
endpoint:
|
|
description: "Full URL to /update (e.g. https://updater.example.com/update)"
|
|
required: true
|
|
image:
|
|
description: "Image reference without tag (e.g. registry.example.com/myapp)"
|
|
required: true
|
|
tag:
|
|
description: "Tag that was just pushed. Required in practice for swarm instances — it becomes the image the service is set to. Omit it and swarm deploys :latest."
|
|
required: false
|
|
default: ""
|
|
token:
|
|
description: "Bearer token for package-updater"
|
|
required: true
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Trigger update
|
|
shell: bash
|
|
env:
|
|
ENDPOINT: ${{ inputs.endpoint }}
|
|
IMAGE: ${{ inputs.image }}
|
|
TAG: ${{ inputs.tag }}
|
|
TOKEN: ${{ inputs.token }}
|
|
run: |
|
|
set -euo pipefail
|
|
# Build the payload with jq so quotes or backslashes in the inputs
|
|
# cannot break out of the JSON string.
|
|
payload=$(jq -nc --arg image "$IMAGE" --arg tag "$TAG" \
|
|
'{image: $image, tag: $tag}')
|
|
response=$(curl -sS -w "\n%{http_code}" \
|
|
-X POST "$ENDPOINT" \
|
|
-H "Authorization: Bearer $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload")
|
|
# Split on the last newline: curl's -w appended the status code
|
|
# there. Pure bash — `head -n -1` is GNU-only and fails on BSD/macOS.
|
|
code="${response##*$'\n'}"
|
|
body="${response%$'\n'*}"
|
|
echo "HTTP $code"
|
|
printf '%s' "$body" | jq . || printf '%s\n' "$body"
|
|
if [ "$code" -ge 400 ]; then
|
|
exit 1
|
|
fi
|