Skip to content

Commit 5dad25e

Browse files
authored
GITHUB_* enironement variables are available during script execution (#10) (#12)
1 parent 4d518c1 commit 5dad25e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/main.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
4747
inlineScript = ` set -e >&2; echo '${START_SCRIPT_EXECUTION_MARKER}' >&2; ${inlineScript}`;
4848
scriptFileName = yield utils_1.createScriptFile(inlineScript);
4949
let startCommand = ` ${BASH_ARG}${CONTAINER_TEMP_DIRECTORY}/${scriptFileName} `;
50+
let gitHubEnvironmentVariables = '';
51+
for (let key in process.env) {
52+
if (key.toUpperCase().startsWith("GITHUB_") && key.toUpperCase() !== 'GITHUB_WORKSPACE' && process.env[key]) {
53+
gitHubEnvironmentVariables += ` -e ${key}=${process.env[key]} `;
54+
}
55+
}
5056
/*
5157
For the docker run command, we are doing the following
5258
- Set the working directory for docker continer
@@ -56,7 +62,8 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
5662
*/
5763
let command = `run --workdir ${CONTAINER_WORKSPACE} -v ${process.env.GITHUB_WORKSPACE}:${CONTAINER_WORKSPACE} `;
5864
command += ` -v ${process.env.HOME}/.azure:/root/.azure -v ${utils_1.TEMP_DIRECTORY}:${CONTAINER_TEMP_DIRECTORY} `;
59-
command += `-e GITHUB_WORKSPACE=${CONTAINER_WORKSPACE} -e GITHUB_SHA=${process.env.GITHUB_SHA} `;
65+
command += ` ${gitHubEnvironmentVariables} `;
66+
command += `-e GITHUB_WORKSPACE=${CONTAINER_WORKSPACE} `;
6067
command += `--name ${CONTAINER_NAME} `;
6168
command += ` mcr.microsoft.com/azure-cli:${azcliversion} ${startCommand}`;
6269
console.log(`${START_SCRIPT_EXECUTION_MARKER}${azcliversion}`);

src/main.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ const run = async () => {
3535
inlineScript = ` set -e >&2; echo '${START_SCRIPT_EXECUTION_MARKER}' >&2; ${inlineScript}`;
3636
scriptFileName = await createScriptFile(inlineScript);
3737
let startCommand: string = ` ${BASH_ARG}${CONTAINER_TEMP_DIRECTORY}/${scriptFileName} `;
38-
38+
let gitHubEnvironmentVariables = '';
39+
for (let key in process.env){
40+
if (key.toUpperCase().startsWith("GITHUB_") && key.toUpperCase() !== 'GITHUB_WORKSPACE' && process.env[key]){
41+
gitHubEnvironmentVariables += ` -e ${key}=${process.env[key]} `;
42+
}
43+
}
3944
/*
4045
For the docker run command, we are doing the following
4146
- Set the working directory for docker continer
@@ -45,7 +50,8 @@ const run = async () => {
4550
*/
4651
let command: string = `run --workdir ${CONTAINER_WORKSPACE} -v ${process.env.GITHUB_WORKSPACE}:${CONTAINER_WORKSPACE} `;
4752
command += ` -v ${process.env.HOME}/.azure:/root/.azure -v ${TEMP_DIRECTORY}:${CONTAINER_TEMP_DIRECTORY} `;
48-
command += `-e GITHUB_WORKSPACE=${CONTAINER_WORKSPACE} -e GITHUB_SHA=${process.env.GITHUB_SHA} `;
53+
command += ` ${gitHubEnvironmentVariables} `;
54+
command += `-e GITHUB_WORKSPACE=${CONTAINER_WORKSPACE} `;
4955
command += `--name ${CONTAINER_NAME} `;
5056
command += ` mcr.microsoft.com/azure-cli:${azcliversion} ${startCommand}`;
5157
console.log(`${START_SCRIPT_EXECUTION_MARKER}${azcliversion}`);

0 commit comments

Comments
 (0)