diff options
Diffstat (limited to 'pkg/runner/testdata/actions-environment-and-context-tests')
6 files changed, 71 insertions, 0 deletions
diff --git a/pkg/runner/testdata/actions-environment-and-context-tests/docker/Dockerfile b/pkg/runner/testdata/actions-environment-and-context-tests/docker/Dockerfile new file mode 100644 index 0000000..bd8fcb2 --- /dev/null +++ b/pkg/runner/testdata/actions-environment-and-context-tests/docker/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine:3 + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/pkg/runner/testdata/actions-environment-and-context-tests/docker/action.yml b/pkg/runner/testdata/actions-environment-and-context-tests/docker/action.yml new file mode 100644 index 0000000..0b0b9f0 --- /dev/null +++ b/pkg/runner/testdata/actions-environment-and-context-tests/docker/action.yml @@ -0,0 +1,5 @@ +name: 'Test' +description: 'Test' +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/pkg/runner/testdata/actions-environment-and-context-tests/docker/entrypoint.sh b/pkg/runner/testdata/actions-environment-and-context-tests/docker/entrypoint.sh new file mode 100755 index 0000000..a954fd4 --- /dev/null +++ b/pkg/runner/testdata/actions-environment-and-context-tests/docker/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +checkEnvVar() { + name=$1 + value=$2 + allowEmpty=$3 + + if [ -z "$value" ]; then + echo "Missing environment variable: $name" + exit 1 + fi + + if [ "$allowEmpty" != "true" ]; then + test=$(echo "$value" |cut -f 2 -d "=") + if [ -z "$test" ]; then + echo "Environment variable is empty: $name" + exit 1 + fi + fi + + echo "$value" +} + +checkEnvVar "GITHUB_ACTION" "$(env |grep "GITHUB_ACTION=")" false +checkEnvVar "GITHUB_ACTION_REPOSITORY" "$(env |grep "GITHUB_ACTION_REPOSITORY=")" true +checkEnvVar "GITHUB_ACTION_REF" "$(env |grep "GITHUB_ACTION_REF=")" true diff --git a/pkg/runner/testdata/actions-environment-and-context-tests/js/action.yml b/pkg/runner/testdata/actions-environment-and-context-tests/js/action.yml new file mode 100644 index 0000000..c29a6df --- /dev/null +++ b/pkg/runner/testdata/actions-environment-and-context-tests/js/action.yml @@ -0,0 +1,5 @@ +name: 'Test' +description: 'Test' +runs: + using: 'node12' + main: 'index.js' diff --git a/pkg/runner/testdata/actions-environment-and-context-tests/js/index.js b/pkg/runner/testdata/actions-environment-and-context-tests/js/index.js new file mode 100644 index 0000000..79d8d06 --- /dev/null +++ b/pkg/runner/testdata/actions-environment-and-context-tests/js/index.js @@ -0,0 +1,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 */ }); diff --git a/pkg/runner/testdata/actions-environment-and-context-tests/push.yml b/pkg/runner/testdata/actions-environment-and-context-tests/push.yml new file mode 100644 index 0000000..1d799d5 --- /dev/null +++ b/pkg/runner/testdata/actions-environment-and-context-tests/push.yml @@ -0,0 +1,15 @@ +name: actions-with-environment-and-context-tests +description: "Actions with environment (env vars) and context (expression) tests" +on: push + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: './actions-environment-and-context-tests/js' + - uses: './actions-environment-and-context-tests/docker' + - uses: 'nektos/act-test-actions/js@main' + - uses: 'nektos/act-test-actions/docker@main' + - uses: 'nektos/act-test-actions/docker-file@main' + - uses: 'nektos/act-test-actions/docker-relative-context/action@main' |