Skip to content

Commit fe017a1

Browse files
james-crowleycpleemergify[bot]
authored
feat: Adding in logic to check if act needs to be downloaded (#2575)
Co-authored-by: Casey Lee <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent b4ef6fb commit fe017a1

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

install.sh

+37-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ usage() {
99
cat <<EOF
1010
$this: download go binaries for nektos/act
1111
12-
Usage: $this [-b bindir] [-d] [tag]
12+
Usage: $this [-b bindir] [-d] [-f] [tag]
1313
-b sets bindir or installation directory, Defaults to ./bin
1414
-d turns on debug logging
15+
-f forces installation, bypassing version checks
1516
[tag] is a tag from
1617
https://github.com/nektos/act/releases
1718
If tag is missing, then the latest will be used.
@@ -24,10 +25,11 @@ parse_args() {
2425
# over-ridden by flag below
2526

2627
BINDIR=${BINDIR:-./bin}
27-
while getopts "b:dh?x" arg; do
28+
while getopts "b:dfh?x" arg; do
2829
case "$arg" in
2930
b) BINDIR="$OPTARG" ;;
3031
d) log_set_priority 10 ;;
32+
f) FORCE_INSTALL="true" ;;
3133
h | \?) usage "$0" ;;
3234
x) set -x ;;
3335
esac
@@ -124,6 +126,37 @@ adjust_arch() {
124126
esac
125127
true
126128
}
129+
check_installed_version() {
130+
# Check if force install flag is set
131+
if [ "${FORCE_INSTALL}" = "true" ]; then
132+
log_info "force install enabled. Skipping version check."
133+
return
134+
fi
135+
136+
# Check if the binary exists
137+
if is_command "$BINARY"; then
138+
# Extract installed version using cut
139+
INSTALLED_VERSION=$($BINARY --version | cut -d' ' -f3)
140+
141+
if [ -z "$INSTALLED_VERSION" ]; then
142+
log_err "failed to detect installed version. Proceeding with installation."
143+
return
144+
fi
145+
146+
log_info "found installed version: $INSTALLED_VERSION"
147+
148+
# Compare versions
149+
if [ "$INSTALLED_VERSION" = "$VERSION" ]; then
150+
log_info "$BINARY version $INSTALLED_VERSION is already installed."
151+
exit 0
152+
else
153+
log_debug "updating $BINARY from version $INSTALLED_VERSION to $VERSION..."
154+
fi
155+
else
156+
log_debug "$BINARY is not installed. Proceeding with installation..."
157+
fi
158+
}
159+
127160

128161
cat /dev/null <<EOF
129162
------------------------------------------------------------------------
@@ -380,6 +413,8 @@ get_binaries
380413

381414
tag_to_version
382415

416+
check_installed_version
417+
383418
adjust_format
384419

385420
adjust_os

0 commit comments

Comments
 (0)