Skip to content

Commit 5fd6fbc

Browse files
Merge pull request #132 from toga4/empty-strings
fix: set outputs/env vars for empty string field values
2 parents fdb192f + 13f927c commit 5fd6fbc

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/utils.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,41 @@ describe("extractSecret", () => {
106106
);
107107
expect(core.setSecret).toHaveBeenCalledWith(testSecretValue);
108108
});
109+
110+
describe("when secret value is empty string", () => {
111+
const emptySecretValue = "";
112+
113+
beforeEach(() => {
114+
(read.parse as jest.Mock).mockReturnValue(emptySecretValue);
115+
});
116+
117+
afterEach(() => {
118+
(read.parse as jest.Mock).mockReturnValue(testSecretValue);
119+
});
120+
121+
it("should set empty string as step output", () => {
122+
extractSecret(envTestSecretEnv, false);
123+
expect(core.setOutput).toHaveBeenCalledWith(
124+
envTestSecretEnv,
125+
emptySecretValue,
126+
);
127+
expect(core.exportVariable).not.toHaveBeenCalled();
128+
});
129+
130+
it("should set empty string as environment variable", () => {
131+
extractSecret(envTestSecretEnv, true);
132+
expect(core.exportVariable).toHaveBeenCalledWith(
133+
envTestSecretEnv,
134+
emptySecretValue,
135+
);
136+
expect(core.setOutput).not.toHaveBeenCalled();
137+
});
138+
139+
it("should not call setSecret for empty string", () => {
140+
extractSecret(envTestSecretEnv, false);
141+
expect(core.setSecret).not.toHaveBeenCalled();
142+
});
143+
});
109144
});
110145

111146
describe("loadSecrets", () => {

src/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const extractSecret = (
4141
}
4242

4343
const secretValue = read.parse(ref);
44-
if (!secretValue) {
44+
if (secretValue === null || secretValue === undefined) {
4545
return;
4646
}
4747

@@ -50,7 +50,11 @@ export const extractSecret = (
5050
} else {
5151
core.setOutput(envName, secretValue);
5252
}
53-
core.setSecret(secretValue);
53+
// Skip setSecret for empty strings to avoid the warning:
54+
// "Can't add secret mask for empty string in ##[add-mask] command."
55+
if (secretValue) {
56+
core.setSecret(secretValue);
57+
}
5458
};
5559

5660
export const loadSecrets = async (shouldExportEnv: boolean): Promise<void> => {

0 commit comments

Comments
 (0)