This GitHub Action allows you to run your Bats tests in a customizable Docker container based on the ffurrer/bats image.
- Create a workflow
.yml
file in your.github/workflows
directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file. - Create a Bats test file. For more information, reference the bats-core documentation for Writing tests.
Input | Description |
---|---|
main (optional) |
The Alpine packages to install from the main repository (e.g. bash curl git ). |
community (optional) |
The Alpine packages to install from the community repository (e.g. docker-cli ). |
testing (optional) |
The Alpine packages to install from the testing repository. |
args |
The flags, options and arguments of bats (e.g. -p -r ./test ). |
On every push
to the main branch, run all tests in the test_docker_container.bats
file:
name: Run Bats tests
on:
push:
tags:
- main
jobs:
test:
name: Test Docker container
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run Bats tests
uses: ffurrer2/bats-action@v1
with:
community: docker-cli
args: ./test_docker_container.bats
#!/usr/bin/env bats
load '/opt/bats-support/load.bash'
load '/opt/bats-assert/load.bash'
@test "Docker container should include bash" {
run docker run \
--rm \
--entrypoint /bin/sh \
ffurrer/bats:latest \
-c '[ -x "$(command -v parallel)" ] || { echo "error: command not found: parallel" >&2; exit 1; }'
assert_success
}
This will use the ffurrer/bats:1.2.0 image, install the docker-cli
package from the Alpine community repository and test if parallel
is installed.
The scripts and documentation in this project are released under the MIT License.