diff --git a/dotnet/dotnet-10/entrypoint.sh b/dotnet/dotnet-10/entrypoint.sh index 88743f2..ebba595 100644 --- a/dotnet/dotnet-10/entrypoint.sh +++ b/dotnet/dotnet-10/entrypoint.sh @@ -4,6 +4,9 @@ set -o pipefail # Add root tools to Path. export PATH="$PATH:/root/.dotnet/tools/" +# Define a local application data folder. +export XDG_DATA_HOME="$HOME/.local/share" +mkdir -p "$XDG_DATA_HOME" PROGRAM=${PROGRAM:-"dotnet"} exec 5>&1 @@ -22,4 +25,4 @@ echo "exitCode=$RESULT" >> "$GITHUB_OUTPUT" if [[ "$CATCH_ERRORS" != "true" ]]; then exit $RESULT -fi \ No newline at end of file +fi diff --git a/dotnet/dotnet-nugetforunity-restore/action.yaml b/dotnet/dotnet-nugetforunity-restore/action.yaml index f748b44..df2934a 100644 --- a/dotnet/dotnet-nugetforunity-restore/action.yaml +++ b/dotnet/dotnet-nugetforunity-restore/action.yaml @@ -1,7 +1,7 @@ name: dotnet-nugetforunity-restore description: "Restore NugetForUnity packages." inputs: - projectPath: + projectPath: description: "Path to the Unity project." required: true default: "." diff --git a/dotnet/dotnet-pack-and-compare/action.yaml b/dotnet/dotnet-pack-and-compare/action.yaml new file mode 100644 index 0000000..309050d --- /dev/null +++ b/dotnet/dotnet-pack-and-compare/action.yaml @@ -0,0 +1,101 @@ +name: nuget-pack-and-compare +description: "Pack a .sln or .csproj file into a .nupkg." +inputs: + name: + description: "The name of the package." + required: true + project: + description: "The .sln or .csproj project to pack." + required: true + configuration: + description: "The build configuration to use. Default: Release" + required: false + default: "Release" + additionalArgs: + description: "Additional arguments to use when packing project." + required: false + keepSymbols: + description: "Keep the '.symbols.nupkg' artifacts. Default: true" + required: false + default: "true" + defaultVersion: + description: "Version of the .nupkg file." + required: true + default: 1.0.0 + outputDirectory: + description: "Directory for the output .nupkg." + required: true + default: "out" + url: + description: "Url of the GitHub server instance." + required: true + default: ${{ github.server_url }} + organization: + description: "Organization to search." + required: true + default: ${{ github.repository_owner }} + username: + description: "Username for the nuget repository to search." + required: true + default: ${{ github.actor }} + password: + description: "Password or ApiKey of the nuget repository to search." + required: true + default: ${{ github.token }} +outputs: + nupkg: + description: "The generated output .nupkg file." + value: ${{ steps.package.outputs.nupkg }} + nupkgName: + description: "The generated output .nupkg file's name." + value: ${{ steps.package.outputs.nupkgName }} + hasChanged: + description: "Whether or not the .nupkg files match." + value: ${{ steps.compare.outputs.success != 'true' }} +runs: + using: "composite" + steps: + - name: "Own workspace." + uses: act/common/utils/chown@master + - name: "Get the next version of the package." + uses: act/common/nuget/nuget-get-next-branched-version@master + id: nuget + with: + name: ${{ inputs.name }} + defaultVersion: ${{ inputs.defaultVersion }} + url: ${{ inputs.url }} + organization: ${{ inputs.organization }} + apiToken: ${{ inputs.password }} + - name: "Build .nupkg." + uses: act/common/dotnet/dotnet-pack@master + with: + project: ${{ inputs.project || inputs.name }} + id: ${{ inputs.name }} + version: ${{ steps.nuget.outputs.nextVersion }} + configuration: ${{ inputs.configuration }} + outputDirectory: ${{ inputs.outputDirectory }} + keepSymbols: ${{ inputs.keepSymbols }} + additionalArgs: ${{ inputs.additionalArgs }} + - name: "Generate package outputs." + id: package + run: | + NUPKG_EXT=".nupkg" + if [ "${{ inputs.keepSymbols }}" == "true" ]; then + NUPKG_EXT=".symbols$NUPKG_EXT" + fi + NUPKG_NAME="${{ inputs.name }}.${{ steps.nuget.outputs.nextVersion }}$NUPKG_EXT" + NUPKG_PATH="${{ inputs.outputDirectory }}/$NUPKG_NAME" + echo "nupkg=$NUPKG_PATH" >> "$GITHUB_OUTPUT" + echo "nupkgName=$NUPKG_NAME" >> "$GITHUB_OUTPUT" + shell: bash + - name: "Compare .nupkg to remote .nupkg." + if: ${{ steps.nuget.outputs.latestVersion }} + id: compare + uses: act/common/nuget/nuget-compare-version@master + with: + lhs: ${{ steps.package.outputs.nupkg }} + version: ${{ steps.nuget.outputs.latestVersion }} + name: ${{ inputs.name }} + username: ${{ inputs.username }} + password: ${{ inputs.password }} + url: ${{ inputs.url }}/_registry/nuget/${{ inputs.organization }}/index.json diff --git a/dotnet/dotnet-pack/action.yaml b/dotnet/dotnet-pack/action.yaml new file mode 100644 index 0000000..c220a10 --- /dev/null +++ b/dotnet/dotnet-pack/action.yaml @@ -0,0 +1,88 @@ +# Reference: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack +name: dotnet-pack +description: "Pack a .sln or .csproj file into a .nupkg." +inputs: + project: + description: "The .sln or .csproj project to pack." + required: true + default: . + id: + description: "The id of the package. Defaults to the AssemblyName." + required: false + default: "" + version: + description: "Version of the .nupkg file." + required: false + default: "" + outputDirectory: + description: "Directory for the output file." + required: true + repositoryBranch: + description: "The repository branch of the package." + required: false + default: ${{ github.ref_name }} + deterministic: + description: "Whether or not the build should be deterministic. Default: true" + required: false + default: "true" + configuration: + description: "The build configuration to use. Default: Release" + required: false + default: "Release" + additionalArgs: + description: "Additional arguments to use when packing project." + required: false + keepSymbols: + description: "Keep the '.symbols.nupkg' artifacts. Default: true" + required: false + default: "true" +runs: + using: "composite" + steps: + - name: "Parse the version." + id: version + uses: act/common/utils/version-parse@master + with: + version: ${{ inputs.version }} + - name: "Build the pack command." + id: command + run: | + #https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/versioning + MMP_VERSION="${{ steps.version.outputs.major || 0 }}.${{ steps.version.outputs.minor || 0 }}" + + COMMAND="pack \"${{ inputs.project }}\" --output \"${{ inputs.outputDirectory }}\"" + CONFIG="${{ inputs.configuration }}" + if [[ -n "$CONFIG" ]]; then + COMMAND="$COMMAND --configuration \"$CONFIG\"" + fi + ID="${{ inputs.id }}" + if [[ -n "$ID" ]]; then + COMMAND="$COMMAND -p:PackageId=$ID" + fi + VERSION="${{ inputs.version }}" + if [[ -n "$VERSION" ]]; then + COMMAND="$COMMAND -p:Version=$VERSION -p:AssemblyVersion=$MM_VERSION" + fi + BRANCH="${{ inputs.repositoryBranch }}" + if [[ -n "$BRANCH" ]]; then + COMMAND="$COMMAND -p:RepositoryBranch=$BRANCH" + fi + DETERMINISTIC="${{ inputs.deterministic }}" + if [[ "$DETERMINISTIC" == "true" ]]; then + COMMAND="$COMMAND -p:ContinuousIntegrationBuild=$DETERMINISTIC" + fi + echo "command=$COMMAND ${{ inputs.additionalArgs }}" >> "$GITHUB_OUTPUT" + shell: bash + - name: "Build the .nupkg file." + uses: act/common/dotnet/dotnet-6@master + with: + command: ${{ steps.command.outputs.command }} + - name: "Own artifacts." + uses: act/common/utils/chown@master + with: + file: ${{ inputs.outputDirectory }} + - name: "Remove symbols." + if: ${{ inputs.keepSymbols == 'false' }} + run: | + rm -rf "${{ inputs.outputDirectory }}"/*.symbols.nupkg + shell: bash diff --git a/dotnet/dotnet-push/action.yaml b/dotnet/dotnet-push/action.yaml index 4db5e3e..39d70a0 100644 --- a/dotnet/dotnet-push/action.yaml +++ b/dotnet/dotnet-push/action.yaml @@ -7,7 +7,10 @@ inputs: url: description: "URL of the nuget repository to push to." required: true - default: ${{ github.server_url }}/_registry/nuget/${{ github.repository_owner }}/index.json + # This is for GitHub. + #default: ${{ github.server_url }}/_registry/nuget/${{ github.repository_owner }}/index.json + # This is for Gitea. + default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json apiKey: description: "ApiKey of the nuget repository to push to." required: true @@ -21,4 +24,4 @@ runs: - name: "Push the NuGet package." uses: act/common/dotnet/dotnet@master with: - command: nuget push ${{ inputs.nupkg }} -s ${{ inputs.url }} -k ${{ inputs.apiKey }} ${{ inputs.options }} \ No newline at end of file + command: nuget push ${{ inputs.nupkg }} -s ${{ inputs.url }} -k ${{ inputs.apiKey }} ${{ inputs.options }} diff --git a/dotnet/dotnet-test/action.yaml b/dotnet/dotnet-test/action.yaml new file mode 100644 index 0000000..0e92e09 --- /dev/null +++ b/dotnet/dotnet-test/action.yaml @@ -0,0 +1,106 @@ +# Reference: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test +name: dotnet-test +description: "Test a .csproj, .sln file, or .dll." +inputs: + project: + description: "The .csproj or .sln project to pack." + required: true + default: . + collect: + description: "Enable the data collector. Options: 'Code Coverage', 'XPlat Code Coverage' (for Coverlet)" + required: false + default: "XPlat Code Coverage" + resultsDirectory: + description: "Directory for the test results." + required: true + default: "TestResults" + logger: + description: "Logger to use. Default: trx" + required: false + default: "trx" + configuration: + description: "The build configuration to use. Default: Release" + required: false + default: "Release" + filter: + description: "Test filter expression." + required: false + default: "" + additionalArgs: + description: "Additional arguments to use when packing project." + required: false + testFormat: + description: "Test format to use when running tests. Default: opencover" + required: false + default: "opencover" + runSettings: + description: "Additional runs settings to use when testing the project." + required: false + default: "" + uploadArtifacts: + description: "Upload the test output as artifacts. Default: true" + required: false + default: "true" + artifactName: + description: "Name of the artifact to upload. Default: TestResults" + required: false + default: "TestResults" + retention-days: + description: "Default number of retention days." + required: false + default: "7" +runs: + using: "composite" + steps: + - name: "Build the test command." + id: command + run: | + COMMAND="test \"${{ inputs.project }}\" --nologo --results-directory \"${{ inputs.resultsDirectory }}\"" + CONFIG="${{ inputs.configuration }}" + if [[ -n "$CONFIG" ]]; then + COMMAND="$COMMAND --configuration \"$CONFIG\"" + fi + COLLECT="${{ inputs.collect }}" + if [[ -n "$COLLECT" ]]; then + COMMAND="$COMMAND --collect \"$COLLECT\"" + fi + LOGGER="${{ inputs.logger }}" + if [[ -n "$LOGGER" ]]; then + COMMAND="$COMMAND --logger \"$LOGGER\"" + fi + FILTER="${{ inputs.filter }}" + if [[ -n "$FILTER" ]]; then + COMMAND="$COMMAND $FILTER --filter \"$FILTER\"" + fi + ADDITIONAL_ARGS="${{ inputs.additionalArgs }}" + if [[ -n "$ADDITIONAL_ARGS" ]]; then + COMMAND="$COMMAND $ADDITIONAL_ARGS" + fi + # For run settings. + COMMAND="$COMMAND --" + TEST_FORMAT="${{ inputs.testFormat }}" + if [[ -n "$TEST_FORMAT" ]]; then + COMMAND="$COMMAND DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=\"$TEST_FORMAT\"" + fi + RUN_SETTINGS="${{ inputs.runSettings }}" + if [[ -n "$RUN_SETTINGS" ]]; then + COMMAND="$COMMAND $RUN_SETTINGS" + fi + echo "command=$COMMAND" >> "$GITHUB_OUTPUT" + shell: bash + - name: "Run the Unit Tests." + uses: act/common/dotnet/dotnet-6@master + with: + command: ${{ steps.command.outputs.command }} + - name: "Own artifacts." + uses: act/common/utils/chown@master + with: + file: ${{ inputs.resultsDirectory }} + - name: "Upload artifacts." + if: ${{ !env.ACT && ( inputs.uploadArtifacts == 'true' ) }} + uses: https://github.com/actions/upload-artifact@v3 + with: + name: ${{ inputs.artifactName }} + path: ${{ inputs.resultsDirectory }} + if-no-files-found: error + retention-days: ${{ inputs.retention-days }} diff --git a/dotnet/dotnet/Dockerfile b/dotnet/dotnet/Dockerfile index b3169bc..6e32c23 100644 --- a/dotnet/dotnet/Dockerfile +++ b/dotnet/dotnet/Dockerfile @@ -1,4 +1,4 @@ -ARG VERSION=7.0 +ARG VERSION=9.0 FROM mcr.microsoft.com/dotnet/sdk:$VERSION RUN apt update @@ -7,7 +7,8 @@ RUN apt install curl -y # Add tools to Path. RUN echo 'export PATH="$PATH:$HOME/.dotnet/tools/"' | tee -a "$HOME/.bashrc" > /dev/null # Install NugetForUnity tool: https://github.com/GlitchEnzo/NuGetForUnity -RUN dotnet tool install --global NuGetForUnity.Cli +ENV NUGETFORUNITY_VERSION=3.1.3 +RUN dotnet tool install --global NuGetForUnity.Cli --version ${NUGETFORUNITY_VERSION} COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh diff --git a/dotnet/dotnet/entrypoint.sh b/dotnet/dotnet/entrypoint.sh index 88743f2..ebba595 100644 --- a/dotnet/dotnet/entrypoint.sh +++ b/dotnet/dotnet/entrypoint.sh @@ -4,6 +4,9 @@ set -o pipefail # Add root tools to Path. export PATH="$PATH:/root/.dotnet/tools/" +# Define a local application data folder. +export XDG_DATA_HOME="$HOME/.local/share" +mkdir -p "$XDG_DATA_HOME" PROGRAM=${PROGRAM:-"dotnet"} exec 5>&1 @@ -22,4 +25,4 @@ echo "exitCode=$RESULT" >> "$GITHUB_OUTPUT" if [[ "$CATCH_ERRORS" != "true" ]]; then exit $RESULT -fi \ No newline at end of file +fi diff --git a/github/download-previous-artifacts/download-previous-artifacts.cs b/github/download-previous-artifacts/download-previous-artifacts.cs index 6d23333..b29d13b 100644 --- a/github/download-previous-artifacts/download-previous-artifacts.cs +++ b/github/download-previous-artifacts/download-previous-artifacts.cs @@ -1,19 +1,7 @@ #!/usr/bin/env -S dotnet run #:package Gitea.Net.API@25.3.* -// static class Program -// { -// static void Main(string[] args) -// { -// Run(); -// } -// static void Run() -// { -// // Your code here -// Console.WriteLine("Running the program..."); -// } -// } using System.Text.Json; using System.Text; using Gitea.Net.Api; @@ -21,16 +9,11 @@ using Gitea.Net.Client; using Gitea.Net.Model; using Microsoft.Extensions.Configuration; -Console.WriteLine("Hello, World!"); -// Console.WriteLine("Environment Variables:"); -// Console.WriteLine(JsonSerializer.Serialize(Environment.GetEnvironmentVariables())); -// Console.WriteLine("Arguments:"); -// Console.WriteLine(JsonSerializer.Serialize(args)); - - -//string jsonInput = args.Length > 0 ? args[0] : "{}"; string jsonInput = Environment.GetEnvironmentVariable("INPUTS") ?? "{}"; -Console.WriteLine($"JSON Input: {jsonInput}"); +const string name = "Download Previous Artifacts"; +Console.WriteLine($"::group::{name} - Inputs"); +Console.WriteLine(jsonInput); +Console.WriteLine("::endgroup::"); byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonInput); using MemoryStream memoryStream = new(jsonBytes); @@ -49,9 +32,7 @@ string owner = configuration["GITHUB_REPOSITORY_OWNER"]!; string repoName = configuration["GITHUB_REPOSITORY"]!; repoName = Path.GetFileName(repoName); -Console.WriteLine($"Owner: {owner}"); -Console.WriteLine($"Repository: {repoName}"); -Console.WriteLine($"Host: {giteaConfig.BasePath}"); + Repository repo = await repoApi.RepoGetAsync(owner, repoName); Console.WriteLine($"Repository:\n {JsonSerializer.Serialize(repo)}"); diff --git a/nuget/nuget-upload-nupkg/action.yaml b/nuget/nuget-upload-nupkg/action.yaml index 1264e3e..8353520 100644 --- a/nuget/nuget-upload-nupkg/action.yaml +++ b/nuget/nuget-upload-nupkg/action.yaml @@ -7,7 +7,7 @@ inputs: source: description: "Name of the source to use." required: true - default: lewdorg + default: ${{ github.repository_owner }} url: description: "Url of the NuGet repository." required: true