diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-07-06 09:49:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-06 09:49:51 -0400 |
commit | 8ce824ac4b2f526331093a7150e643700efd4d20 (patch) | |
tree | 99e27dee24e82d78941ded4c510e1bac57c3f015 /src/stasis_main.c | |
parent | abe87056faa6ed02aff3bbf77c1fd78b713a0864 (diff) | |
download | stasis-8ce824ac4b2f526331093a7150e643700efd4d20.tar.gz |
Add github.c and github.h (#9)
* Add github.c and github.h
* Implements get_github_release_notes()
* Remove unused variables
* Fix circular dependency on tplfunc_frame
* Remove predeclaration of tplfunc_frame
* tpl_register_func accepts pointer to void instead
* tpl_register_func sets maximum number of arguments
* Frame is generated within tpl_register_func
* Improve template function error handling and return/output management
* Remove redundant extern statement
* Include github.h and template_func_proto.h in core.h
* Expose get_github_release_notes_tplfunc_entrypoint function to template engine
* Add template_func_proto.c and template_func_proto.h
* Replace free() with guard variant
* Fix test_template::test_tpl_register_func
* Fix tests
* Fix tests
* cmd should be at least PATH_MAX in size.
* Magic number caused failure to install conda with a long installation path
* Implement get_github_release_notes_auto function that bases release note data off test contexts
* Disable overwriting releases by default
* Add automatic release note generation function call to release_notes.md.in
* Fix test_tpl_register_func()
* Add enough space for tar command plus a path
* Fix circular include
* Github functions do not require access to core.h anyway
* Add comments to union
* Update README to mention template function availability
* Add EnvCtl structure
* Add runtime checks to avoid running all the way to the end only to be met with a configuration error.
* Rename GITHUB to GH
* Development docs pre-rough-draft
Diffstat (limited to 'src/stasis_main.c')
-rw-r--r-- | src/stasis_main.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/stasis_main.c b/src/stasis_main.c index c550982..ce49829 100644 --- a/src/stasis_main.c +++ b/src/stasis_main.c @@ -9,6 +9,7 @@ #define OPT_NO_DOCKER 1001 #define OPT_NO_ARTIFACTORY 1002 #define OPT_NO_TESTING 1003 +#define OPT_OVERWRITE 1004 static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, @@ -18,6 +19,7 @@ static struct option long_options[] = { {"verbose", no_argument, 0, 'v'}, {"unbuffered", no_argument, 0, 'U'}, {"update-base", no_argument, 0, OPT_ALWAYS_UPDATE_BASE}, + {"overwrite", no_argument, 0, OPT_OVERWRITE}, {"no-docker", no_argument, 0, OPT_NO_DOCKER}, {"no-artifactory", no_argument, 0, OPT_NO_ARTIFACTORY}, {"no-testing", no_argument, 0, OPT_NO_TESTING}, @@ -33,6 +35,7 @@ const char *long_options_help[] = { "Increase output verbosity", "Disable line buffering", "Update conda installation prior to STASIS environment creation", + "Overwrite an existing release", "Do not build docker images", "Do not upload artifacts to Artifactory", "Do not execute test scripts", @@ -95,7 +98,32 @@ static void usage(char *progname) { } } +static const char *has_envctl_key_(size_t i) { + for (size_t x = 0; globals.envctl[i].name[x] != NULL; x++) { + const char *name = globals.envctl[i].name[x]; + const char *data = getenv(name); + if (data) { + return name; + } + } + return NULL; +} + +static void check_system_env_requirements() { + msg(STASIS_MSG_L1, "Checking environment\n"); + for (size_t i = 0; globals.envctl[i].name[0] != NULL; i++) { + unsigned int flags = globals.envctl[i].flags; + const char *key = has_envctl_key_(i); + if ((flags & STASIS_ENVCTL_REQUIRED) && !(key && strlen(getenv(key)))) { + if (!strcmp(key, "STASIS_JF_REPO") && !globals.enable_artifactory) { + continue; + } + msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "Environment variable '%s' must be configured.\n", globals.envctl[i].name[0]); + exit(1); + } + } +} static void check_system_requirements(struct Delivery *ctx) { const char *tools_required[] = { @@ -139,6 +167,11 @@ static void check_system_requirements(struct Delivery *ctx) { } } +static void check_requirements(struct Delivery *ctx) { + check_system_requirements(ctx); + check_system_env_requirements(); +} + int main(int argc, char *argv[]) { struct Delivery ctx; struct Process proc = { @@ -193,6 +226,9 @@ int main(int argc, char *argv[]) { case 'v': globals.verbose = true; break; + case OPT_OVERWRITE: + globals.enable_overwrite = true; + break; case OPT_NO_DOCKER: globals.enable_docker = false; user_disabled_docker = true; @@ -260,6 +296,11 @@ int main(int argc, char *argv[]) { tpl_register("workaround.tox_posargs", &globals.workaround.tox_posargs); tpl_register("workaround.conda_reactivate", &globals.workaround.conda_reactivate); + // Expose function(s) to the template engine + // Prototypes can be found in template_func_proto.h + tpl_register_func("get_github_release_notes", &get_github_release_notes_tplfunc_entrypoint, 3, NULL); + tpl_register_func("get_github_release_notes_auto", &get_github_release_notes_auto_tplfunc_entrypoint, 1, &ctx); + // Set up PREFIX/etc directory information // The user may manipulate the base directory path with STASIS_SYSCONFDIR // environment variable @@ -325,7 +366,7 @@ int main(int argc, char *argv[]) { msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to initialize delivery context\n"); exit(1); } - check_system_requirements(&ctx); + check_requirements(&ctx); msg(STASIS_MSG_L2, "Configuring JFrog CLI\n"); if (delivery_init_artifactory(&ctx)) { @@ -346,6 +387,12 @@ int main(int argc, char *argv[]) { //delivery_runtime_show(&ctx); } + // Safety gate: Avoid clobbering a delivery unless the user wants that behavior + 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); + exit(1); + } + msg(STASIS_MSG_L1, "Conda setup\n"); delivery_get_installer_url(&ctx, installer_url); msg(STASIS_MSG_L2, "Downloading: %s\n", installer_url); |