diff --git a/README.md b/README.md index c04308a..5b85f99 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# .NET Setup +# .NET Restore ![License: MIT][shield-license-mit] [![CI][shield-ci]][workflow-ci] diff --git a/action.yml b/action.yml index 04d617f..19fb6de 100644 --- a/action.yml +++ b/action.yml @@ -76,13 +76,14 @@ runs: - name: .NET Restore working-directory: ${{ inputs.working-directory }} shell: bash - run: > - dotnet restore - "${{ inputs.workspace }}" - ${{ inputs.configfile != '' && format('--configfile "{0}"', inputs.configfile) || '' }} - ${{ inputs.ignore-failed-sources != 'false' && '--ignore-failed-sources' || '' }} - ${{ inputs.force != 'false' && '--force' || '' }} - ${{ inputs.force-evaluate != 'false' && '--force-evaluate' || '' }} - ${{ inputs.use-lock-file != 'false' && '--use-lock-file' || '' }} - ${{ inputs.lock-file-path != '' && format('--lock-file-path "{0}"', inputs.lock-file-path) || '' }} - ${{ inputs.locked-mode != 'false' && '--locked-mode' || '' }} + env: + INPUT_WORKSPACE: ${{ inputs.workspace }} + INPUT_CONFIGFILE: ${{ inputs.configfile }} + INPUT_IGNORE_FAILED_SOURCES: ${{ inputs.ignore-failed-sources != 'false' && 'true' || 'false' }} + INPUT_FORCE: ${{ inputs.force != 'false' && 'true' || 'false' }} + INPUT_FORCE_EVALUATE: ${{ inputs.force-evaluate != 'false' && 'true' || 'false' }} + INPUT_USE_LOCK_FILE: ${{ inputs.use-lock-file != 'false' && 'true' || 'false' }} + INPUT_LOCK_FILE_PATH: ${{ inputs.lock-file-path != 'false' && 'true' || 'false' }} + INPUT_LOCKED_MODE: ${{ inputs.locked-mode != 'false' && 'true' || 'false' }} + run: | + "${{ github.action_path }}/entrypoint.sh" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..facf8a2 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +if sdk_version=$(dotnet --version 2>&1); then + echo "Using .NET SDK version '$sdk_version'" +else + echo "::error ::The .NET SDK is not installed" + exit 1 +fi + +if version=$(dotnet restore --version 2>&1); then + echo "Using 'dotnet restore' version '$version'" +else + echo "::error ::The 'dotnet restore' tool is not installed" + exit 1 +fi + +cmd="dotnet restore" + +if [[ -n "$INPUT_CONFIGFILE" ]]; then + cmd+=" --configfile '$INPUT_CONFIGFILE'" +fi + +if [[ -n "$INPUT_IGNORE_FAILED_SOURCES" ]]; then + cmd+=" --ignore-failed-sources" +fi + +if [[ -n "$INPUT_FORCE" ]]; then + cmd+=" --force" +fi + +if [[ -n "$INPUT_FORCE_EVALUATE" ]]; then + cmd+=" --force-evaluate" +fi + +if [[ -n "$INPUT_USE_LOCK_FILE" ]]; then + cmd+=" --use-lock-file" +fi + +if [[ -n "$INPUT_LOCK_FILE_PATH" ]]; then + cmd+=" --lock-file-path '$INPUT_LOCK_FILE_PATH'" +fi + +if [[ -n "$INPUT_LOCKED_MODE" ]]; then + cmd+=" --locked-mode" +fi + +eval "$cmd"