|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# ******************************************************************************* |
| 4 | +# Copyright (c) 2026 Contributors to the Eclipse Foundation |
| 5 | +# |
| 6 | +# See the NOTICE file(s) distributed with this work for additional |
| 7 | +# information regarding copyright ownership. |
| 8 | +# |
| 9 | +# This program and the accompanying materials are made available under the |
| 10 | +# terms of the Apache License Version 2.0 which is available at |
| 11 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# SPDX-License-Identifier: Apache-2.0 |
| 14 | +# ******************************************************************************* |
| 15 | + |
| 16 | +set -euxo pipefail |
| 17 | + |
| 18 | +# Usage: test_consumer.sh <repo-url> [revision] [devcontainer-image] |
| 19 | +# Tests that a consumer repository can be built and tested using the devcontainer. |
| 20 | +# It is checked that these commands work without errors: |
| 21 | +# - bazel build //... |
| 22 | +# - bazel test //... |
| 23 | +# Parameters: |
| 24 | +# repo-url : Git URL of the consumer repository |
| 25 | +# revision : Git branch/tag/commit (default: main) |
| 26 | + |
| 27 | +REPO_URL="${1:?Repository URL is required}" |
| 28 | +REVISION="${2:-main}" |
| 29 | + |
| 30 | +IMAGE="s-core-devcontainer" |
| 31 | + |
| 32 | +export DOCKER_BUILDKIT=1 |
| 33 | + |
| 34 | +SCRIPT_PATH=$(readlink -f "$0") |
| 35 | +SCRIPT_DIR=$(dirname -- "${SCRIPT_PATH}") |
| 36 | +PROJECT_DIR=$(dirname -- "${SCRIPT_DIR}") |
| 37 | +ID_LABEL="test-container=${IMAGE}" |
| 38 | + |
| 39 | +. "${SCRIPT_DIR}/functions.sh" |
| 40 | +set_dockerfile_name |
| 41 | + |
| 42 | +devcontainer up \ |
| 43 | + --id-label "${ID_LABEL}" \ |
| 44 | + --workspace-folder "${PROJECT_DIR}/src/${IMAGE}/" \ |
| 45 | + --remove-existing-container |
| 46 | + |
| 47 | +# Extract repo name from URL |
| 48 | +REPO_NAME=$(basename "${REPO_URL}" .git) |
| 49 | +REPO_WORKSPACE="/tmp/${REPO_NAME}" |
| 50 | + |
| 51 | +echo "(*) Cloning repository..." |
| 52 | +# --revision not supported by older git versions, so we clone first and then checkout the revision |
| 53 | +# devcontainer exec --id-label "${ID_LABEL}" git clone --depth 1 --revision "${REVISION}" "${REPO_URL}" "${REPO_WORKSPACE}" |
| 54 | +devcontainer exec --id-label "${ID_LABEL}" git clone "${REPO_URL}" "${REPO_WORKSPACE}" |
| 55 | +devcontainer exec --id-label "${ID_LABEL}" git -C "${REPO_WORKSPACE}" checkout "${REVISION}" |
| 56 | + |
| 57 | +# Run build and test with Bazel using docker exec |
| 58 | +echo "(*) Running Bazel build in devcontainer..." |
| 59 | +devcontainer exec --id-label="${ID_LABEL}" /bin/sh -c "set -e && cd \"${REPO_WORKSPACE}\" && bazel build //..." |
| 60 | + |
| 61 | +echo "(*) Running Bazel test in devcontainer..." |
| 62 | +devcontainer exec --id-label="${ID_LABEL}" /bin/sh -c "set -e && cd \"${REPO_WORKSPACE}\" && bazel test //..." |
| 63 | + |
| 64 | +echo "(*) Bazel build and test completed successfully for ${REPO_NAME}" |
0 commit comments