@@ -776,7 +776,8 @@ def commands_step(path, commands):
776
776
step ("zip:embedded" , _path , prefix )
777
777
elif len (c ) == 1 :
778
778
prefix = None
779
- step ("zip:embedded" , path , prefix )
779
+ _path = None
780
+ step ("zip:embedded" , _path , prefix )
780
781
else :
781
782
raise ValueError (
782
783
":zip invalid call signature, use: "
@@ -788,6 +789,8 @@ def commands_step(path, commands):
788
789
step ("sh" , path , "\n " .join (batch ))
789
790
batch .clear ()
790
791
792
+ step ("reset:workdir" )
793
+
791
794
for claim in claims :
792
795
if isinstance (claim , str ):
793
796
path = claim
@@ -884,6 +887,8 @@ def commands_step(path, commands):
884
887
return build_plan
885
888
886
889
def execute (self , build_plan , zip_stream , query ):
890
+ tf_work_dir = os .getcwd ()
891
+
887
892
zs = zip_stream
888
893
sh_work_dir = None
889
894
pf = None
@@ -893,10 +898,14 @@ def execute(self, build_plan, zip_stream, query):
893
898
if cmd .startswith ("zip" ):
894
899
ts = 0 if cmd == "zip:embedded" else None
895
900
source_path , prefix = action [1 :]
896
- if sh_work_dir :
897
- if source_path != sh_work_dir :
898
- if not os .path .isfile (source_path ):
899
- source_path = sh_work_dir
901
+ if not sh_work_dir :
902
+ sh_work_dir = tf_work_dir
903
+ log .info ("WORKDIR: %s" , sh_work_dir )
904
+ if source_path :
905
+ if not os .path .isabs (source_path ):
906
+ source_path = os .path .join (sh_work_dir , source_path )
907
+ else :
908
+ source_path = sh_work_dir
900
909
if os .path .isdir (source_path ):
901
910
if pf :
902
911
self ._zip_write_with_filter (
@@ -944,10 +953,17 @@ def execute(self, build_plan, zip_stream, query):
944
953
elif cmd == "sh" :
945
954
with tempfile .NamedTemporaryFile (mode = "w+t" , delete = True ) as temp_file :
946
955
path , script = action [1 :]
947
- # NOTE: Execute `pwd` to determine the subprocess shell's working directory after having executed all other commands.
956
+
957
+ if not path :
958
+ path = tf_work_dir
959
+ if not os .path .isabs (path ):
960
+ path = os .path .join (tf_work_dir , path )
961
+
948
962
script = "\n " .join (
949
963
(
950
964
script ,
965
+ # NOTE: Execute `pwd` to determine the subprocess shell's
966
+ # working directory after having executed all other commands.
951
967
"retcode=$?" ,
952
968
f"pwd >{ temp_file .name } " ,
953
969
"exit $retcode" ,
@@ -968,7 +984,7 @@ def execute(self, build_plan, zip_stream, query):
968
984
# NOTE: This var `sh_work_dir` is consumed in cmd == "zip" loop
969
985
sh_work_dir = temp_file .read ().strip ()
970
986
971
- log .info ("WD : %s" , sh_work_dir )
987
+ log .info ("WORKDIR : %s" , sh_work_dir )
972
988
973
989
call_stdout , call_stderr = p .communicate ()
974
990
exit_code = p .returncode
@@ -981,6 +997,8 @@ def execute(self, build_plan, zip_stream, query):
981
997
call_stderr .decode ("utf-8" ).strip (),
982
998
)
983
999
)
1000
+ elif cmd == "reset:workdir" :
1001
+ sh_work_dir = tf_work_dir
984
1002
elif cmd == "set:filter" :
985
1003
patterns = action [1 ]
986
1004
pf = ZipContentFilter (args = self ._args )
0 commit comments