Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ed6ea68
add labels, do not use root, start to add libs
brokenpip3 Nov 2, 2022
57cb398
fix docker hub label
brokenpip3 Nov 3, 2022
64453f1
add utility to download and install the bats libs
brokenpip3 Nov 17, 2022
f648cc2
fix duplicate exit trap https://github.com/bats-core/bats-core/pull/6…
brokenpip3 Jan 5, 2023
785c9e1
make if more readable, ref: https://github.com/bats-core/bats-core/pu…
brokenpip3 Jan 5, 2023
6fa8c9a
fix(install_libs) move check param to the top, ref https://github.com…
brokenpip3 Jan 5, 2023
4a43668
fix(dockerfile): add arg with defaults instead of hardcoding values
brokenpip3 Jan 5, 2023
bc16a7a
Add test via Dockerfile
martin-schulze-vireso Jan 6, 2023
4060d25
Warn if runlog can't be created
martin-schulze-vireso Jan 6, 2023
2a01202
CI: Add test for official docker image
martin-schulze-vireso Jan 6, 2023
f4eb785
Fix shellcheck
martin-schulze-vireso Jan 6, 2023
35769e8
Add changelog entry for #674
martin-schulze-vireso Jan 6, 2023
8341a07
Fix expand_path for one element paths (like /code)
martin-schulze-vireso Jan 6, 2023
e4a3275
Also test libraries
martin-schulze-vireso Jan 6, 2023
8ee52d4
Make volume mounts work in default case
martin-schulze-vireso Jan 8, 2023
2911163
Improve output
martin-schulze-vireso Jan 8, 2023
0e0dad5
Docker: Undo unprivileged user for now
martin-schulze-vireso Jan 8, 2023
9cc95c6
Add missing dependencies for bats-file
martin-schulze-vireso Jan 8, 2023
8d43d5c
Install libs in correct default location
martin-schulze-vireso Jan 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,49 @@ jobs:
env:
TERM: linux # fix tput for tty issue work around
run: bats --print-output-on-failure --filter-tags !dep:install_sh test/

dockerfile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- uses: docker/build-push-action@v2
with:
platforms: linux/amd64
tags: bats:test
load: true

- run: docker run -itv "$PWD":/code bats:test --tap --print-output-on-failure test/
shell: 'script -q -e -c "bash {0}"' # work around tty issues
env:
TERM: linux # fix tput for tty issue work around

- uses: actions/checkout@v2
with:
repository: bats-core/bats-assert
path: bats-assert

- uses: actions/checkout@v2
with:
repository: bats-core/bats-support
path: bats-support

- uses: actions/checkout@v2
with:
repository: bats-core/bats-file
path: bats-file

- run: |
<<EOF cat >test.sh
apk add sudo python3 # install bats-file's dependencies
ln -sf python3 /usr/bin/python # bats-file uses python without version
bats --tap --print-output-on-failure bats-*/test/"
EOF
docker run -itv "$PWD":/code --entrypoint bash bats:test test.sh
shell: 'script -q -e -c "bash {0}"' # work around tty issues
env:
TERM: linux # fix tput for tty issue work around
26 changes: 23 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,41 @@ ARG bashver=latest
FROM bash:${bashver}
ARG TINI_VERSION=v0.19.0
ARG TARGETPLATFORM
ARG LIBS_VER_SUPPORT=0.3.0
ARG LIBS_VER_FILE=0.3.0
ARG LIBS_VER_ASSERT=2.1.0
ARG LIBS_VER_DETIK=1.1.0
ARG UID=1001
ARG GID=115


# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL maintainer="Bats-core Team"
LABEL org.opencontainers.image.authors="Bats-core Team"
LABEL org.opencontainers.image.title="Bats"
LABEL org.opencontainers.image.description="Bash Automated Testing System"
LABEL org.opencontainers.image.url="https://hub.docker.com/r/bats/bats"
LABEL org.opencontainers.image.source="https://github.com/bats-core/bats-core"
LABEL org.opencontainers.image.base.name="docker.io/bash"

COPY ./docker /tmp/docker
# default to amd64 when not running in buildx environment that provides target platform
RUN /tmp/docker/install_tini.sh "${TARGETPLATFORM-linux/amd64}"

# Install bats libs
RUN /tmp/docker/install_libs.sh support ${LIBS_VER_SUPPORT}
RUN /tmp/docker/install_libs.sh file ${LIBS_VER_FILE}
RUN /tmp/docker/install_libs.sh assert ${LIBS_VER_ASSERT}
RUN /tmp/docker/install_libs.sh detik ${LIBS_VER_DETIK}

# Install parallel and accept the citation notice (we aren't using this in a
# context where it make sense to cite GNU Parallel).
RUN apk add --no-cache parallel ncurses && \
mkdir -p ~/.parallel && touch ~/.parallel/will-cite
mkdir -p ~/.parallel && touch ~/.parallel/will-cite \
&& mkdir /code

RUN ln -s /opt/bats/bin/bats /usr/local/bin/bats
COPY . /opt/bats/

RUN mkdir -p /code
WORKDIR /code/

ENTRYPOINT ["/tini", "--", "bash", "bats"]
51 changes: 51 additions & 0 deletions docker/install_libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset


LIBNAME="${1:-support}"
LIVERSION="${2:-0.3.0}"
BASEURL='https://github.com/bats-core'
DESTDIR="${BATS_LIBS_DEST_DIR:-/usr/lib/bats}"
TMPDIR=$(mktemp -d -t bats-libs-XXXXXX)
USAGE="Please provide the bats libe name and version \nFor example: install_libs.sh support 2.0.0\n"

trap 'test -d "${TMPDIR}" && rm -fr "${TMPDIR}"' EXIT ERR SIGINT SIGTERM

[[ $# -ne 2 ]] && { _log FATAL "$USAGE"; exit 1; }

_log() {
printf "$(date "+%Y-%m-%d %H:%M:%S") - %s - %s\n" "${1}" "${2}"
}

create_temp_dirs() {
mkdir -p "${TMPDIR}/${1}"
if [[ ${LIBNAME} != "detik" ]]; then
mkdir -p "${DESTDIR}/bats-${1}/src"
else
_log INFO "Skipping src 'cause Detik does not need it"
fi
}

download_extract_source() {
wget -qO- ${BASEURL}/bats-"${1}"/archive/refs/tags/v"${2}".tar.gz | tar xz -C "${TMPDIR}/${1}" --strip-components 1
}

install_files() {
if [[ ${LIBNAME} != "detik" ]]; then
install -Dm755 "${TMPDIR}/${1}/load.bash" "${DESTDIR}/bats-${1}/load.bash"
for fn in "${TMPDIR}/${1}/src/"*.bash; do install -Dm755 "$fn" "${DESTDIR}/bats-${1}/src/$(basename "$fn")"; done
else
for fn in "${TMPDIR}/${1}/lib/"*.bash; do install -Dm755 "$fn" "${DESTDIR}/bats-${1}/$(basename "$fn")"; done
fi
}

_log INFO "Starting to install ${LIBNAME} ver ${LIVERSION}"
_log INFO "Creating directories"
create_temp_dirs "${LIBNAME}"
_log INFO "Downloading"
download_extract_source "${LIBNAME}" "${LIVERSION}"
_log INFO "Installation"
install_files "${LIBNAME}"
_log INFO "Done, cleaning.."
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
* `uri`: `file:///path/to/file.bats:1`
* `custom`: define your own formatter in `bats_format_file_line_reference_custom`
* add `bats:focus` tag to run only focused tests (#679)
* add bats-support, bats-assert, bats-file and bats-detik to Dockerfile (#674)

### Documentation

Expand Down
4 changes: 4 additions & 0 deletions libexec/bats-core/bats
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ HELP_TEXT_BODY
expand_path() {
local path="${1%/}"
local dirname="${path%/*}"
if [[ -z "$dirname" ]]; then
dirname=/
fi
local result="$2"
local OLDPWD="$PWD"

if [[ "$dirname" == "$path" ]]; then
dirname="$PWD"
Expand Down
6 changes: 5 additions & 1 deletion libexec/bats-core/bats-exec-suite
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ else
# use UTC (-u) to avoid problems with TZ changes
BATS_RUNLOG_DATE=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
export BATS_RUNLOG_FILE="$BATS_RUN_LOGS_DIRECTORY/${BATS_RUNLOG_DATE}.log"
if [[ ! -w "$BATS_RUN_LOGS_DIRECTORY" ]]; then
printf "WARNING: Cannot write in %s. This run will not write a log!\n" "$BATS_RUN_LOGS_DIRECTORY" >&2
BATS_RUNLOG_FILE='/dev/null' # disable runlog file
fi
fi

bats_gather_tests "$@"
Expand Down Expand Up @@ -375,7 +379,7 @@ bats_suite_exit_trap() {

if [[ -d "$BATS_RUN_LOGS_DIRECTORY" && -n "${BATS_INTERRUPTED:-}" ]]; then
# aborting a test run with CTRL+C does not save the runlog file
rm "$BATS_RUNLOG_FILE"
[[ "$BATS_RUNLOG_FILE" != /dev/null ]] && rm "$BATS_RUNLOG_FILE"
fi
exit "$bats_exec_suite_status"
} >&3
Expand Down