Skip to content

Commit

Permalink
Remove PACKAGE_PATH and make SOLUTION_FILE_PATH optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
AraHaan committed Jun 15, 2021
1 parent 50c25e3 commit b43ea09
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 12 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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}`}`)
}
}
}
Expand Down

0 comments on commit b43ea09

Please sign in to comment.