|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# /******************************************************************************* |
| 4 | +# * Copyright (C) 2026 the Eclipse BaSyx Authors |
| 5 | +# * |
| 6 | +# * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | +# * a copy of this software and associated documentation files (the |
| 8 | +# * "Software"), to deal in the Software without restriction, including |
| 9 | +# * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | +# * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | +# * permit persons to whom the Software is furnished to do so, subject to |
| 12 | +# * the following conditions: |
| 13 | +# * |
| 14 | +# * The above copyright notice and this permission notice shall be |
| 15 | +# * included in all copies or substantial portions of the Software. |
| 16 | +# * |
| 17 | +# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | +# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | +# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | +# * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 21 | +# * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | +# * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | +# * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | +# * |
| 25 | +# * SPDX-License-Identifier: MIT |
| 26 | +# ******************************************************************************/ |
| 27 | + |
| 28 | +set -euo pipefail |
| 29 | + |
| 30 | +readonly SCRIPT_DIRECTORY="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 31 | +readonly GUARD_SCRIPT="${SCRIPT_DIRECTORY}/check_docker_publication.sh" |
| 32 | +readonly WORKFLOW_DIRECTORY="${SCRIPT_DIRECTORY}/.." |
| 33 | + |
| 34 | +assert_guard_result() { |
| 35 | + local description="$1" |
| 36 | + local repository="$2" |
| 37 | + local is_fork="$3" |
| 38 | + local expected="$4" |
| 39 | + local actual |
| 40 | + |
| 41 | + actual="$(bash "${GUARD_SCRIPT}" "${repository}" "${is_fork}")" |
| 42 | + if [[ "${actual}" != "${expected}" ]]; then |
| 43 | + echo "${description}: expected ${expected}, got ${actual}" >&2 |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +} |
| 47 | + |
| 48 | +assert_workflow_uses_guard() { |
| 49 | + local workflow="$1" |
| 50 | + |
| 51 | + if [[ "$(grep -c 'check_docker_publication.sh' "${workflow}")" -ne 1 ]]; then |
| 52 | + echo "${workflow} must invoke the shared Docker publication guard exactly once" >&2 |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +# Release workflow cases |
| 58 | +assert_guard_result "release in upstream" "eclipse-basyx/basyx-java-server-sdk" "false" "true" |
| 59 | +assert_guard_result "release in upstream marked as fork" "eclipse-basyx/basyx-java-server-sdk" "true" "false" |
| 60 | +assert_guard_result "release in fork" "contributor/basyx-java-server-sdk" "true" "false" |
| 61 | +assert_guard_result "release in renamed repository" "eclipse-basyx/basyx-java-server-sdk-renamed" "false" "false" |
| 62 | + |
| 63 | +# Snapshot push workflow cases |
| 64 | +assert_guard_result "push in upstream" "eclipse-basyx/basyx-java-server-sdk" "false" "true" |
| 65 | +assert_guard_result "push in upstream marked as fork" "eclipse-basyx/basyx-java-server-sdk" "true" "false" |
| 66 | +assert_guard_result "push in fork" "contributor/basyx-java-server-sdk" "true" "false" |
| 67 | +assert_guard_result "push in renamed repository" "eclipse-basyx/basyx-java-server-sdk-renamed" "false" "false" |
| 68 | + |
| 69 | +# Missing event metadata must fail closed. |
| 70 | +assert_guard_result "missing fork metadata" "eclipse-basyx/basyx-java-server-sdk" "" "false" |
| 71 | +assert_guard_result "missing repository metadata" "" "false" "false" |
| 72 | + |
| 73 | +assert_workflow_uses_guard "${WORKFLOW_DIRECTORY}/docker-milestone-release.yml" |
| 74 | +assert_workflow_uses_guard "${WORKFLOW_DIRECTORY}/docker-snapshot-release.yml" |
| 75 | + |
| 76 | +echo "Docker publication guard tests passed" |
0 commit comments