This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: adding yq-shim to support v3 and v4
Some tests uses yq installed by this repository but other tests might use yq installed by the kata-containers repository. We are pushing yq to v4 within the main kata repository and this shim will handle only basic syntax of yq v3 and v4 during the transition period. Fixes: #5820 Signed-off-by: Beraldo Leal <[email protected]>
- Loading branch information
1 parent
996bea0
commit fc6c8a5
Showing
8 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2024 Red Hat, Inc. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -euo pipefail | ||
|
||
usage() { echo "Usage: $0 <query> <path to yaml> <action> [value]"; } | ||
|
||
QUERY="${1-}" | ||
YAML_PATH="${2-}" | ||
ACTION="${3-}" | ||
VALUE="${4-}" | ||
VERSION="" | ||
|
||
handle_v3() { | ||
query="${QUERY#.}" | ||
|
||
case ${ACTION} in | ||
r) | ||
yq r "${YAML_PATH}" "${query}" | ||
;; | ||
w) | ||
yq w -i "${YAML_PATH}" "${query}" "${VALUE}" | ||
;; | ||
d) | ||
yq d -i -d'*' "${YAML_PATH}" "${query}" | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
handle_v4() { | ||
query=".${QUERY#.}" | ||
case ${ACTION} in | ||
r) | ||
yq "${query}" "${YAML_PATH}" | ||
;; | ||
w) | ||
export VALUE | ||
yq -i "${query} = strenv(VALUE)" "${YAML_PATH}" | ||
;; | ||
d) | ||
yq -i "del(${query})" "${YAML_PATH}" | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
if [ "$QUERY" == "-h" ]; then | ||
usage | ||
exit 0 | ||
elif [ $# -lt 3 ]; then | ||
usage >&2 | ||
exit 1 | ||
fi | ||
|
||
if ! command -v yq > /dev/null; then | ||
echo "yq not found in path" >&2 | ||
exit 1 | ||
fi | ||
|
||
if yq --version | grep '^.* version v4.*$' > /dev/null; then | ||
handle_v4 | ||
elif yq --version | grep '^.* version 3.*$' > /dev/null; then | ||
handle_v3 | ||
else | ||
echo "unsupported yq version" >&2 | ||
exit 1 | ||
fi |