@sasjs/core 4.43.0 → 4.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mf_getgitbranch.sas +37 -0
- package/base/mf_readfile.sas +63 -0
- package/base/mp_dirlist.sas +1 -2
- package/base/mp_gitadd.sas +1 -2
- package/base/mp_gitlog.sas +99 -0
- package/base/mp_gitstatus.sas +6 -6
- package/base/mp_hashdirectory.sas +5 -3
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Retrieves the current branch from a local GIT repo
|
|
4
|
+
@details In a local git repository, the current branch is always available in
|
|
5
|
+
the `.git/HEAD` file in a format like this: `ref: refs/heads/master`
|
|
6
|
+
|
|
7
|
+
This macro simply reads the file and returns the last word (eg `master`).
|
|
8
|
+
|
|
9
|
+
Example usage:
|
|
10
|
+
|
|
11
|
+
%let gitdir=%sysfunc(pathname(work))/core;
|
|
12
|
+
%let repo=https://github.com/sasjs/core;
|
|
13
|
+
%put source clone rc=%sysfunc(GITFN_CLONE(&repo,&gitdir));
|
|
14
|
+
|
|
15
|
+
%put The current branch is %mf_getgitbranch(&gitdir);
|
|
16
|
+
|
|
17
|
+
@param [in] gitdir The directory containing the GIT repository
|
|
18
|
+
|
|
19
|
+
<h4> SAS Macros </h4>
|
|
20
|
+
@li mf_readfile.sas
|
|
21
|
+
|
|
22
|
+
<h4> Related Macros </h4>
|
|
23
|
+
@li mp_gitadd.sas
|
|
24
|
+
@li mp_gitlog.sas
|
|
25
|
+
@li mp_gitreleaseinfo.sas
|
|
26
|
+
@li mp_gitstatus.sas
|
|
27
|
+
|
|
28
|
+
@version 9.2
|
|
29
|
+
@author Allan Bowe
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mf_getgitbranch(gitdir
|
|
33
|
+
)/*/STORE SOURCE*/;
|
|
34
|
+
|
|
35
|
+
%scan(%mf_readfile(&gitdir/.git/HEAD),-1)
|
|
36
|
+
|
|
37
|
+
%mend mf_getgitbranch;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Reads the first line of a file using pure macro
|
|
4
|
+
@details Reads the first line of a file and returns it. Future versions may
|
|
5
|
+
read each line into a macro variable array.
|
|
6
|
+
|
|
7
|
+
Generally, reading data into macro variables is not great as certain
|
|
8
|
+
nonprintable characters (such as CR, LF) may be dropped in the conversion.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
|
|
12
|
+
%mf_writefile(&sasjswork/myfile.txt,l1=some content,l2=more content)
|
|
13
|
+
|
|
14
|
+
%put %mf_readfile(&sasjswork/myfile.txt);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@param [in] fpath Full path to file to be read
|
|
18
|
+
|
|
19
|
+
<h4> Related Macros </h4>
|
|
20
|
+
@li mf_deletefile.sas
|
|
21
|
+
@li mf_writefile.sas
|
|
22
|
+
@li mf_readfile.test.sas
|
|
23
|
+
|
|
24
|
+
@version 9.2
|
|
25
|
+
@author Allan Bowe
|
|
26
|
+
**/
|
|
27
|
+
/** @cond */
|
|
28
|
+
|
|
29
|
+
%macro mf_readfile(fpath
|
|
30
|
+
)/*/STORE SOURCE*/;
|
|
31
|
+
%local fref rc fid fcontent;
|
|
32
|
+
|
|
33
|
+
/* check file exists */
|
|
34
|
+
%if %sysfunc(filename(fref,&fpath)) ne 0 %then %do;
|
|
35
|
+
%put &=fref &=fpath;
|
|
36
|
+
%put %str(ERR)OR: %sysfunc(sysmsg());
|
|
37
|
+
%return;
|
|
38
|
+
%end;
|
|
39
|
+
|
|
40
|
+
%let fid=%sysfunc(fopen(&fref,I));
|
|
41
|
+
|
|
42
|
+
%if &fid=0 %then %do;
|
|
43
|
+
%put %str(ERR)OR: %sysfunc(sysmsg());
|
|
44
|
+
%return;
|
|
45
|
+
%end;
|
|
46
|
+
|
|
47
|
+
%if %sysfunc(fread(&fid)) = 0 %then %do;
|
|
48
|
+
%let rc=%sysfunc(fget(&fid,fcontent,65534));
|
|
49
|
+
&fcontent
|
|
50
|
+
%end;
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
%do %while(%sysfunc(fread(&fid)) = 0);
|
|
54
|
+
%let rc=%sysfunc(fget(&fid,fcontent,65534));
|
|
55
|
+
&fcontent
|
|
56
|
+
%end;
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
%let rc=%sysfunc(fclose(&fid));
|
|
60
|
+
%let rc=%sysfunc(filename(&fref));
|
|
61
|
+
|
|
62
|
+
%mend mf_readfile;
|
|
63
|
+
/** @endcond */
|
package/base/mp_dirlist.sas
CHANGED
|
@@ -101,8 +101,7 @@ data &out_ds(compress=no
|
|
|
101
101
|
if did=0 then do;
|
|
102
102
|
putlog "NOTE: This directory is empty, or does not exist - &path";
|
|
103
103
|
msg=sysmsg();
|
|
104
|
-
put
|
|
105
|
-
put _all_;
|
|
104
|
+
put (_all_)(=);
|
|
106
105
|
stop;
|
|
107
106
|
end;
|
|
108
107
|
/* attribute is OS-dependent - could be "Directory" or "Directory Name" */
|
package/base/mp_gitadd.sas
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
@details Uses the output dataset from mp_gitstatus.sas to determine the files
|
|
5
5
|
that should be staged.
|
|
6
6
|
|
|
7
|
-
If STAGED
|
|
8
|
-
char column if staging all observations).
|
|
7
|
+
If `STAGED ne "TRUE"` then the file is staged.
|
|
9
8
|
|
|
10
9
|
Usage:
|
|
11
10
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Creates a dataset with the commit history of a local repository
|
|
4
|
+
@details Returns the commit history from a local repository. The name of the
|
|
5
|
+
branch is also returned.
|
|
6
|
+
|
|
7
|
+
More details here:
|
|
8
|
+
https://documentation.sas.com/doc/ko/pgmsascdc/v_033/lefunctionsref/n1qo5miyvry1nen111js203hlwrh.htm
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
|
|
12
|
+
%let gitdir=%sysfunc(pathname(work))/core;
|
|
13
|
+
%let repo=https://github.com/sasjs/core;
|
|
14
|
+
%put source clone rc=%sysfunc(GITFN_CLONE(&repo,&dir));
|
|
15
|
+
|
|
16
|
+
%mp_gitlog(&gitdir,outds=work.mp_gitlog)
|
|
17
|
+
|
|
18
|
+
@param [in] gitdir The directory containing the GIT repository
|
|
19
|
+
@param [in] filter= (BRANCHONLY) To return only the commits for the current
|
|
20
|
+
branch, use BRANCHONLY (the default). Anything else will return the entire
|
|
21
|
+
commit history.
|
|
22
|
+
@param [out] outds= (work.mp_gitlog) The output dataset to create.
|
|
23
|
+
All vars are $128 except `message` which is $4000.
|
|
24
|
+
@li author returns the author who submitted the commit.
|
|
25
|
+
@li children_ids returns a list of the children commit IDs
|
|
26
|
+
@li committer returns the name of the committer.
|
|
27
|
+
@li committer_email returns the email of the committer.
|
|
28
|
+
@li email returns the email of the commit author.
|
|
29
|
+
@li id returns the commit ID of the commit object.
|
|
30
|
+
@li in_current_branch returns "TRUE" or "FALSE" to indicate if the commit is
|
|
31
|
+
in the current branch.
|
|
32
|
+
@li message returns the commit message.
|
|
33
|
+
@li parent_ids returns a list of the parent commit IDs.
|
|
34
|
+
@li stash returns "TRUE" or "FALSE" to indicate if the commit is a stash
|
|
35
|
+
commit.
|
|
36
|
+
@li time returns the time of the commit as numeric string
|
|
37
|
+
@li commit_time_num time of the commit as numeric SAS datetime
|
|
38
|
+
@li commit_time_str the commit_time_num variable cast as string
|
|
39
|
+
|
|
40
|
+
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
|
41
|
+
|
|
42
|
+
<h4> SAS Macros </h4>
|
|
43
|
+
@li mf_getgitbranch.sas
|
|
44
|
+
|
|
45
|
+
<h4> Related Files </h4>
|
|
46
|
+
@li mp_gitadd.sas
|
|
47
|
+
@li mp_gitreleaseinfo.sas
|
|
48
|
+
@li mp_gitstatus.sas
|
|
49
|
+
|
|
50
|
+
**/
|
|
51
|
+
|
|
52
|
+
%macro mp_gitlog(gitdir,outds=work.mp_gitlog,mdebug=0,filter=BRANCHONLY);
|
|
53
|
+
|
|
54
|
+
%local varlist i var;
|
|
55
|
+
%let varlist=author children_ids committer committer_email email id
|
|
56
|
+
in_current_branch parent_ids stash time ;
|
|
57
|
+
|
|
58
|
+
data &outds;
|
|
59
|
+
LENGTH gitdir branch $ 1024 message $4000 &varlist $128 commit_time_num 8.
|
|
60
|
+
commit_time_str $32;
|
|
61
|
+
call missing (of _all_);
|
|
62
|
+
branch="%mf_getgitbranch(&gitdir)";
|
|
63
|
+
gitdir=symget('gitdir');
|
|
64
|
+
rc=git_status_free(trim(gitdir));
|
|
65
|
+
if rc=-1 then do;
|
|
66
|
+
put "The libgit2 library is unavailable and no Git operations can be used.";
|
|
67
|
+
put "See: https://stackoverflow.com/questions/74082874";
|
|
68
|
+
stop;
|
|
69
|
+
end;
|
|
70
|
+
else if rc=-2 then do;
|
|
71
|
+
put "The libgit2 library is available, but the status function failed.";
|
|
72
|
+
put "See the log for details.";
|
|
73
|
+
stop;
|
|
74
|
+
end;
|
|
75
|
+
entries=git_commit_log(trim(gitdir));
|
|
76
|
+
do n=1 to entries;
|
|
77
|
+
|
|
78
|
+
%do i=1 %to %sysfunc(countw(&varlist message));
|
|
79
|
+
%let var=%scan(&varlist message,&i,%str( ));
|
|
80
|
+
rc=git_commit_get(n,trim(gitdir),"&var",&var);
|
|
81
|
+
%end;
|
|
82
|
+
/* convert unix time to SAS time - https://4gl.uk/corelink0 */
|
|
83
|
+
/* Number of seconds between 01JAN1960 and 01JAN1970: 315619200 */
|
|
84
|
+
format commit_time_num datetime19.;
|
|
85
|
+
commit_time_num=sum(input(cats(time),best.),315619200);
|
|
86
|
+
commit_time_str=put(commit_time_num,datetime19.);
|
|
87
|
+
%if &mdebug=1 %then %do;
|
|
88
|
+
putlog (_all_)(=);
|
|
89
|
+
%end;
|
|
90
|
+
if "&filter"="BRANCHONLY" then do;
|
|
91
|
+
if cats(in_current_branch)='TRUE' then output;
|
|
92
|
+
end;
|
|
93
|
+
else output;
|
|
94
|
+
end;
|
|
95
|
+
rc=git_commit_free(trim(gitdir));
|
|
96
|
+
keep gitdir branch &varlist message time commit_time_num commit_time_str;
|
|
97
|
+
run;
|
|
98
|
+
|
|
99
|
+
%mend mp_gitlog;
|
package/base/mp_gitstatus.sas
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
@file
|
|
3
3
|
@brief Creates a dataset with the output from `GIT_STATUS()`
|
|
4
4
|
@details Uses `git_status()` to fetch the number of changed files, then
|
|
5
|
-
iterates
|
|
6
|
-
|
|
5
|
+
iterates with `git_status_get()`, inserting all attributes into an output
|
|
6
|
+
dataset.
|
|
7
7
|
|
|
8
8
|
Usage:
|
|
9
9
|
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
|
|
16
16
|
%mp_gitstatus(&dir,outds=work.gitstatus)
|
|
17
17
|
|
|
18
|
-
More info on these functions is in this [helpful paper]
|
|
19
|
-
https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3057-2019.pdf
|
|
20
|
-
|
|
18
|
+
More info on these functions is in this [helpful paper]
|
|
19
|
+
(https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3057-2019.pdf)
|
|
20
|
+
by Danny Zimmerman.
|
|
21
21
|
|
|
22
22
|
@param [in] gitdir The directory containing the GIT repository
|
|
23
23
|
@param [out] outds= (work.git_status) The output dataset to create. Vars:
|
|
@@ -60,7 +60,7 @@ data &outds;
|
|
|
60
60
|
putlog (_all_)(=);
|
|
61
61
|
%end;
|
|
62
62
|
end;
|
|
63
|
-
rc=git_status_free(gitdir);
|
|
63
|
+
rc=git_status_free(trim(gitdir));
|
|
64
64
|
drop rc cnt;
|
|
65
65
|
run;
|
|
66
66
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
create a hash for each directory also.
|
|
6
6
|
|
|
7
7
|
This makes use of the new `hashing_file()` and `hashing` functions, available
|
|
8
|
-
since 9.4m6. Interestingly,
|
|
8
|
+
since 9.4m6. Interestingly, those functions can be used in pure macro, eg:
|
|
9
9
|
|
|
10
10
|
%put %sysfunc(hashing_file(md5,/path/to/file.blob,0));
|
|
11
11
|
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
@li If a folder contains other folders, start from the bottom of the tree -
|
|
31
31
|
the folder hashes cascade upwards so you know immediately if there is a
|
|
32
32
|
change in a sub/sub directory
|
|
33
|
-
@li If
|
|
33
|
+
@li If a subfolder has no content (empty) then it is ignored. No hash created.
|
|
34
34
|
@li If the file is empty, it is also ignored / no hash created.
|
|
35
|
+
@li If the target directory (&inloc) is empty, &outds will also be empty
|
|
35
36
|
|
|
36
37
|
<h4> SAS Macros </h4>
|
|
37
38
|
@li mp_dirlist.sas
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
iftrue=%str(1=1)
|
|
73
74
|
)/*/STORE SOURCE*/;
|
|
74
75
|
|
|
75
|
-
%local curlevel tempds ;
|
|
76
|
+
%local curlevel tempds maxlevel;
|
|
76
77
|
|
|
77
78
|
%if not(%eval(%unquote(&iftrue))) %then %return;
|
|
78
79
|
|
|
@@ -108,6 +109,7 @@ proc sort data=&outds ;
|
|
|
108
109
|
by descending level directory file_path;
|
|
109
110
|
run;
|
|
110
111
|
|
|
112
|
+
%let maxlevel=0;
|
|
111
113
|
data _null_;
|
|
112
114
|
set &outds;
|
|
113
115
|
call symputx('maxlevel',level,'l');
|
package/package.json
CHANGED