-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·80 lines (68 loc) · 2.34 KB
/
entrypoint.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
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
set -euo pipefail
if [[ $GITHUB_EVENT_NAME != 'release' && -z $INPUT_CURRENT_VERSION ]]; then
echo "Skipping: This should only run on release not '$GITHUB_EVENT_NAME'.";
exit 0;
fi
git fetch origin +refs/tags/*:refs/tags/*
NEW_TAG=${INPUT_NEW_VERSION:-"${GITHUB_REF/refs\/tags\//}"}
CURRENT_TAG=$INPUT_CURRENT_VERSION && exit_status=$? || exit_status=$?
PATTERN=$INPUT_PATTERN
if [[ -z "$CURRENT_TAG" ]]; then
CURRENT_TAG=$(git tag --sort=-v:refname | grep -vE "^v[0-9]+$" | head -n 2 | tail -n 1) && exit_status=$? || exit_status=$?
fi
if [[ -n "$INPUT_STRIP_PREFIX" ]]; then
CURRENT_TAG=${CURRENT_TAG#"$INPUT_STRIP_PREFIX"}
NEW_TAG=${NEW_TAG#"$INPUT_STRIP_PREFIX"}
fi
if [[ $exit_status -ne 0 ]]; then
echo "::warning::Initial release detected no updates would be made to specified files."
echo "::warning::Setting new_version and old_version to $NEW_TAG."
cat <<EOF >> "$GITHUB_OUTPUT"
is_initial_release=true
new_version=$NEW_TAG
old_version=$NEW_TAG
EOF
exit 0;
else
echo "is_initial_release=false" >> "$GITHUB_OUTPUT"
fi
if [[ "$INPUT_ONLY_MAJOR" == "true" ]]; then
NEW_MAJOR_TAG=$(echo "$NEW_TAG" | cut -d. -f1)
CURRENT_MAJOR_TAG=$(echo "$CURRENT_TAG" | cut -d. -f1)
if [[ "$NEW_MAJOR_TAG" == "$CURRENT_MAJOR_TAG" ]]; then
echo "Skipping: This will only run on major version release not '$NEW_TAG'.";
cat <<EOF >> "$GITHUB_OUTPUT"
new_version=$NEW_TAG
old_version=$CURRENT_TAG
major_update=false
EOF
else
for path in $INPUT_PATHS
do
echo "Replacing major version $CURRENT_MAJOR_TAG with $NEW_MAJOR_TAG for: $path"
sed -i "s|$PATTERN$CURRENT_MAJOR_TAG\(.[[:digit:]]\)\{0,1\}\(.[[:digit:]]\)\{0,1\}|$PATTERN$NEW_MAJOR_TAG|g" "$path"
done
cat <<EOF >> "$GITHUB_OUTPUT"
new_version=$NEW_MAJOR_TAG
old_version=$CURRENT_TAG
major_update=true
EOF
fi
else
NEW_MAJOR_TAG=$(echo "$NEW_TAG" | cut -d. -f1)
if [[ "$NEW_TAG" == "$NEW_MAJOR_TAG" ]]; then
echo "::warning::New version $NEW_TAG is a major version, skipping minor and patch version updates. You can set only_major to true to prevent this warning."
else
for path in $INPUT_PATHS
do
echo "Replacing $CURRENT_TAG with $NEW_TAG for: $path"
sed -i "s|$PATTERN$CURRENT_TAG|$PATTERN$NEW_TAG|g" "$path"
done
fi
cat <<EOF >> "$GITHUB_OUTPUT"
new_version=$NEW_TAG
old_version=$CURRENT_TAG
major_update=true
EOF
fi