From 279305ab431847d3d66a77ffca6f2c979ba8752d Mon Sep 17 00:00:00 2001 From: Adrien Date: Mon, 28 Oct 2024 10:37:27 +0100 Subject: [PATCH] feat: support for comma separated list of commits & deliverables --- README.md | 4 ++-- action.yml | 4 ++-- entrypoint.sh | 26 ++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 77197cc..b53dd00 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,9 @@ See [Examples](#examples) below for more details. with: # Optional. Can either be `post-deploy` or `post-status`. Defaults to `post-deploy`. action-type: string - # Required. Newline-separated list of deliverables the deployment contains (e.g., microservice name, application name). Defaults to repository name. + # Required. Newline-separated or comma-separated list of deliverables the deployment contains (e.g., microservice name, application name). Defaults to repository name. deliverables: string - # Required. Newline-separated list of commits SHA shipped as part of the deployment. Defaults to listing commits between the last 2 tags or as a last fallback $GITHUB_SHA. + # Required. Newline-separated or comma-separated list of commits SHA shipped as part of the deployment. Defaults to listing commits between the last 2 tags or as a last fallback $GITHUB_SHA. commits: string # Optional. Version being deployed. version: string diff --git a/action.yml b/action.yml index 6a6eaf7..3ff1703 100644 --- a/action.yml +++ b/action.yml @@ -4,10 +4,10 @@ author: "EchoesHQ" description: "Declare deployments and notify their status to Echoes." inputs: deliverables: - description: "Newline-separated list of deliverables the deployment contains (e.g., microservice name, application name)..." + description: "Newline-separated or comma-separated list of deliverables the deployment contains (e.g., microservice name, application name)..." required: false commits: - description: "Newline-separated list of commits SHA shipped as part of the deployment. Defaults to listing commits between the last 2 tags or as a last fallback $GITHUB_SHA." + description: "Newline-separated or comma-separated list of commits SHA shipped as part of the deployment. Defaults to listing commits between the last 2 tags or as a last fallback $GITHUB_SHA." required: false version: description: "Version being deployed." diff --git a/entrypoint.sh b/entrypoint.sh index 5cc316f..fcc74cc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,10 +14,32 @@ while getopts ":t:v:d:c:u:s:i:" opt; do v) version=$(trim "${OPTARG}") ;; d) - mapfile -t deliverables < <(trim "${OPTARG}") + deliverables=() + + if [[ "${OPTARG}" =~ ^([^,]+,)+[^,]+$ ]]; then # Support comma separated list of deliverables + IFS=',' read -r -a raw_deliverables <<< "${OPTARG}" + else + mapfile -t raw_deliverables < <(echo "${OPTARG}") # Support Newline-separated list of deliverables + fi + + for deliverable in "${raw_deliverables[@]}"; do + trimmed_deliverable=$(trim "$deliverable") + deliverables+=("$trimmed_deliverable") + done ;; c) - mapfile -t commits < <(trim "${OPTARG}") + commits=() + + if [[ "${OPTARG}" =~ ^([^,]+,)+[^,]+$ ]]; then # Support comma separated list of commits + IFS=',' read -r -a raw_commits <<< "${OPTARG}" + else + mapfile -t raw_commits < <(echo "${OPTARG}") # Support Newline-separated list of commits + fi + + for commit in "${raw_commits[@]}"; do + trimmed_commit=$(trim "$commit") + commits+=("$trimmed_commit") + done ;; u) url=$(trim "${OPTARG}") ;;