Skip to content

Fix: Add compatibility with the new Github Environment Files #101

Fix: Add compatibility with the new Github Environment Files

Fix: Add compatibility with the new Github Environment Files #101

Workflow file for this run

name: All Tests
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'
jobs:
code-format:
name: Test code format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
npm install
- run: |
npm run all
test:
name: Test Functionality
runs-on: ubuntu-latest
services:
nginx:
image: nginxdemos/hello:plain-text
steps:
- uses: actions/checkout@v4
- name: Copy test.sh to executable path
run: |
mkdir -p ~/.local/bin
cp ./tests/test.sh ~/.local/bin/test.sh
- name: "Test: Run a command in a public image"
id: test-simple
uses: ./
with:
image: ubuntu:latest
run: echo "success=true" >> $GITHUB_OUTPUT
- name: "Validate Test: Run a command in a public image"
run: test.sh equal "${{ steps.test-simple.outputs.success }}" "true"
- name: "Test: Multline script with defaults settings"
id: test-defaults
uses: ./
with:
image: ubuntu:latest
run: |
# prepare...
apt-get update && apt-get install -y iputils-ping
# check if the script is running in default "sh" (which is dash in ubuntu)
[ ! -z "${BASH_VERSION}" ] && echo "ERROR: Shell is not sh" && exit 1
# check if the default workdir ("/") is used
echo "Workdir is: ${PWD}"
[ "${PWD}" != "/" ] && echo "ERROR: Workdir is not /" && exit 1
# check if the container is attached to the local docker network:
ping -c 1 nginx
- name: "Test: Multiline run fails on error (should have error)"
continue-on-error: true
id: test-multiline-with-error
uses: ./
with:
image: ubuntu:latest
run: |
echo "start"
echo "beforeError=true" >> $GITHUB_OUTPUT
cat non-existing-file
echo "afterError=true" >> $GITHUB_OUTPUT
echo "end"
- name: "Validate Test: Multiline run fails on error"
run: |
test.sh equal "${{ steps.test-multiline-with-error.outputs.beforeError }}" "true"
test.sh empty "${{ steps.test-multiline-with-error.outputs.afterError }}"
- name: "Test: Shell input"
id: test-shell-input
uses: ./
with:
image: ubuntu:latest
shell: /bin/bash
run: echo "bash-version=${BASH_VERSION}" >> $GITHUB_OUTPUT
- name: "Validate Test: Shell input"
run: test.sh not-empty "${{ steps.test-shell-input.outputs.bash-version }}"
- name: "Test: Env input"
id: test-env-input
uses: ./
with:
image: ubuntu:latest
environment: |
GITHUB_JOB
CUSTOM_VAR=foo
run: |
echo "github-job=${GITHUB_JOB}" >> $GITHUB_OUTPUT
echo "custom-var=${CUSTOM_VAR}" >> $GITHUB_OUTPUT
- name: "Validate Test: Env input"
run: |
test.sh equal "${{ steps.test-env-input.outputs.github-job }}" "${GITHUB_JOB}"
test.sh equal "${{ steps.test-env-input.outputs.custom-var }}" "foo"
- name: "Test: Volume input"
id: test-volume-input
uses: ./
with:
image: ubuntu:latest
volumes: |
/home/runner/volume-test:/home-volume-test
${{ github.workspace }}:/workspace
run: |
echo "present" > /home-volume-test/file1
echo "present" > /workspace/file2
- name: "Validate Test: Volume input"
run: |
test.sh equal $(cat ~/volume-test/file1) "present"
test.sh equal $(cat ${GITHUB_WORKSPACE}/file2) "present"
- name: "Test: Workdir input"
id: test-workdir-input
uses: ./
with:
image: ubuntu:latest
workdir: "/var/mywork"
run: |
echo "present" > /var/mywork/test-file
echo "file-content=$(cat ./test-file)" >> $GITHUB_OUTPUT
- name: "Validate Test: Workdir input"
run: test.sh equal "${{ steps.test-workdir-input.outputs.file-content }}" "present"
- name: "Test: Tempdir input"
id: test-tempdir-input
uses: ./
with:
image: ubuntu:latest
tempdir: "/var/mytemp"
run: |
ls command*
ls set_output*
ls a*
- name: "Validate Test: Workdir input"
run: test.sh equal "${{ steps.test-workdir-input.outputs.file-content }}" "present"
- name: "Test: Options input"
id: test-options-input
uses: ./
with:
image: ubuntu:latest
options: |
--name=TestContainer
--label test
-e TEST_VAR=bar
run: echo "test-var=${TEST_VAR}" >> $GITHUB_OUTPUT
- name: "Validate Test: Options input"
run: test.sh equal "${{ steps.test-options-input.outputs.test-var }}" "bar"
- name: "Test: Setting Environment Files (env, output, summary, path)"
id: test-runner-env
uses: ./
with:
image: ubuntu:latest
volumes: ${{ github.workspace }}:/workspace
run: |
echo "test_env=IsSet" >> "$GITHUB_ENV"
echo "test_path=/IsSet" >> "$GITHUB_PATH"
echo "test_output=IsSet" >> "$GITHUB_OUTPUT"
echo "test_state=IsSet" >> "$GITHUB_STATE"
echo "### Step summary worked! :rocket:" >> "$GITHUB_STEP_SUMMARY"
- name: "Validate Test: Setting Environment Files (env, output, summary, path)"
run: |
test.sh equal "$test_env" "IsSet"
test.sh contains "$PATH" "IsSet"
test.sh equal "${{ steps.test-runner-env.outputs.test_output }}" "IsSet"
- name: Authorize docker for private image
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Test: Can access private image after authorization"
id: test-private-image
uses: ./
with:
image: ghcr.io/${{ github.repository }}/private-image:latest
run: cat /var/mywork/private-image-test