Skip to content

Commit

Permalink
[TASK] Add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ochorocho committed Jul 7, 2024
1 parent 040a135 commit efc9117
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
branches:
- main
schedule:
- cron: "0 5 * * *"
- cron: "0 1 * * 1"

jobs:
build:
name: Build Container
name: Build and Push Container
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -21,9 +21,6 @@ jobs:
-
name: Docker info
run: docker info
-
name: Docker Builder
run: docker buildx ls
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -32,17 +29,19 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Setup BATS
-
name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.2.1

- name: Check out code
-
name: Check out code
uses: actions/checkout@v1

- name: "Test ddev ${{ matrix.version }} image"
-
name: "Test ddev ${{ matrix.version }} image"
shell: 'script -q -e -c "bash {0}"'
run: |
sudo snap install yq
./build.sh -v ${{ matrix.version }} -l
DDEV_VERSION=${{ matrix.version }} bash bats tests
-
Expand All @@ -51,4 +50,4 @@ jobs:
run: |
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
docker buildx create --use --platform=linux/arm64,linux/amd64
./build.sh -v ${{ matrix.version }} -p
./build.sh -v ${{ matrix.version }} -x -p
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '!main'
jobs:
build:
name: Build Container
name: Build and Test Container
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -20,9 +20,6 @@ jobs:
-
name: Docker info
run: docker info
-
name: Docker Builder
run: docker buildx ls
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -31,9 +28,6 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
-
name: Setup yq
uses: mikefarah/yq@master
-
name: Setup BATS
uses: mig4/setup-bats@v1
Expand All @@ -46,5 +40,6 @@ jobs:
name: "Test ddev ${{ matrix.version }} image"
shell: 'script -q -e -c "bash {0}"'
run: |
sudo snap install yq
./build.sh -v ${{ matrix.version }} -l
DDEV_VERSION=${{ matrix.version }} bash bats tests
13 changes: 6 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ help() {
echo " * v - DDEV version e.g. 'v1.23.1'"
echo " * l - Load the image (--load)"
echo " * p - Push the image (--push)"
echo " * x - Build multi-arch image (--platform linux/amd64,linux/arm64)"
}

loadVersionAndTags() {
Expand Down Expand Up @@ -49,7 +50,7 @@ loadVersionAndTags() {
fi
}

while getopts ":v:hpl" opt; do
while getopts ":v:hplx" opt; do
case $opt in
h)
help
Expand All @@ -64,6 +65,9 @@ while getopts ":v:hpl" opt; do
l)
LOAD="--load"
;;
x)
PLATFORM="--platform linux/amd64,linux/arm64"
;;
*)
echo "Invalid option: -$OPTARG"
help
Expand All @@ -74,9 +78,4 @@ done

loadVersionAndTags

docker buildx build --platform linux/amd64,linux/arm64 --progress plain --no-cache --pull . -f Dockerfile ${DOCKER_TAGS[@]} --build-arg ddev_version="$DDEV_VERSION" $PUSH $LOAD

if [ $LOAD ]; then
docker run --rm -it -v "$(pwd)/test.sh:/tmp/test.sh" --entrypoint "ash" "$IMAGE_NAME:$DDEV_VERSION" /tmp/test.sh
fi

docker buildx build ${PLATFORM} --progress plain --no-cache --pull . -f Dockerfile ${DOCKER_TAGS[@]} --build-arg ddev_version="$DDEV_VERSION" $PUSH $LOAD
4 changes: 2 additions & 2 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@test "See ddev version" {
run docker-run "ddev version -j"

version=$(echo "$output" | head -2 | tail -1 | yq '.raw.["DDEV version"]')
version=$(echo "$output" | tail -n 1 | yq '.raw.["DDEV version"]')
regex='^v([0-9]+)\.([0-9]+)\.([0-9]+)$'

[[ $version =~ $regex ]]
Expand Down Expand Up @@ -71,6 +71,6 @@

docker-run() {
local COMMAND=${1}
# @todo: Pass in the current version

docker run --rm -it --network ddev-docker ghcr.io/ochorocho/ddev-gitlab-ci:"${DDEV_VERSION}" /bin/sh -c "${COMMAND}"
}

0 comments on commit efc9117

Please sign in to comment.