Skip to content

Commit

Permalink
FEAT: Releasing 4.44.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sasjssrv committed Nov 30, 2022
1 parent 8e5416f commit fc483a7
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
github_token: ${{ secrets.GH_TOKEN }}
branch: main
draft: false
version: 4.43.0
description: 'Version 4.43.0 of sasjs/core is now on SAS PACKAGES :ok_hand:'
version: 4.44.0
description: 'Version 4.44.0 of sasjs/core is now on SAS PACKAGES :ok_hand:'
37 changes: 37 additions & 0 deletions 005_macros/mf_getgitbranch.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*** HELP START ***//**
@file
@brief Retrieves the current branch from a local GIT repo
@details In a local git repository, the current branch is always available in
the `.git/HEAD` file in a format like this: `ref: refs/heads/master`
This macro simply reads the file and returns the last word (eg `master`).
Example usage:
%let gitdir=%sysfunc(pathname(work))/core;
%let repo=https://github.com/sasjs/core;
%put source clone rc=%sysfunc(GITFN_CLONE(&repo,&gitdir));
%put The current branch is %mf_getgitbranch(&gitdir);
@param [in] gitdir The directory containing the GIT repository
<h4> SAS Macros </h4>
@li mf_readfile.sas
<h4> Related Macros </h4>
@li mp_gitadd.sas
@li mp_gitlog.sas
@li mp_gitreleaseinfo.sas
@li mp_gitstatus.sas
@version 9.2
@author Allan Bowe
**//*** HELP END ***/

%macro mf_getgitbranch(gitdir
)/*/STORE SOURCE*/;

%scan(%mf_readfile(&gitdir/.git/HEAD),-1)

%mend mf_getgitbranch;
63 changes: 63 additions & 0 deletions 005_macros/mf_readfile.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*** HELP START ***//**
@file
@brief Reads the first line of a file using pure macro
@details Reads the first line of a file and returns it. Future versions may
read each line into a macro variable array.
Generally, reading data into macro variables is not great as certain
nonprintable characters (such as CR, LF) may be dropped in the conversion.
Usage:
%mf_writefile(&sasjswork/myfile.txt,l1=some content,l2=more content)
%put %mf_readfile(&sasjswork/myfile.txt);
@param [in] fpath Full path to file to be read
<h4> Related Macros </h4>
@li mf_deletefile.sas
@li mf_writefile.sas
@li mf_readfile.test.sas
@version 9.2
@author Allan Bowe
**//*** HELP END ***/
/** @cond */

%macro mf_readfile(fpath
)/*/STORE SOURCE*/;
%local fref rc fid fcontent;

/* check file exists */
%if %sysfunc(filename(fref,&fpath)) ne 0 %then %do;
%put &=fref &=fpath;
%put %str(ERR)OR: %sysfunc(sysmsg());
%return;
%end;

%let fid=%sysfunc(fopen(&fref,I));

%if &fid=0 %then %do;
%put %str(ERR)OR: %sysfunc(sysmsg());
%return;
%end;

%if %sysfunc(fread(&fid)) = 0 %then %do;
%let rc=%sysfunc(fget(&fid,fcontent,65534));
&fcontent
%end;

/*
%do %while(%sysfunc(fread(&fid)) = 0);
%let rc=%sysfunc(fget(&fid,fcontent,65534));
&fcontent
%end;
*/

%let rc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(&fref));

%mend mf_readfile;
/** @endcond */
3 changes: 1 addition & 2 deletions 005_macros/mp_dirlist.sas
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ data &out_ds(compress=no
if did=0 then do;
putlog "NOTE: This directory is empty, or does not exist - &path";
msg=sysmsg();
put msg;
put _all_;
put (_all_)(=);
stop;
end;
/* attribute is OS-dependent - could be "Directory" or "Directory Name" */
Expand Down
3 changes: 1 addition & 2 deletions 005_macros/mp_gitadd.sas
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
@details Uses the output dataset from mp_gitstatus.sas to determine the files
that should be staged.
If STAGED != `"TRUE"` then the file is staged (so you could provide an empty
char column if staging all observations).
If `STAGED ne "TRUE"` then the file is staged.
Usage:
Expand Down
99 changes: 99 additions & 0 deletions 005_macros/mp_gitlog.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*** HELP START ***//**
@file
@brief Creates a dataset with the commit history of a local repository
@details Returns the commit history from a local repository. The name of the
branch is also returned.
More details here:
https://documentation.sas.com/doc/ko/pgmsascdc/v_033/lefunctionsref/n1qo5miyvry1nen111js203hlwrh.htm
Usage:
%let gitdir=%sysfunc(pathname(work))/core;
%let repo=https://github.com/sasjs/core;
%put source clone rc=%sysfunc(GITFN_CLONE(&repo,&dir));
%mp_gitlog(&gitdir,outds=work.mp_gitlog)
@param [in] gitdir The directory containing the GIT repository
@param [in] filter= (BRANCHONLY) To return only the commits for the current
branch, use BRANCHONLY (the default). Anything else will return the entire
commit history.
@param [out] outds= (work.mp_gitlog) The output dataset to create.
All vars are $128 except `message` which is $4000.
@li author returns the author who submitted the commit.
@li children_ids returns a list of the children commit IDs
@li committer returns the name of the committer.
@li committer_email returns the email of the committer.
@li email returns the email of the commit author.
@li id returns the commit ID of the commit object.
@li in_current_branch returns "TRUE" or "FALSE" to indicate if the commit is
in the current branch.
@li message returns the commit message.
@li parent_ids returns a list of the parent commit IDs.
@li stash returns "TRUE" or "FALSE" to indicate if the commit is a stash
commit.
@li time returns the time of the commit as numeric string
@li commit_time_num time of the commit as numeric SAS datetime
@li commit_time_str the commit_time_num variable cast as string
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
<h4> SAS Macros </h4>
@li mf_getgitbranch.sas
<h4> Related Files </h4>
@li mp_gitadd.sas
@li mp_gitreleaseinfo.sas
@li mp_gitstatus.sas
**//*** HELP END ***/

%macro mp_gitlog(gitdir,outds=work.mp_gitlog,mdebug=0,filter=BRANCHONLY);

%local varlist i var;
%let varlist=author children_ids committer committer_email email id
in_current_branch parent_ids stash time ;

data &outds;
LENGTH gitdir branch $ 1024 message $4000 &varlist $128 commit_time_num 8.
commit_time_str $32;
call missing (of _all_);
branch="%mf_getgitbranch(&gitdir)";
gitdir=symget('gitdir');
rc=git_status_free(trim(gitdir));
if rc=-1 then do;
put "The libgit2 library is unavailable and no Git operations can be used.";
put "See: https://stackoverflow.com/questions/74082874";
stop;
end;
else if rc=-2 then do;
put "The libgit2 library is available, but the status function failed.";
put "See the log for details.";
stop;
end;
entries=git_commit_log(trim(gitdir));
do n=1 to entries;

%do i=1 %to %sysfunc(countw(&varlist message));
%let var=%scan(&varlist message,&i,%str( ));
rc=git_commit_get(n,trim(gitdir),"&var",&var);
%end;
/* convert unix time to SAS time - https://4gl.uk/corelink0 */
/* Number of seconds between 01JAN1960 and 01JAN1970: 315619200 */
format commit_time_num datetime19.;
commit_time_num=sum(input(cats(time),best.),315619200);
commit_time_str=put(commit_time_num,datetime19.);
%if &mdebug=1 %then %do;
putlog (_all_)(=);
%end;
if "&filter"="BRANCHONLY" then do;
if cats(in_current_branch)='TRUE' then output;
end;
else output;
end;
rc=git_commit_free(trim(gitdir));
keep gitdir branch &varlist message time commit_time_num commit_time_str;
run;

%mend mp_gitlog;
6 changes: 3 additions & 3 deletions 005_macros/mp_gitstatus.sas
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@file
@brief Creates a dataset with the output from `GIT_STATUS()`
@details Uses `git_status()` to fetch the number of changed files, then
iterates through with `git_status_get()` and `git_index_add()` for each
change - which is created in an output dataset.
iterates with `git_status_get()`, inserting all attributes into an output
dataset.
Usage:
Expand Down Expand Up @@ -60,7 +60,7 @@ data &outds;
putlog (_all_)(=);
%end;
end;
rc=git_status_free(gitdir);
rc=git_status_free(trim(gitdir));
drop rc cnt;
run;

Expand Down
8 changes: 5 additions & 3 deletions 005_macros/mp_hashdirectory.sas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
create a hash for each directory also.
This makes use of the new `hashing_file()` and `hashing` functions, available
since 9.4m6. Interestingly, these can even be used in pure macro, eg:
since 9.4m6. Interestingly, those functions can be used in pure macro, eg:
%put %sysfunc(hashing_file(md5,/path/to/file.blob,0));
Expand All @@ -30,8 +30,9 @@
@li If a folder contains other folders, start from the bottom of the tree -
the folder hashes cascade upwards so you know immediately if there is a
change in a sub/sub directory
@li If the folder has no content (empty) then it is ignored. No hash created.
@li If a subfolder has no content (empty) then it is ignored. No hash created.
@li If the file is empty, it is also ignored / no hash created.
@li If the target directory (&inloc) is empty, &outds will also be empty
<h4> SAS Macros </h4>
@li mp_dirlist.sas
Expand Down Expand Up @@ -72,7 +73,7 @@
iftrue=%str(1=1)
)/*/STORE SOURCE*/;

%local curlevel tempds ;
%local curlevel tempds maxlevel;

%if not(%eval(%unquote(&iftrue))) %then %return;

Expand Down Expand Up @@ -108,6 +109,7 @@ proc sort data=&outds ;
by descending level directory file_path;
run;

%let maxlevel=0;
data _null_;
set &outds;
call symputx('maxlevel',level,'l');
Expand Down
2 changes: 1 addition & 1 deletion description.sas
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: SASjsCore
Title: SAS Macros for Application Development
Version: 4.43.0
Version: 4.44.0
Author: Allan Bowe
Maintainer: 4GL Ltd
License: MIT
Expand Down
Binary file modified sasjscore.zip
Binary file not shown.

0 comments on commit fc483a7

Please sign in to comment.