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 # Install NugetForUnity tool: https://github.com/GlitchEnzo/NuGetForUnity
RUN dotnet tool install --global NuGetForUnity.Cli RUN dotnet tool install --global NuGetForUnity.Cli
COPY nuget_utils.sh /nuget_utils.sh
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -11,8 +11,23 @@ inputs:
catchErrors: catchErrors:
description: "Whether or not errors should be handled." description: "Whether or not errors should be handled."
required: false 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: runs:
env: env:
NUGET_SOURCES: ${{ inputs.nugetSources }}
NUGET_USERNAMES: ${{ inputs.nugetUsernames }}
NUGET_PASSWORDS: ${{ inputs.nugetPasswords }}
PROGRAM: ${{ inputs.program }} PROGRAM: ${{ inputs.program }}
CATCH_ERRORS: ${{ inputs.catchErrors }} CATCH_ERRORS: ${{ inputs.catchErrors }}
using: 'docker' using: 'docker'

View File

@@ -1,4 +1,6 @@
#!/bin/bash #!/bin/bash
source nuget_utils.sh
COMMAND="$@" COMMAND="$@"
set -o pipefail set -o pipefail
@@ -21,8 +23,14 @@ if [[ -n "$OUTPUT" ]]; then
echo "EOF" >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT"
fi fi
# Add NuGet sources before running command
handle_nuget_sources "add"
echo "exitCode=$RESULT" >> "$GITHUB_OUTPUT" echo "exitCode=$RESULT" >> "$GITHUB_OUTPUT"
# Remove NuGet sources after running command
handle_nuget_sources "remove"
if [[ "$CATCH_ERRORS" != "true" ]]; then if [[ "$CATCH_ERRORS" != "true" ]]; then
exit $RESULT exit $RESULT
fi 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 ENV NUGETFORUNITY_VERSION=3.1.3
RUN dotnet tool install --global NuGetForUnity.Cli --version ${NUGETFORUNITY_VERSION} RUN dotnet tool install --global NuGetForUnity.Cli --version ${NUGETFORUNITY_VERSION}
COPY nuget_utils.sh /nuget_utils.sh
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -11,8 +11,23 @@ inputs:
catchErrors: catchErrors:
description: "Whether or not errors should be handled." description: "Whether or not errors should be handled."
required: false 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: runs:
env: env:
NUGET_SOURCES: ${{ inputs.nugetSources }}
NUGET_USERNAMES: ${{ inputs.nugetUsernames }}
NUGET_PASSWORDS: ${{ inputs.nugetPasswords }}
PROGRAM: ${{ inputs.program }} PROGRAM: ${{ inputs.program }}
CATCH_ERRORS: ${{ inputs.catchErrors }} CATCH_ERRORS: ${{ inputs.catchErrors }}
using: 'docker' using: 'docker'

View File

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

@@ -1,13 +1,19 @@
#!/usr/bin/env -S dotnet run #!/usr/bin/env -S dotnet run
#:package StudioWhy.Gitea.Net@1.24.2.* #:package StudioWhy.Gitea.Net.API@1.24.2.*
using System.Text.Json; using System.Text.Json;
using System.Text; using System.Text;
using Gitea.Net.Api; using Gitea.Net.Api;
using Gitea.Net.Client; using Gitea.Net.Client;
using Gitea.Net.Extensions;
using Gitea.Net.Model; using Gitea.Net.Model;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
string jsonInput = Environment.GetEnvironmentVariable("INPUTS") ?? "{}"; string jsonInput = Environment.GetEnvironmentVariable("INPUTS") ?? "{}";
const string name = "Download Previous Artifacts"; const string name = "Download Previous Artifacts";
@@ -24,18 +30,52 @@ IConfiguration configuration = new ConfigurationBuilder()
PrintConfiguration(configuration); PrintConfiguration(configuration);
Configuration giteaConfig = GetGiteaConfig(configuration); string host = configuration["Host"]!;
RepositoryApi repoApi = new(giteaConfig); string username = configuration["Username"]!;
string password = configuration["Password"]!;
ServiceCollection services = new();
services.AddApi(o =>
{
BasicToken basicToken = new(username, password);
o.AddTokens(basicToken);
});
UriBuilder hostUriBuilder = new(host);
hostUriBuilder.Path = "/api/v1";
using HttpClient httpClient = new()
{
BaseAddress = hostUriBuilder.Uri,
};
services.AddLogging(configure => configure.AddConsole());
services.AddSingleton(httpClient);
services.AddSingleton<OrganizationApi>();
services.AddSingleton<RepositoryApi>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
OrganizationApi organizationApi = serviceProvider.GetRequiredService<OrganizationApi>();
RepositoryApi repositoryApi = serviceProvider.GetRequiredService<RepositoryApi>();
IOrgGetAllApiResponse response = await organizationApi.OrgGetAllAsync();
if (response.TryOk(out List<Organization> organizations))
{
foreach (Organization org in organizations)
{
Console.WriteLine($"Organization: {org.Name}");
}
//Console.WriteLine($"Repository: {repo?.Name}");
}
// string owner = configuration["GITHUB_REPOSITORY_OWNER"]!;
// string repoName = configuration["GITHUB_REPOSITORY"]!;
// repoName = Path.GetFileName(repoName);
string owner = configuration["GITHUB_REPOSITORY_OWNER"]!; // Repository repo = await repoApi.RepoGetAsync(owner, repoName);
string repoName = configuration["GITHUB_REPOSITORY"]!;
repoName = Path.GetFileName(repoName);
// Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}");
Repository repo = await repoApi.RepoGetAsync(owner, repoName);
Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}");
static void PrintConfiguration(IConfiguration configuration) static void PrintConfiguration(IConfiguration configuration)
{ {
@@ -44,25 +84,3 @@ static void PrintConfiguration(IConfiguration configuration)
Console.WriteLine($"{kvp.Key}: {kvp.Value}"); Console.WriteLine($"{kvp.Key}: {kvp.Value}");
} }
} }
static Configuration GetGiteaConfig(IConfiguration configuration)
{
string host = configuration["Host"]!;
string username = configuration["Username"]!;
string password = configuration["Password"]!;
string accessToken = configuration["Token"]!;
UriBuilder hostUriBuilder = new(host);
hostUriBuilder.Path = "/api/v1";
string hostUri = hostUriBuilder.ToString();
Configuration config = new()
{
BasePath = hostUri,
AccessToken = accessToken,
Username = username,
Password = password,
};
return config;
}

View File

@@ -47,4 +47,3 @@ runs:
nuspec: ${{ steps.nuspec.outputs.nuspec }} nuspec: ${{ steps.nuspec.outputs.nuspec }}
version: ${{ inputs.version }} version: ${{ inputs.version }}
outputDirectory: ${{ inputs.outputDirectory }} outputDirectory: ${{ inputs.outputDirectory }}

View File

@@ -54,14 +54,13 @@ runs:
- name: "Convert the Nuspec Yaml to XML" - name: "Convert the Nuspec Yaml to XML"
id: xml id: xml
uses: act/common/yq/yq-convert@master uses: act/common/yq/yq-convert@master
with: with:
input: ${{ steps.trim.outputs.result }} input: ${{ steps.trim.outputs.result }}
from: yaml from: yaml
to: xml to: xml
- name: "Get id from input." - name: "Get id from input."
id: name id: name
uses: act/common/yq/yq-expression@master uses: act/common/yq/yq-expression@master
with: with:
input: ${{ steps.merge.outputs.result }} input: ${{ steps.merge.outputs.result }}
expression: .id expression: .id