Skip to content

Commit

Permalink
added assets option for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
KDesp73 committed Oct 31, 2024
1 parent ac1e5e1 commit 566a56b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
9 changes: 6 additions & 3 deletions docs/_changelogger.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ _changelogger() {
'--remote-repo[Specify the URL of the remote repo]' \
'--editor[Specify the editor to use]' \
'--always-push[Specify whether to immediately push the release]' \
'--always-export[Specify whether to export the CHANGELOG.md file]'
'--always-export[Specify whether to export the CHANGELOG.md file]' \
'--version-ful[Set the current version of the project]'
;;
list)
_arguments \
Expand Down Expand Up @@ -78,7 +79,8 @@ _changelogger() {
_arguments \
'-h[Prints the help message]' \
'-V[Specify the version of the release you want to push]' \
'-y[Skip the confirmation message]'
'-y[Skip the confirmation message]' \
'-B[Include an asset with the release]'
;;
release)
_arguments \
Expand All @@ -87,7 +89,8 @@ _changelogger() {
'-p[Push the release on GitHub]' \
'-y[Skip the confirmation message]' \
'-Y[Set a release as YANKED]' \
'-U[Set a release as not YANKED]'
'-U[Set a release as not YANKED]' \
'-B[Include an asset with the release]'
;;
edit)
_arguments \
Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CONFIG_H

#define EXECUTABLE_NAME "changelogger"
#define VERSION "0.0.13"
#define VERSION "0.0.14"
#define CHANGELOG_FILE "CHANGELOG.md"
#define CHANGELOG_DIR ".changelog"
#define SQLITE_DB ".changelog/changelog.db"
Expand Down
4 changes: 3 additions & 1 deletion include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ typedef enum {
ABBR_ALL = 'A',
ABBR_ALWAYS_EXPORT = 'E',
ABBR_ALWAYS_PUSH = 'P',
ABBR_ASSET = 'B', // for binary
ABBR_COMMITS = 'C',
ABBR_CONFIG_PATH = 'c',
ABBR_EDITOR = 'e',
ABBR_FILE = 'f',
ABBR_FORMAT = 'F',
ABBR_HELP = 'h',
Expand All @@ -25,7 +27,6 @@ typedef enum {
ABBR_VERSION_FULL = 'V',
ABBR_YANK = 'Y',
ABBR_YES = 'y',
ABBR_EDITOR = 'e',
} ArgumentAbbr;

typedef struct {
Expand All @@ -51,6 +52,7 @@ typedef struct {
_Bool releases;
_Bool commits;
const char* editor;
const char* asset;
} Options;

int always_push_set(Options options);
Expand Down
20 changes: 15 additions & 5 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,26 @@ int is_gh_cli_available() {
return 1;
}


void push_release(const char* version)
void push_release(const char* version, const char* asset)
{
if (!is_gh_cli_available()){
exit(1);
}

command_export((Options){0});
char* gh_command = clib_format_text("gh release create v%s -F %s/%s.md -t v%s", version, CHANGELOG_DIR, version, version);

char* asset_str = clib_format_text(" '%s' ", asset);
char* gh_command = clib_format_text(
"gh release create v%s%s-F %s/%s.md -t v%s",
version,
(asset) ? asset_str : " ",
CHANGELOG_DIR,
version,
version
);
printf("%s\n", gh_command);
clib_execute_command(gh_command);
free(asset_str);
free(gh_command);
}

Expand All @@ -791,7 +801,7 @@ void handle_push_release(const char* version, Options options)
}

make_sure_user_wants_to_proceed_with_releasing(options);
push_release(version);
push_release(version, options.asset);
update(TABLE_RELEASES, RELEASES_PUSHED, "1", condition);
free(condition);
}
Expand Down Expand Up @@ -844,7 +854,7 @@ void command_release(Options options)

if(!should_push) return; // Do not push the release on Github

push_release(version);
push_release(version, options.asset);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void push_help()
PTNI("-h --help Prints this message");
PTNI("-V --version-full Specify the version of the release you want to push");
PTNI("-y --yes Skip the confirmation message");
PTNI("-B --asset <path> Include an asset in the release");
}

void release_help()
Expand All @@ -151,6 +152,7 @@ void release_help()
PTNI("-y --yes Skip the confirmation message");
PTNI("-Y --yank <version> Set a release as YANKED");
PTNI("-U --unyank <version> Set a release as not YANKED");
PTNI("-B --asset <path> Include an asset in the release");
}

void edit_help()
Expand Down
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "options.h"
#include "status.h"
#include "version.h"
#include <bits/getopt_ext.h>
#include <stdio.h>

#define CLIB_IMPLEMENTATION
Expand Down Expand Up @@ -84,10 +85,11 @@ Options parse_options(int argc, char** argv, Command* command)

// NOTE: The help fields are not set since
// the help message is written by hand
CliArguments args = clib_make_cli_arguments(22,
CliArguments args = clib_make_cli_arguments(23,
clib_create_argument(ABBR_ALL, "all", "", no_argument),
clib_create_argument(ABBR_ALWAYS_EXPORT, "always-export", "", required_argument),
clib_create_argument(ABBR_ALWAYS_PUSH, "always-push", "", required_argument),
clib_create_argument(ABBR_ASSET, "asset", "", required_argument),
clib_create_argument(ABBR_COMMITS, "commits", "", no_argument),
clib_create_argument(ABBR_CONFIG_PATH, "config-path", "", required_argument),
clib_create_argument(ABBR_EDITOR, "editor", "", required_argument),
Expand Down Expand Up @@ -218,6 +220,11 @@ Options parse_options(int argc, char** argv, Command* command)

options.editor = optarg;
break;
case ABBR_ASSET:
CHECK_USABILITY(COMMAND_PUSH, COMMAND_RELEASE);

options.asset = optarg;
break;
default:
CLEANUP;
exit(1);
Expand Down
1 change: 1 addition & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int is_number(const char *str)

return has_digits;
}

void append_line(const char* file, const char* line, size_t index)
{
FILE *fp = fopen(file, "r");
Expand Down

0 comments on commit 566a56b

Please sign in to comment.