Skip to content

Commit ef155fb

Browse files
committed
Test image size
1 parent fd973aa commit ef155fb

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Test test-image-size action
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v6
12+
13+
- name: Test scripts
14+
run: ./test-image-size/test_scripts.sh
15+
16+
- name: Run test-image-size
17+
uses: ./test-image-size
18+
with:
19+
image: hazelcast/hazelcast:5.0.1-slim

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
uses: ./.github/workflows/test-slack-notification.yml
4242
secrets: inherit
4343

44+
test-test-image-size:
45+
uses: ./.github/workflows/test-test-image-size.yml
46+
secrets: inherit
47+
4448
assert-all-jobs-succeeded:
4549
runs-on: ubuntu-latest
4650
needs:
@@ -54,6 +58,7 @@ jobs:
5458
- test-get-supported-platforms
5559
- test-resolve-editions
5660
- test-slack-notification
61+
- test-test-image-size
5762
if: always()
5863
steps:
5964
- name: Check all jobs succeeded

test-image-size/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test image size
2+
description: Test image isn't excessively large / wasting space
3+
4+
inputs:
5+
image:
6+
description: Image name to test
7+
required: true
8+
minimum_efficiency:
9+
description: Minimum efficiency percentage required - 0-1 scale
10+
required: false
11+
default: 0.95
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- shell: bash
17+
run: |
18+
. ${GITHUB_ACTION_PATH}/test-image-size.functions.sh
19+
20+
test_image_size "${IMAGE}" "${MINIMUM_EFFICIENCY}"
21+
env:
22+
IMAGE: ${{ inputs.image }}
23+
MINIMUM_EFFICIENCY: ${{ inputs.minimum_efficiency }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function test_image_size() {
2+
local image=$1
3+
local minimum_efficiency=$2
4+
5+
local config_file
6+
config_file=$(mktemp)
7+
8+
# https://github.com/wagoodman/dive/blob/main/README.md#ci-integration
9+
yq eval -n "
10+
.rules.lowestEfficiency = ${minimum_efficiency}
11+
" > "${config_file}"
12+
13+
docker run --rm \
14+
--env CI=true \
15+
--volume /var/run/docker.sock:/var/run/docker.sock \
16+
--volume "${config_file}:/.dive-ci" \
17+
docker.io/wagoodman/dive:latest \
18+
"${image}"
19+
20+
return $?
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu ${RUNNER_DEBUG:+-x}
4+
5+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
6+
7+
# Source the latest version of assert.sh unit testing library and include in current shell
8+
source /dev/stdin <<< "$(curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh)"
9+
10+
. "$SCRIPT_DIR"/test-image-size.functions.sh
11+
12+
TESTS_RESULT=0
13+
14+
function assert_test_image_size {
15+
local image=$1
16+
local minimum_efficiency=$2
17+
local expected_exit_code=$3
18+
test_image_size "${image}" "${minimum_efficiency}" && true
19+
local actual_exit_code=$?
20+
local msg="Expected exit code for \"${image}\" / \"${minimum_efficiency}\""
21+
assert_eq "${expected_exit_code}" "${actual_exit_code}" "${msg}" && log_success "${msg}" || TESTS_RESULT=$?
22+
}
23+
24+
log_header "Tests for test_image_size"
25+
# expected efficiency: 99.8541 %
26+
assert_test_image_size hazelcast/hazelcast:5.0.1-slim 0.95 0
27+
assert_test_image_size hazelcast/hazelcast:5.0.1-slim 0.99999999999 1
28+
29+
assert_eq 0 "$TESTS_RESULT" "All tests should pass"

test-image-size/test_scripts.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
4+
5+
find "$SCRIPT_DIR" -name "*_tests.sh" -print0 | xargs -0 -n1 bash

0 commit comments

Comments
 (0)