Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback option for falling back to another installation method #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ jobs:
nimble test
```

## Fallback to a different install method

```yaml
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: iffy/install-nim@v4
with:
version: binary:stable
fallback: git:2382937843092342342556456
- name: Test
run: |
nimble install -y
nimble test
```

If you run into trouble with GitHub rate limits, set the `GITHUB_TOKEN` environment variable like this:

```yaml
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ branding:
inputs:
version:
default: stable
fallback:
default: ''

runs:
using: composite
Expand All @@ -15,4 +17,4 @@ runs:
shell: bash
run: |
export SHELL=/bin/bash
"${GITHUB_ACTION_PATH}/install-nim.sh" '${{ inputs.version }}'
"${GITHUB_ACTION_PATH}/install-nim.sh" '${{ inputs.version }}' '${{ inputs.fallback }}'
1 change: 1 addition & 0 deletions changes/new-Add-fallback-option-20230828-160957.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `fallback` option for falling back to another installation method
89 changes: 52 additions & 37 deletions install-nim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ usage() {
cat <<EOF
This script will install Nim for GitHub Actions from a variety of
sources. Provide a single command-line argument of the following
format:
format. Or provide multiple arguments to try each installation target
until one succeeds:

Using choosenim:

Expand Down Expand Up @@ -331,47 +332,61 @@ install_choosenim() {
chmod u+x "${HOME}"/.choosenim/toolchains/*/bin/*
}

#------------------------------------------------
# main
#------------------------------------------------
set -e
TARGET=$1
if [ -z "$TARGET" ]; then
usage
exit 1
fi
do_installation() {
TARGET="$1"
install_type=$(echo "$TARGET" | cut -d: -f1)
install_arg=$(echo "$TARGET" | cut -d: -f2-)
if [ "$install_type" == "$install_arg" ]; then
install_type="choosenim"
fi

install_type=$(echo "$TARGET" | cut -d: -f1)
install_arg=$(echo "$TARGET" | cut -d: -f2-)
if [ "$install_type" == "$install_arg" ]; then
install_type="choosenim"
fi
#------------------------------------------------
# Install Nim
#------------------------------------------------
echo "Install type: $install_type"
echo " param: $install_arg"
(install_${install_type} "${install_arg}")

#------------------------------------------------
# Install Nim
#------------------------------------------------
echo "Install type: $install_type"
echo " param: $install_arg"
(install_${install_type} "${install_arg}")
#------------------------------------------------
# Set up PATH
#------------------------------------------------
echo "Setting up PATH"
[ -f "$NIMDIR/bin/nim" ] && add-path "$(abspath "$NIMDIR/bin")"
[ -f "$(pwd)/$NIMDIR/bin/nim" ] && add-path "$(pwd)/$NIMDIR/bin"
add-path "$HOME/.nimble/bin" && add-path "$(abspath "$HOME/.nimble/bin")"
#[ -f "$HOME/.nimble/bin/nim" ] && add-path "$HOME/.nimble/bin" && add-path "$(abspath "$HOME/.nimble/bin")"

#------------------------------------------------
# Set up PATH
#------------------------------------------------
echo "Setting up PATH"
[ -f "$NIMDIR/bin/nim" ] && add-path "$(abspath "$NIMDIR/bin")"
[ -f "$(pwd)/$NIMDIR/bin/nim" ] && add-path "$(pwd)/$NIMDIR/bin"
add-path "$HOME/.nimble/bin" && add-path "$(abspath "$HOME/.nimble/bin")"
#[ -f "$HOME/.nimble/bin/nim" ] && add-path "$HOME/.nimble/bin" && add-path "$(abspath "$HOME/.nimble/bin")"

#------------------------------------------------
# DLLs
#------------------------------------------------
if [ -f "$HOME/.nimble/bin/nim" ]; then
ensure_dlls "$HOME/.nimble/bin"
elif [ -f "$NIMDIR/bin/nim" ]; then
ensure_dlls "$NIMDIR/bin"
else
echo "Nim doesn't seem to have been installed"
fi
}

#------------------------------------------------
# DLLs
# main
#------------------------------------------------
if [ -f "$HOME/.nimble/bin/nim" ]; then
ensure_dlls "$HOME/.nimble/bin"
elif [ -f "$NIMDIR/bin/nim" ]; then
ensure_dlls "$NIMDIR/bin"
else
echo "Nim doesn't seem to have been installed"
set -e
TARGETS="$@"
if [ -z "$TARGETS" ]; then
usage
exit 1
fi

RC=1
for TARGET in $TARGETS; do
if [ -z "$TARGET" ]; then
break
fi
echo "Trying $TARGET ..."
if do_installation "$TARGET"; then
RC=0
break
fi
done
exit "$RC"