diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-02-18 10:00:47 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-02-18 10:01:27 -0500 |
commit | 04e0835f29b6d21e8491ba6f35092f1ab860263d (patch) | |
tree | 5de89e718e62cdb6d6bddea7b57a68a3a101e176 | |
parent | c9516dffaf28447b317bae080bdf79b5bb7dea5e (diff) | |
download | stasis-04e0835f29b6d21e8491ba6f35092f1ab860263d.tar.gz |
Extract git repository information
* First pass; this will eventually be used to rewite exact commit refs in YAML delivery files
-rw-r--r-- | include/deliverable.h | 2 | ||||
-rw-r--r-- | include/utils.h | 1 | ||||
-rw-r--r-- | src/deliverable.c | 7 | ||||
-rw-r--r-- | src/utils.c | 22 |
4 files changed, 30 insertions, 2 deletions
diff --git a/include/deliverable.h b/include/deliverable.h index b528c46..85cda6b 100644 --- a/include/deliverable.h +++ b/include/deliverable.h @@ -129,6 +129,8 @@ struct Delivery { char *repository; ///< Git repository of package char *script; ///< Commands to execute char *build_recipe; ///< Conda recipe to build (optional) + char *repository_info_ref; ///< Git commit hash + char *repository_info_tag; ///< Git tag (first parent) struct Runtime runtime; ///< Environment variables specific to the test context } tests[1000]; ///< An array of tests diff --git a/include/utils.h b/include/utils.h index f0400fb..d32a123 100644 --- a/include/utils.h +++ b/include/utils.h @@ -33,6 +33,7 @@ char *find_program(const char *name); int touch(const char *filename); int git_clone(struct Process *proc, char *url, char *destdir, char *gitref); char *git_describe(const char *path); +char *git_rev_parse(const char *path, char *args); int path_store(char **destptr, size_t maxlen, const char *base, const char *path); #define OMC_MSG_SUCCESS 0 diff --git a/src/deliverable.c b/src/deliverable.c index 9b5d94d..e1179a4 100644 --- a/src/deliverable.c +++ b/src/deliverable.c @@ -1302,7 +1302,12 @@ void delivery_tests_run(struct Delivery *ctx) { } } msg(OMC_MSG_L3, "Cloning repository %s\n", ctx->tests[i].repository); - git_clone(&proc, ctx->tests[i].repository, destdir, ctx->tests[i].version); + if (!git_clone(&proc, ctx->tests[i].repository, destdir, ctx->tests[i].version)) { + ctx->tests[i].repository_info_tag = strdup(git_describe(destdir)); + ctx->tests[i].repository_info_ref = strdup(git_rev_parse(destdir, "HEAD")); + } else { + COE_CHECK_ABORT(!globals.continue_on_error, "Unable to clone repository\n") + } if (pushd(destdir)) { COE_CHECK_ABORT(!globals.continue_on_error, "Unable to enter repository directory\n") diff --git a/src/utils.c b/src/utils.c index 12cf22c..d8cf929 100644 --- a/src/utils.c +++ b/src/utils.c @@ -377,7 +377,27 @@ char *git_describe(const char *path) { pushd(path); static char version[NAME_MAX]; FILE *pp; - pp = popen("git describe --always --tags", "r"); + pp = popen("git describe --first-parent --always --tags", "r"); + memset(version, 0, sizeof(version)); + fgets(version, sizeof(version) - 1, pp); + strip(version); + pclose(pp); + popd(); + return version; +} + +char *git_rev_parse(const char *path, char *args) { + pushd(path); + static char version[NAME_MAX]; + char cmd[PATH_MAX]; + FILE *pp; + + if (isempty(args)) { + fprintf(stderr, "git_rev_parse args cannot be empty"); + return NULL; + } + sprintf(cmd, "git rev-parse %s", args); + pp = popen(cmd, "r"); memset(version, 0, sizeof(version)); fgets(version, sizeof(version) - 1, pp); strip(version); |