Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/test-test-image-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test test-image-size action
Comment thread
nishaatr marked this conversation as resolved.
Outdated

on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Test scripts
run: ./test-image-size/test_scripts.sh

- name: Run test-image-size
uses: ./test-image-size
with:
image: hazelcast/hazelcast:5.0.1-slim
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ jobs:
uses: ./.github/workflows/test-slack-notification.yml
secrets: inherit

test-test-image-size:
uses: ./.github/workflows/test-test-image-size.yml
secrets: inherit

assert-all-jobs-succeeded:
runs-on: ubuntu-latest
needs:
Expand All @@ -54,6 +58,7 @@ jobs:
- test-get-supported-platforms
- test-resolve-editions
- test-slack-notification
- test-test-image-size
if: always()
steps:
- name: Check all jobs succeeded
Expand Down
23 changes: 23 additions & 0 deletions test-image-size/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test image size
description: Test image isn't excessively large / wasting space

inputs:
image:
description: Image name to test
required: true
minimum_efficiency:
description: Minimum efficiency percentage required - 0-1 scale
required: false
default: 0.95

runs:
using: "composite"
steps:
- shell: bash
run: |
. ${GITHUB_ACTION_PATH}/test-image-size.functions.sh

test_image_size "${IMAGE}" "${MINIMUM_EFFICIENCY}"
env:
IMAGE: ${{ inputs.image }}
MINIMUM_EFFICIENCY: ${{ inputs.minimum_efficiency }}
23 changes: 23 additions & 0 deletions test-image-size/test-image-size.functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function test_image_size() {
local image=$1
local minimum_efficiency=$2

local config_file
config_file=$(mktemp)

# https://github.com/wagoodman/dive/blob/main/README.md#ci-integration
yq eval -n "
.rules.lowestEfficiency = ${minimum_efficiency} |
.rules.highestWastedBytes = \"disabled\" |
.rules.highestUserWastedPercent = \"disabled\"
" > "${config_file}"

docker run --rm \
--env CI=true \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "${config_file}:/.dive-ci" \
docker.io/wagoodman/dive:latest \
"${image}"

return $?
}
29 changes: 29 additions & 0 deletions test-image-size/test-image-size.functions_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -eu ${RUNNER_DEBUG:+-x}

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

# Source the latest version of assert.sh unit testing library and include in current shell
source /dev/stdin <<< "$(curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh)"

. "$SCRIPT_DIR"/test-image-size.functions.sh

TESTS_RESULT=0

function assert_test_image_size {

Check warning on line 14 in test-image-size/test-image-size.functions_tests.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add an explicit return statement at the end of the function.

See more on https://sonarcloud.io/project/issues?id=hazelcast_docker-actions&issues=AZsH4Q1IMTbvIquXfwMQ&open=AZsH4Q1IMTbvIquXfwMQ&pullRequest=40
local image=$1
local minimum_efficiency=$2
local expected_exit_code=$3
test_image_size "${image}" "${minimum_efficiency}" && true
local actual_exit_code=$?
local msg="Expected exit code for \"${image}\" / \"${minimum_efficiency}\""
assert_eq "${expected_exit_code}" "${actual_exit_code}" "${msg}" && log_success "${msg}" || TESTS_RESULT=$?
}

log_header "Tests for test_image_size"
# expected efficiency: 99.8541 %
assert_test_image_size hazelcast/hazelcast:5.0.1-slim 0.95 0
assert_test_image_size hazelcast/hazelcast:5.0.1-slim 0.99999999999 1

assert_eq 0 "$TESTS_RESULT" "All tests should pass"
5 changes: 5 additions & 0 deletions test-image-size/test_scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

find "$SCRIPT_DIR" -name "*_tests.sh" -print0 | xargs -0 -n1 bash
Loading