-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- introduced output helper - storing now outputs directly to file by own helper method instead of using core.setOutput(..)
- Loading branch information
Showing
7 changed files
with
152 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
import * as outputHelper from '../src/output-helper'; | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
describe('storeOutput', () => { | ||
const outputPath = path.join(__dirname, 'test_output.txt'); | ||
|
||
beforeAll(() => { | ||
process.env.GITHUB_OUTPUT = outputPath; | ||
}); | ||
|
||
afterEach(() => { | ||
if (fs.existsSync(outputPath)) { | ||
fs.unlinkSync(outputPath); | ||
} | ||
}); | ||
|
||
it('should append a line with key=value to the file', () => { | ||
/* execute */ | ||
outputHelper.storeOutput('TEST_KEY', 'TEST_VALUE'); | ||
|
||
/* test */ | ||
const content = fs.readFileSync(outputPath, 'utf8'); | ||
expect(content).toBe('TEST_KEY=TEST_VALUE\n'); | ||
}); | ||
|
||
it('should append multiple lines correctly', () => { | ||
/* execute */ | ||
outputHelper.storeOutput('KEY1', 'VALUE1'); | ||
outputHelper.storeOutput('KEY2', 'VALUE2'); | ||
|
||
/* test */ | ||
const content = fs.readFileSync(outputPath, 'utf8'); | ||
expect(content).toBe('KEY1=VALUE1\nKEY2=VALUE2\n'); | ||
}); | ||
|
||
it('should throw an error if GITHUB_OUTPUT is not set', () => { | ||
/* prepare */ | ||
delete process.env.GITHUB_OUTPUT; | ||
|
||
/* execute + test */ | ||
expect(() => outputHelper.storeOutput('KEY', 'VALUE')).toThrow('GITHUB_OUTPUT environment variable is not set'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
import * as fs from 'fs'; | ||
|
||
/** | ||
* Sets the value of an output variable for the GitHub Action. | ||
* This method is a replacement of usage of core.setOutput(..) method. | ||
* There were problems with core.setOutput(...), see | ||
* - https://github.com/mercedes-benz/sechub/issues/3481#issuecomment-2539015176 and | ||
* - https://github.com/actions/toolkit/issues/1218 | ||
* | ||
*/ | ||
export function storeOutput(field: string, value: string) { | ||
const outputFilePath = process.env['GITHUB_OUTPUT'] || ''; | ||
|
||
if (!outputFilePath) { | ||
throw new Error('GITHUB_OUTPUT environment variable is not set'); | ||
} | ||
|
||
const outputLine = `${field}=${value}\n`; | ||
|
||
fs.appendFileSync(outputFilePath, outputLine, { encoding: 'utf8' }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters