From 4bcb0dacb6b13c279e55b2a8cd3ddd6271611a09 Mon Sep 17 00:00:00 2001
From: James Ives <iam@jamesiv.es>
Date: Fri, 27 Sep 2024 15:13:16 +0000
Subject: [PATCH] =?UTF-8?q?Deploy=20Production=20Code=20for=20Commit=20c30?=
 =?UTF-8?q?eaca6255fe9a52a0769888b2d63c3e79a25bb=20=F0=9F=9A=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/execute.d.ts | 15 +++++++++++++++
 lib/execute.js   |  6 ++++++
 lib/git.js       | 20 +++++++++++++++++---
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/lib/execute.d.ts b/lib/execute.d.ts
index 4cda3b3b5..618edd924 100644
--- a/lib/execute.d.ts
+++ b/lib/execute.d.ts
@@ -1,5 +1,14 @@
+/**
+ * The output of a command.
+ */
 type ExecuteOutput = {
+    /**
+     * The standard output of the command.
+     */
     stdout: string;
+    /**
+     * The standard error of the command.
+     */
     stderr: string;
 };
 /** Wrapper around the GitHub toolkit exec command which returns the output.
@@ -12,6 +21,12 @@ type ExecuteOutput = {
  * on a non-zero exit status or to leave implementation up to the caller.
  */
 export declare function execute(cmd: string, cwd: string, silent: boolean, ignoreReturnCode?: boolean): Promise<ExecuteOutput>;
+/**
+ * Writes the output of a command to the stdout buffer.
+ */
 export declare function stdout(data: Buffer | string): void;
+/**
+ * Writes the output of a command to the stderr buffer.
+ */
 export declare function stderr(data: Buffer | string): void;
 export {};
diff --git a/lib/execute.js b/lib/execute.js
index 3b0a56607..2520b548d 100644
--- a/lib/execute.js
+++ b/lib/execute.js
@@ -41,6 +41,9 @@ function execute(cmd_1, cwd_1, silent_1) {
         return Promise.resolve(output);
     });
 }
+/**
+ * Writes the output of a command to the stdout buffer.
+ */
 function stdout(data) {
     const dataString = data.toString().trim();
     if (output.stdout.length + dataString.length <
@@ -48,6 +51,9 @@ function stdout(data) {
         output.stdout += dataString;
     }
 }
+/**
+ * Writes the output of a command to the stderr buffer.
+ */
 function stderr(data) {
     const dataString = data.toString().trim();
     if (output.stderr.length + dataString.length <
diff --git a/lib/git.js b/lib/git.js
index 01feede12..a4957030e 100644
--- a/lib/git.js
+++ b/lib/git.js
@@ -29,10 +29,24 @@ function init(action) {
         try {
             (0, core_1.info)(`Deploying using ${action.tokenType}… 🔑`);
             (0, core_1.info)('Configuring git…');
+            /**
+             * Add safe directory to the global git config.
+             */
             try {
-                yield (0, execute_1.execute)(`git config --global --add safe.directory "${action.workspace}"`, action.workspace, action.silent);
+                yield (0, execute_1.execute)(`git config --global safe.directory '*'`, action.workspace, action.silent);
             }
             catch (_a) {
+                (0, core_1.info)('Unable to set workflow file tree as a safe directory…');
+            }
+            /**
+             * Ensure that the workspace is a safe directory, this is somewhat redundant as the action
+             * will always set the workspace as a safe directory, but this is a fallback in case the action
+             * fails to do so.
+             */
+            try {
+                yield (0, execute_1.execute)(`git config --global --add safe.directory "${action.workspace}"`, action.workspace, action.silent);
+            }
+            catch (_b) {
                 (0, core_1.info)('Unable to set workspace as a safe directory…');
             }
             yield (0, execute_1.execute)(`git config user.name "${action.name}"`, action.workspace, action.silent);
@@ -49,7 +63,7 @@ function init(action) {
                     throw new Error();
                 }
             }
-            catch (_b) {
+            catch (_c) {
                 (0, core_1.info)('Unable to unset previous git config authentication as it may not exist, continuing…');
             }
             try {
@@ -58,7 +72,7 @@ function init(action) {
                     throw new Error();
                 }
             }
-            catch (_c) {
+            catch (_d) {
                 (0, core_1.info)('Attempted to remove origin but failed, continuing…');
             }
             yield (0, execute_1.execute)(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);