-
Notifications
You must be signed in to change notification settings - Fork 0
/
replace_pkg_version.sh
executable file
·69 lines (58 loc) · 1.92 KB
/
replace_pkg_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
if [ "${BASH_VERSINFO[0]}" -lt 5 ];then
echo "Bash5 is required" > /dev/stderr
exit 1
fi
# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "jq could not be found. Please install jq to run this script."
exit 1
fi
# Check if a JSON file is provided as an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <json-file>"
exit 1
fi
JSON_FILE=$1
# Check if the JSON file exists
if [ ! -f "$JSON_FILE" ]; then
echo "JSON file not found!"
exit 1
fi
# Define the mapping between release names and filenames
declare -A FILE_MAP
FILE_MAP=(
["@saucelabs/visual"]="visual/src/common/api.ts"
["@saucelabs/cypress-visual-plugin"]="visual-cypress/src/index.ts"
["@saucelabs/nightwatch-sauce-visual-service"]="visual-nightwatch/src/utils/constants.ts"
["@saucelabs/visual-storybook"]="visual-storybook/src/api.ts"
["@saucelabs/wdio-sauce-visual-service"]="visual-wdio/src/SauceVisualService.ts"
["@saucelabs/visual-playwright"]="visual-playwright/src/api.ts"
# Add more mappings as needed
)
# Read releases from the JSON file
releases=$(jq -c '.releases[]' "$JSON_FILE")
# Iterate over each release
for release in $releases; do
# Extract name and version
release_name=$(echo "$release" | jq -r '.name')
version=$(echo "$release" | jq -r '.newVersion')
# Get the corresponding filename from the mapping
filename=${FILE_MAP[$release_name]}
# Exit immediately if a command exits with a non-zero status
set -e
# Check if the filename exists
if [ -n "$filename" ] && [ -f "$filename" ]; then
# Replace the version placeholder in the file
if sed -i "s/PKG_VERSION/$version/g" "$filename"; then
echo "Updated $filename with version $version"
else
echo "Error: Failed to update $filename" >&2
exit 1
fi
else
echo "File for release $release_name not found"
exit 1
fi
done