summaryrefslogtreecommitdiffstats
path: root/pkg/runner/testdata/actions-environment-and-context-tests/js/index.js
blob: 79d8d06a5fd86a7ff4353ef1cbd8b31c9c78f280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function checkEnvVar({ name, allowEmpty }) {
  if (
    process.env[name] === undefined ||
    (allowEmpty === false && process.env[name] === "")
  ) {
    throw new Error(
      `${name} is undefined` + (allowEmpty === false ? " or empty" : "")
    );
  }
  console.log(`${name}=${process.env[name]}`);
}

checkEnvVar({ name: "GITHUB_ACTION", allowEmpty: false });
checkEnvVar({ name: "GITHUB_ACTION_REPOSITORY", allowEmpty: true /* allows to be empty for local actions */ });
checkEnvVar({ name: "GITHUB_ACTION_REF", allowEmpty: true /* allows to be empty for local actions */ });