From 91520dfd9f56006691956ae6376e26d246c642a6 Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Fri, 24 Sep 2021 16:49:17 +0200
Subject: [PATCH] Don't set outputs if empty or nil

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 dist/index.js | 8 ++++++--
 src/buildx.ts | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 861ac54..83c3476 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -57,7 +57,7 @@ function getImageID() {
         if (!fs_1.default.existsSync(iidFile)) {
             return undefined;
         }
-        return fs_1.default.readFileSync(iidFile, { encoding: 'utf-8' });
+        return fs_1.default.readFileSync(iidFile, { encoding: 'utf-8' }).trim();
     });
 }
 exports.getImageID = getImageID;
@@ -73,7 +73,11 @@ function getMetadata() {
         if (!fs_1.default.existsSync(metadataFile)) {
             return undefined;
         }
-        return fs_1.default.readFileSync(metadataFile, { encoding: 'utf-8' });
+        const content = fs_1.default.readFileSync(metadataFile, { encoding: 'utf-8' }).trim();
+        if (content === 'null') {
+            return undefined;
+        }
+        return content;
     });
 }
 exports.getMetadata = getMetadata;
diff --git a/src/buildx.ts b/src/buildx.ts
index 77b450b..157f21c 100644
--- a/src/buildx.ts
+++ b/src/buildx.ts
@@ -15,7 +15,7 @@ export async function getImageID(): Promise<string | undefined> {
   if (!fs.existsSync(iidFile)) {
     return undefined;
   }
-  return fs.readFileSync(iidFile, {encoding: 'utf-8'});
+  return fs.readFileSync(iidFile, {encoding: 'utf-8'}).trim();
 }
 
 export async function getMetadataFile(): Promise<string> {
@@ -27,7 +27,11 @@ export async function getMetadata(): Promise<string | undefined> {
   if (!fs.existsSync(metadataFile)) {
     return undefined;
   }
-  return fs.readFileSync(metadataFile, {encoding: 'utf-8'});
+  const content = fs.readFileSync(metadataFile, {encoding: 'utf-8'}).trim();
+  if (content === 'null') {
+    return undefined;
+  }
+  return content;
 }
 
 export async function getSecretString(kvp: string): Promise<string> {