diff --git a/dotnet/dotnet-10/Dockerfile b/dotnet/dotnet-10/Dockerfile index 81d1fe2..013c66b 100644 --- a/dotnet/dotnet-10/Dockerfile +++ b/dotnet/dotnet-10/Dockerfile @@ -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"] \ No newline at end of file diff --git a/dotnet/dotnet-10/action.yaml b/dotnet/dotnet-10/action.yaml index 8c451e6..0c79059 100644 --- a/dotnet/dotnet-10/action.yaml +++ b/dotnet/dotnet-10/action.yaml @@ -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' diff --git a/dotnet/dotnet-10/entrypoint.sh b/dotnet/dotnet-10/entrypoint.sh index ebba595..d225b0d 100644 --- a/dotnet/dotnet-10/entrypoint.sh +++ b/dotnet/dotnet-10/entrypoint.sh @@ -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 diff --git a/dotnet/dotnet-10/nuget_utils.sh b/dotnet/dotnet-10/nuget_utils.sh new file mode 100644 index 0000000..00fdff6 --- /dev/null +++ b/dotnet/dotnet-10/nuget_utils.sh @@ -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 +} diff --git a/dotnet/dotnet/Dockerfile b/dotnet/dotnet/Dockerfile index 6e32c23..3299740 100644 --- a/dotnet/dotnet/Dockerfile +++ b/dotnet/dotnet/Dockerfile @@ -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"] \ No newline at end of file diff --git a/dotnet/dotnet/action.yaml b/dotnet/dotnet/action.yaml index d9927cd..b8f4ce6 100644 --- a/dotnet/dotnet/action.yaml +++ b/dotnet/dotnet/action.yaml @@ -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' diff --git a/dotnet/dotnet/entrypoint.sh b/dotnet/dotnet/entrypoint.sh index ebba595..d225b0d 100644 --- a/dotnet/dotnet/entrypoint.sh +++ b/dotnet/dotnet/entrypoint.sh @@ -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 diff --git a/dotnet/dotnet/nuget_utils.sh b/dotnet/dotnet/nuget_utils.sh new file mode 100644 index 0000000..00fdff6 --- /dev/null +++ b/dotnet/dotnet/nuget_utils.sh @@ -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 +} diff --git a/github/download-previous-artifacts/download-previous-artifacts.cs b/github/download-previous-artifacts/download-previous-artifacts.cs index 5cc766e..d298b32 100644 --- a/github/download-previous-artifacts/download-previous-artifacts.cs +++ b/github/download-previous-artifacts/download-previous-artifacts.cs @@ -1,13 +1,19 @@ #!/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; + using Gitea.Net.Api; using Gitea.Net.Client; +using Gitea.Net.Extensions; using Gitea.Net.Model; + using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; string jsonInput = Environment.GetEnvironmentVariable("INPUTS") ?? "{}"; const string name = "Download Previous Artifacts"; @@ -24,18 +30,52 @@ IConfiguration configuration = new ConfigurationBuilder() PrintConfiguration(configuration); -Configuration giteaConfig = GetGiteaConfig(configuration); -RepositoryApi repoApi = new(giteaConfig); +string host = configuration["Host"]!; +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(); +services.AddSingleton(); + +ServiceProvider serviceProvider = services.BuildServiceProvider(); +OrganizationApi organizationApi = serviceProvider.GetRequiredService(); +RepositoryApi repositoryApi = serviceProvider.GetRequiredService(); + +IOrgGetAllApiResponse response = await organizationApi.OrgGetAllAsync(); + +if (response.TryOk(out List 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"]!; -string repoName = configuration["GITHUB_REPOSITORY"]!; -repoName = Path.GetFileName(repoName); +// Repository repo = await repoApi.RepoGetAsync(owner, repoName); - -Repository repo = await repoApi.RepoGetAsync(owner, repoName); - -Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}"); +// Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}"); static void PrintConfiguration(IConfiguration configuration) { @@ -44,25 +84,3 @@ static void PrintConfiguration(IConfiguration configuration) 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; -} diff --git a/tpl/tpl-to-nupkg/action.yaml b/tpl/tpl-to-nupkg/action.yaml index 097ee82..b5d43ed 100644 --- a/tpl/tpl-to-nupkg/action.yaml +++ b/tpl/tpl-to-nupkg/action.yaml @@ -47,4 +47,3 @@ runs: nuspec: ${{ steps.nuspec.outputs.nuspec }} version: ${{ inputs.version }} outputDirectory: ${{ inputs.outputDirectory }} - \ No newline at end of file diff --git a/tpl/tpl-to-nuspec/action.yaml b/tpl/tpl-to-nuspec/action.yaml index 4dc9f5d..4bbe5d7 100644 --- a/tpl/tpl-to-nuspec/action.yaml +++ b/tpl/tpl-to-nuspec/action.yaml @@ -54,14 +54,13 @@ runs: - name: "Convert the Nuspec Yaml to XML" id: xml uses: act/common/yq/yq-convert@master - with: + with: input: ${{ steps.trim.outputs.result }} from: yaml to: xml - name: "Get id from input." id: name uses: act/common/yq/yq-expression@master - with: + with: input: ${{ steps.merge.outputs.result }} expression: .id - \ No newline at end of file