From b43ea098f6d27a52b2876f772c34c6fbf18b5050 Mon Sep 17 00:00:00 2001 From: AraHaan Date: Mon, 14 Jun 2021 23:56:46 -0400 Subject: [PATCH] Remove PACKAGE_PATH and make SOLUTION_FILE_PATH optional. --- README.md | 5 +---- action.yml | 6 ++---- index.js | 33 ++++++++++++--------------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 17943d7..883f7fa 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,6 @@ jobs: - name: Restore, Build, test, and pack uses: Elskom/build-dotnet@main with: - SOLUTION_FILE_PATH: solution.sln - PACKAGE_PATH: artifacts/ TEST: true ``` @@ -36,8 +34,7 @@ Project gets built, optionally tested, and packaged (packaging is default enable Input | Default Value | Description --- | --- | --- -SOLUTION_FILE_PATH | | Filepath of the solution of which contains all the projects to be packed, relative to root of repository -PACKAGE_PATH | | Path to store all generated nuget packages, relative to root of repository +SOLUTION_FILE_PATH | `''` | Filepath of the solution of which contains all the projects to be packed, relative to root of repository TEST | `false` | Flag to toggle running unit tests for the projects built, disabled by default PACK | `true` | Flag to toggle packing the projects built, enabled by default diff --git a/action.yml b/action.yml index 3f9bc9c..8eb8283 100644 --- a/action.yml +++ b/action.yml @@ -5,10 +5,8 @@ description: 📦 GitHub action to build, test, and package projects. inputs: SOLUTION_FILE_PATH: description: Filepath of the solution of which contains all the projects to be built, optionally tested and packed, relative to root of repository - required: true - PACKAGE_PATH: - description: Path to store all generated nuget packages, relative to root of repository - required: true + required: false + default: '' TEST: description: Flag to toggle running unit tests for the projects built, disabled by default required: false diff --git a/index.js b/index.js index 784c1c0..e19f199 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,12 @@ -const os = require("os"), - fs = require("fs"), - path = require("path"), +const fs = require("fs"), spawnSync = require("child_process").spawnSync class Action { constructor() { - this.solutionFile = process.env.SOLUTION_FILE_PATH - this.packagePath = process.env.PACKAGE_PATH - this.test = process.env.TEST - this.pack = process.env.PACK + this.solutionFile = process.env.INPUT_SOLUTION_FILE_PATH + this.test = process.env.INPUT_TEST + this.pack = process.env.INPUT_PACK } _printErrorAndExit(msg) { @@ -24,32 +21,26 @@ class Action { return spawnSync(TOOL, ARGS, options) } + _executeInProcess(cmd) { + this._executeCommand(cmd, { encoding: "utf-8", stdio: [process.stdin, process.stdout, process.stderr] }) + } + run() { if (!this.solutionFile || !fs.existsSync(this.solutionFile)) { this._printErrorAndExit("solution file not found") } - if (!this.packagePath || !fs.existsSync(this.packagePath)) { - this._printErrorAndExit("PACKAGE_PATH not provided.") - } - - // nuke any normal .nupkg/.snupkg inside the user specified package path - // and then build the packages for the resulting projects inside of the - // solution file specified. - fs.readdirSync(this.packagePath).filter(fn => /\.s?nupkg$/.test(fn)).forEach(fn => fs.unlinkSync(fn)) - console.log(this._executeCommand(`dotnet restore ${this.solutionFile}`).stdout) - console.log(this._executeCommand(`dotnet build -c Release --no-restore ${this.solutionFile}`).stdout) + this._executeInProcess(`dotnet restore${this.solutionFile === "" ? this.solutionFile : ` ${this.solutionFile}`}`) + this._executeInProcess(`dotnet build -c Release --no-restore${this.solutionFile === "" ? this.solutionFile : ` ${this.solutionFile}`}`) if (this.test) { - console.log(this._executeCommand(`dotnet test -c Release --no-build --no-restore ${this.solutionFile}`).stdout) + this._executeInProcess(`dotnet test -c Release --no-build --no-restore${this.solutionFile === "" ? this.solutionFile : ` ${this.solutionFile}`}`) } if (this.pack) { console.log(`Note: To package symbol packages as well as normal packages specify these msbuild properties inside of the project's csproj file or to an Directory.Build.props file that is automatically imported by the .NET SDK:`) console.log(`https://docs.microsoft.com/en-us/nuget/create-packages/symbol-packages-snupkg#creating-a-symbol-package`) console.log(`setting these will be honored when calling dotnet pack and dotnet nugget push.`) - console.log(this._executeCommand(`dotnet pack --no-build --no-restore -c Release ${this.solutionFile} -o ${this.packagePath}`).stdout) - const packages = fs.readdirSync(this.packagePath).filter(fn => fn.endsWith("nupkg")) - console.log(`Generated Package(s): ${packages.join(", ")}`) + this._executeInProcess(`dotnet pack --no-build --no-restore -c Release${this.solutionFile === "" ? this.solutionFile : ` ${this.solutionFile}`}`) } } }