From 82a99143b0808e23a318ced80481e2b7b63af579 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 28 Nov 2021 01:38:39 +0900 Subject: [PATCH] include/msg/dist: Add information about sources to dist message Dist messages do not carry any information about the sources used to build the artifacts, making it needlessly complicated to trace the build/distribution. This commit adds fields for the repository, branch, and commit that the artifacts were built from. Further, this commit renames the field for the package repository to "distribution" so it won't be confused with the source repository. --- include/msg/dist.sh | 53 +++++++++++++++++++++++++++++++++++++++++---- spec/dist.json | 24 ++++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/include/msg/dist.sh b/include/msg/dist.sh index 5352916..5f881b3 100644 --- a/include/msg/dist.sh +++ b/include/msg/dist.sh @@ -13,7 +13,10 @@ __init() { foundry_msg_dist_new() { local context="$1" local repository="$2" - local artifacts=("${@:3}") + local branch="$3" + local ref="$4" + local distribution="$5" + local artifacts=("${@:6}") local artifacts_json local json @@ -23,9 +26,12 @@ foundry_msg_dist_new() { return 1 fi - if ! json=$(json_object "context" "$context" \ - "repository" "$repository" \ - "artifacts" "$artifacts_json"); then + if ! json=$(json_object "context" "$context" \ + "repository" "$repository" \ + "branch" "$branch" \ + "ref" "$ref" \ + "distribution" "$distribution" \ + "artifacts" "$artifacts_json"); then return 1 fi @@ -63,6 +69,45 @@ foundry_msg_dist_get_repository() { return 0 } +foundry_msg_dist_get_branch() { + local msg="$1" + + local branch + + if ! branch=$(foundry_msg_get_data_field "$msg" "branch"); then + return 1 + fi + + echo "$branch" + return 0 +} + +foundry_msg_dist_get_ref() { + local msg="$1" + + local ref + + if ! ref=$(foundry_msg_get_data_field "$msg" "ref"); then + return 1 + fi + + echo "$ref" + return 0 +} + +foundry_msg_dist_get_distribution() { + local msg="$1" + + local distribution + + if ! distribution=$(foundry_msg_get_data_field "$msg" "distribution"); then + return 1 + fi + + echo "$distribution" + return 0 +} + foundry_msg_dist_get_artifacts() { local msg="$1" diff --git a/spec/dist.json b/spec/dist.json index 014334d..41ea791 100644 --- a/spec/dist.json +++ b/spec/dist.json @@ -10,6 +10,23 @@ "type": "string" }, + "repository": { + "description": "The URL of the repository that the artifacts were built from", + "type": "string", + "pattern": "^(https|file)://.*$" + }, + + "branch": { + "description": "The name of the branch the artifacts were built from", + "type": "string" + }, + + "ref": { + "description": "Identifier of the source code version", + "type": "string", + "pattern": "^[0-9a-fA-F]+$" + }, + "artifacts": { "description": "Artifacts that were published", "type": "array", @@ -19,7 +36,7 @@ "minItems": 1 }, - "repository": { + "distribution": { "description": "The repository where the artifacts were published", "type": "string" } @@ -27,8 +44,11 @@ "required": [ "context", + "repository", + "branch", + "ref", "artifacts", - "repository" + "distribution" ], "$defs": { -- 2.47.3