Updated .net actions.

This commit is contained in:
2025-07-07 20:58:04 -07:00
parent 50bfb1278e
commit d41bf186fe
11 changed files with 188 additions and 36 deletions

View File

@@ -9,6 +9,7 @@ RUN echo 'export PATH="$PATH:$HOME/.dotnet/tools/"' | tee -a "$HOME/.bashrc" > /
# Install NugetForUnity tool: https://github.com/GlitchEnzo/NuGetForUnity
RUN dotnet tool install --global NuGetForUnity.Cli
COPY nuget_utils.sh /nuget_utils.sh
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -11,8 +11,23 @@ inputs:
catchErrors:
description: "Whether or not errors should be handled."
required: false
nugetSources:
description: "List of additional NuGet sources to use."
required: false
default: ""
nugetUsernames:
description: "List of additional NuGet usernames to use."
required: false
default: ""
nugetPasswords:
description: "List of additional NuGet passwords to use."
required: false
default: ""
runs:
env:
NUGET_SOURCES: ${{ inputs.nugetSources }}
NUGET_USERNAMES: ${{ inputs.nugetUsernames }}
NUGET_PASSWORDS: ${{ inputs.nugetPasswords }}
PROGRAM: ${{ inputs.program }}
CATCH_ERRORS: ${{ inputs.catchErrors }}
using: 'docker'

View File

@@ -1,4 +1,6 @@
#!/bin/bash
source nuget_utils.sh
COMMAND="$@"
set -o pipefail
@@ -21,8 +23,14 @@ if [[ -n "$OUTPUT" ]]; then
echo "EOF" >> "$GITHUB_OUTPUT"
fi
# Add NuGet sources before running command
handle_nuget_sources "add"
echo "exitCode=$RESULT" >> "$GITHUB_OUTPUT"
# Remove NuGet sources after running command
handle_nuget_sources "remove"
if [[ "$CATCH_ERRORS" != "true" ]]; then
exit $RESULT
fi

View File

@@ -0,0 +1,44 @@
#!/bin/bash
# Function to add or remove a single NuGet source
add_or_remove_nuget_source() {
local action="$1"
local source="$2"
local username="$3"
local password="$4"
if [[ -n "$source" ]]; then
if [[ "$action" == "remove" ]]; then
echo "Removing NuGet source: $source"
dotnet nuget remove source "$source" 2>/dev/null || true
else
echo "Adding NuGet source: $source"
if [[ -n "$username" && -n "$password" ]]; then
dotnet nuget add source "$source" --username "$username" --password "$password" --store-password-in-clear-text
else
dotnet nuget add source "$source"
fi
fi
fi
}
# Function to add/remove NuGet sources
handle_nuget_sources() {
local action="${1:-add}" # Default to 'add', can be 'remove'
if [[ -n "$NUGET_SOURCES" ]]; then
# Split sources, usernames, and passwords on newlines
IFS=$'\n' read -rd '' -a sources <<< "$NUGET_SOURCES"
IFS=$'\n' read -rd '' -a usernames <<< "$NUGET_USERNAMES"
IFS=$'\n' read -rd '' -a passwords <<< "$NUGET_PASSWORDS"
# Loop through sources
for i in "${!sources[@]}"; do
# Trim whitespace
source=$(echo "${sources[$i]}" | xargs)
username=$(echo "${usernames[$i]:-}" | xargs)
password=$(echo "${passwords[$i]:-}" | xargs)
add_or_remove_nuget_source "$action" "$source" "$username" "$password"
done
fi
}

View File

@@ -10,6 +10,7 @@ RUN echo 'export PATH="$PATH:$HOME/.dotnet/tools/"' | tee -a "$HOME/.bashrc" > /
ENV NUGETFORUNITY_VERSION=3.1.3
RUN dotnet tool install --global NuGetForUnity.Cli --version ${NUGETFORUNITY_VERSION}
COPY nuget_utils.sh /nuget_utils.sh
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -11,8 +11,23 @@ inputs:
catchErrors:
description: "Whether or not errors should be handled."
required: false
nugetSources:
description: "List of additional NuGet sources to use."
required: false
default: ""
nugetUsernames:
description: "List of additional NuGet usernames to use."
required: false
default: ""
nugetPasswords:
description: "List of additional NuGet passwords to use."
required: false
default: ""
runs:
env:
NUGET_SOURCES: ${{ inputs.nugetSources }}
NUGET_USERNAMES: ${{ inputs.nugetUsernames }}
NUGET_PASSWORDS: ${{ inputs.nugetPasswords }}
PROGRAM: ${{ inputs.program }}
CATCH_ERRORS: ${{ inputs.catchErrors }}
using: 'docker'

View File

@@ -1,4 +1,6 @@
#!/bin/bash
source nuget_utils.sh
COMMAND="$@"
set -o pipefail
@@ -21,8 +23,14 @@ if [[ -n "$OUTPUT" ]]; then
echo "EOF" >> "$GITHUB_OUTPUT"
fi
# Add NuGet sources before running command
handle_nuget_sources "add"
echo "exitCode=$RESULT" >> "$GITHUB_OUTPUT"
# Remove NuGet sources after running command
handle_nuget_sources "remove"
if [[ "$CATCH_ERRORS" != "true" ]]; then
exit $RESULT
fi

View File

@@ -0,0 +1,44 @@
#!/bin/bash
# Function to add or remove a single NuGet source
add_or_remove_nuget_source() {
local action="$1"
local source="$2"
local username="$3"
local password="$4"
if [[ -n "$source" ]]; then
if [[ "$action" == "remove" ]]; then
echo "Removing NuGet source: $source"
dotnet nuget remove source "$source" 2>/dev/null || true
else
echo "Adding NuGet source: $source"
if [[ -n "$username" && -n "$password" ]]; then
dotnet nuget add source "$source" --username "$username" --password "$password" --store-password-in-clear-text
else
dotnet nuget add source "$source"
fi
fi
fi
}
# Function to add/remove NuGet sources
handle_nuget_sources() {
local action="${1:-add}" # Default to 'add', can be 'remove'
if [[ -n "$NUGET_SOURCES" ]]; then
# Split sources, usernames, and passwords on newlines
IFS=$'\n' read -rd '' -a sources <<< "$NUGET_SOURCES"
IFS=$'\n' read -rd '' -a usernames <<< "$NUGET_USERNAMES"
IFS=$'\n' read -rd '' -a passwords <<< "$NUGET_PASSWORDS"
# Loop through sources
for i in "${!sources[@]}"; do
# Trim whitespace
source=$(echo "${sources[$i]}" | xargs)
username=$(echo "${usernames[$i]:-}" | xargs)
password=$(echo "${passwords[$i]:-}" | xargs)
add_or_remove_nuget_source "$action" "$source" "$username" "$password"
done
fi
}