diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-07-22 16:02:10 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-07-22 16:02:10 -0400 |
commit | 1741e582ff7b7c18e69a0e5c0c68814c2825766e (patch) | |
tree | 983eb884ba6f4e9413506020e62520e87272f4ee | |
parent | dae644e06e384b39a023a511ac934603e43b4be2 (diff) | |
download | stasis-check-release-jf.tar.gz |
When artifactory is enabled check if the release is already present.check-release-jf
* When artifactory is disabled the check will be made against the local filesystem.
-rw-r--r-- | src/delivery.c | 38 | ||||
-rw-r--r-- | src/stasis_main.c | 5 |
2 files changed, 31 insertions, 12 deletions
diff --git a/src/delivery.c b/src/delivery.c index d7b9b99..8e37bc0 100644 --- a/src/delivery.c +++ b/src/delivery.c @@ -2191,18 +2191,36 @@ int delivery_fixup_test_results(struct Delivery *ctx) { } int delivery_exists(struct Delivery *ctx) { - // TODO: scan artifactory repo for the same information + int release_exists = 0; char release_pattern[PATH_MAX] = {0}; sprintf(release_pattern, "*%s*", ctx->info.release_name); - struct StrList *files = listdir(ctx->storage.delivery_dir); - for (size_t i = 0; i < strlist_count(files); i++) { - char *filename = strlist_item(files, i); - int release_exists = fnmatch(release_pattern, filename, FNM_PATHNAME); - if (!globals.enable_overwrite && !release_exists) { - guard_strlist_free(&files); - return 1; + + if (globals.enable_artifactory) { + if (jfrt_auth_init(&ctx->deploy.jfrog_auth)) { + fprintf(stderr, "Failed to initialize Artifactory authentication context\n"); + return -1; // error + } + + struct JFRT_Search search = {.fail_no_op = true}; + release_exists = jfrog_cli_rt_search(&ctx->deploy.jfrog_auth, &search, globals.jfrog.repo, release_pattern); + if (release_exists != 2) { + if (!globals.enable_overwrite && !release_exists) { + // --fail_no_op returns 2 on failure + // without: it returns an empty list "[]" and exit code 0 + return 1; // found + } } + } else { + struct StrList *files = listdir(ctx->storage.delivery_dir); + for (size_t i = 0; i < strlist_count(files); i++) { + char *filename = strlist_item(files, i); + release_exists = fnmatch(release_pattern, filename, FNM_PATHNAME); + if (!globals.enable_overwrite && !release_exists) { + guard_strlist_free(&files); + return 1; // found + } + } + guard_strlist_free(&files); } - guard_strlist_free(&files); - return 0; + return 0; // not found }
\ No newline at end of file diff --git a/src/stasis_main.c b/src/stasis_main.c index 7e2262a..686c044 100644 --- a/src/stasis_main.c +++ b/src/stasis_main.c @@ -415,9 +415,10 @@ int main(int argc, char *argv[]) { //delivery_runtime_show(&ctx); } - // Safety gate: Avoid clobbering a delivery unless the user wants that behavior + // Safety gate: Avoid clobbering a delivered release unless the user wants that behavior + msg(STASIS_MSG_L1, "Checking release history\n"); if (delivery_exists(&ctx)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Refusing to overwrite delivery: %s\nUse --overwrite to enable release clobbering.\n", ctx.info.release_name); + msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Refusing to overwrite release: %s\nUse --overwrite to enable release clobbering.\n", ctx.info.release_name); exit(1); } |