Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.
/ bats-action Public archive

A GitHub Action to run Bats tests in a customizable Alpine-based Docker container

License

Notifications You must be signed in to change notification settings

ffurrer2/bats-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bats Action

CI MIT License GitHub Release

This GitHub Action allows you to run your Bats tests in a customizable Docker container based on the ffurrer/bats image.

Usage

Prerequisites

  • 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.

Inputs

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).

Example: Test a Docker container with Bats

Example workflow

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

Example test_docker_container.bats file

#!/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.

License

The scripts and documentation in this project are released under the MIT License.