From fc4116f33244d12dcc7bd3cf030c8d36a9bcd862 Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:34:14 +0300 Subject: [PATCH 01/20] added hack to get versions array from GPR --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f123d67..b177cbc 100644 --- a/index.js +++ b/index.js @@ -94,8 +94,17 @@ class Action { } console.log(`Package Name: ${this.packageName}`) + + let requestUrl = "" + + //small hack to get package versions from Github Package Registry + if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { + requestUrl = `${this.nugetSource}/download/${this.packageName}/index.json` + } else { + requestUrl = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` + } - https.get(`${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json`, res => { + https.get(requestUrl, res => { let body = "" if (res.statusCode == 404){ From 6c1fcca9220f51b54517da86ec7f1b6821e2266b Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Tue, 20 Oct 2020 14:46:23 +0300 Subject: [PATCH 02/20] added hack to get versions array from GPR --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index db47a6d..c3ca4ff 100644 --- a/index.js +++ b/index.js @@ -93,8 +93,16 @@ class Action { } console.log(`Package Name: ${this.packageName}`) + let requestUrl = "" - https.get(`${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json`, res => { + //small hack to get package versions from Github Package Registry + if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { + requestUrl = `${this.nugetSource}/download/${this.packageName}/index.json` + } else { + requestUrl = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` + } + + https.get(requestUrl, res => { let body = "" if (res.statusCode == 404) From d14f1f316069f214590fd82eadd231339d801fcd Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:52:54 +0300 Subject: [PATCH 03/20] Update action.yml --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 71c0ee9..f72fce2 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ -name: Publish NuGet -author: Rohith Reddy (@rohith) -description: Build, Pack & Publish a NuGet package with dotnet core on project version change +name: Publish NuGet 2 +author: Rebel028 +description: Build, Pack & Publish a NuGet package with dotnet core on project version change (temporary fork of https://github.com/brandedoutcast/publish-nuget/) inputs: PROJECT_FILE_PATH: From 9da2a97aefdb5ae433f5758ad73d67d46b585ccb Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:59:55 +0300 Subject: [PATCH 04/20] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f72fce2..3674fd7 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ name: Publish NuGet 2 author: Rebel028 -description: Build, Pack & Publish a NuGet package with dotnet core on project version change (temporary fork of https://github.com/brandedoutcast/publish-nuget/) +description: Temporary fork of https://github.com/brandedoutcast/publish-nuget/ inputs: PROJECT_FILE_PATH: From 08574af7243cbfcb21bb6c038e4b12277773b663 Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Thu, 22 Oct 2020 15:28:18 +0300 Subject: [PATCH 05/20] Update index.js --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index b177cbc..b8a7434 100644 --- a/index.js +++ b/index.js @@ -100,12 +100,16 @@ class Action { //small hack to get package versions from Github Package Registry if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { requestUrl = `${this.nugetSource}/download/${this.packageName}/index.json` + console.log(`This is GPR, changing url for versioning...`) + console.log(requestUrl) } else { requestUrl = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` } https.get(requestUrl, res => { let body = "" + + console.log(res) if (res.statusCode == 404){ console.log(`No packages found. Pushing initial version...`) From ef77d7a54fa3e9941f212438bcb441617c1c3cda Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Thu, 22 Oct 2020 15:29:57 +0300 Subject: [PATCH 06/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2992a1d..5fb8002 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ SYMBOLS_PACKAGE_PATH | Path to the generated symbols package **FYI:** - Outputs may or may not be set depending on the action inputs or if the action failed -- `NUGET_SOURCE` must support `/v3-flatcontainer/PACKAGE_NAME/index.json` for version change detection to work +- ~`NUGET_SOURCE` must support `/v3-flatcontainer/PACKAGE_NAME/index.json` for version change detection to work~ - Multiple projects can make use of steps to configure each project individually, common inputs between steps can be given as `env` for [job / workflow](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#env) ## License From 9c9998220284aff508d141090ad6bea970d157df Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Thu, 22 Oct 2020 15:56:03 +0300 Subject: [PATCH 07/20] Updated status codes handling --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b8a7434..6649b9d 100644 --- a/index.js +++ b/index.js @@ -109,14 +109,13 @@ class Action { https.get(requestUrl, res => { let body = "" - console.log(res) + console.log(`Status code: ${res.statusCode}: ${res.statusMessage}`) if (res.statusCode == 404){ console.log(`No packages found. Pushing initial version...`) this._pushPackage(this.version, this.packageName) - } - - if (res.statusCode == 200) { + } + else if (res.statusCode == 200) { res.setEncoding("utf8") res.on("data", chunk => body += chunk) res.on("end", () => { @@ -136,6 +135,10 @@ class Action { } }) } + else { + this._printErrorAndExit(`error: ${res.statusCode}: ${res.statusMessage}`) + } + }).on("error", e => { this._printErrorAndExit(`error: ${e.message}`) }) From 605df4681adf5a64580aa1671d8ea87b91d6ed4e Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Thu, 3 Dec 2020 21:10:31 +0300 Subject: [PATCH 08/20] handling source type --- README.md | 7 ++++--- action.yml | 5 ++++- index.js | 33 +++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7f46d67..1a2530c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ jobs: name: build, pack & publish runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2.5.9 # - name: Setup dotnet # uses: actions/setup-dotnet@v1 @@ -48,7 +48,7 @@ jobs: # Format of the git tag, [*] gets replaced with actual version # TAG_FORMAT: v* - # API key to authenticate with NuGet server + # API key to authenticate with NuGet server, or a token, issued for GITHUB_USER if you use GPR # NUGET_KEY: ${{secrets.NUGET_API_KEY}} # NuGet server uri hosting the packages, defaults to https://api.nuget.org @@ -71,7 +71,8 @@ VERSION_REGEX | `^\s*(.*)<\/Version>\s*$` | Regex pattern to extract ve VERSION_STATIC| | Useful with external providers like Nerdbank.GitVersioning, ignores VERSION_FILE_PATH & VERSION_REGEX TAG_COMMIT | `true` | Flag to toggle git tagging, enabled by default TAG_FORMAT | `v*` | Format of the git tag, `[*]` gets replaced with actual version -NUGET_KEY | | API key to authenticate with NuGet server +GITHUB_USER |`[GITHUB_ACTOR]` | Required for packages pushed to Github Package Registry. User allowed to push to repository, defaults to GITHUB_ACTOR (user that triggered the action) +NUGET_KEY | | API key to authenticate with NuGet server, or a token, issued for GITHUB_USER if you use GPR NUGET_SOURCE | `https://api.nuget.org` | NuGet server uri hosting the packages, defaults to https://api.nuget.org INCLUDE_SYMBOLS | `false` | Flag to toggle pushing symbols along with nuget package to the server, disabled by default diff --git a/action.yml b/action.yml index 9dc71b2..be9d200 100644 --- a/action.yml +++ b/action.yml @@ -27,8 +27,11 @@ inputs: description: Format of the git tag, [*] gets replaced with actual version required: false default: v* + GITHUB_USER: + description: Required for packages pushed to Github Package Registry. User allowed to push to repository, defaults to GITHUB_ACTOR (user that triggered the action) + required: false NUGET_KEY: - description: API key to authenticate with NuGet server + description: API key to authenticate with NuGet server, or a token, issued for GITHUB_USER if you use GPR required: false NUGET_SOURCE: description: NuGet server uri hosting the packages, defaults to https://api.nuget.org diff --git a/index.js b/index.js index c3ca4ff..cf858b0 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,10 @@ const os = require("os"), spawnSync = require("child_process").spawnSync class Action { + + SOURCE_NAME = "default"; + + constructor() { this.projectFile = process.env.INPUT_PROJECT_FILE_PATH this.packageName = process.env.INPUT_PACKAGE_NAME || process.env.PACKAGE_NAME @@ -13,9 +17,22 @@ class Action { this.version = process.env.INPUT_VERSION_STATIC || process.env.VERSION_STATIC this.tagCommit = JSON.parse(process.env.INPUT_TAG_COMMIT || process.env.TAG_COMMIT) this.tagFormat = process.env.INPUT_TAG_FORMAT || process.env.TAG_FORMAT + this.githubUser = process.env.INPUT_GITHUB_USER || process.env.GITHUB_ACTOR this.nugetKey = process.env.INPUT_NUGET_KEY || process.env.NUGET_KEY this.nugetSource = process.env.INPUT_NUGET_SOURCE || process.env.NUGET_SOURCE this.includeSymbols = JSON.parse(process.env.INPUT_INCLUDE_SYMBOLS || process.env.INCLUDE_SYMBOLS) + + + + if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { + this.sourceType = "GPR" + const addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)} --username ${this.githubUser} --password ${this.nugetKey}` + this._executeCommand(addSourceCmd, { encoding: "utf-8" }) + } else { + this.sourceType = "NuGet" + const addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)}` + this._executeCommand(addSourceCmd, { encoding: "utf-8" }) + } } _printErrorAndExit(msg) { @@ -64,8 +81,9 @@ class Action { const packages = fs.readdirSync(".").filter(fn => fn.endsWith("nupkg")) console.log(`Generated Package(s): ${packages.join(", ")}`) - const pushCmd = `dotnet nuget push *.nupkg -s ${this.nugetSource}/v3/index.json -k ${this.nugetKey} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}`, - pushOutput = this._executeCommand(pushCmd, { encoding: "utf-8" }).stdout + const pushCmd = `dotnet nuget push *.nupkg -s ${(this.SOURCE_NAME)} ${this.nugetSource !== "GPR"? `-k ${this.nugetKey}`: ""} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}` + + const pushOutput = this._executeCommand(pushCmd, { encoding: "utf-8" }).stdout console.log(pushOutput) @@ -94,15 +112,22 @@ class Action { console.log(`Package Name: ${this.packageName}`) let requestUrl = "" + let options; //small hack to get package versions from Github Package Registry - if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { + if (this.sourceType === "GPR") { requestUrl = `${this.nugetSource}/download/${this.packageName}/index.json` + options = { + auth:{ + user: this.githubUser, + pass: this.nugetKey + } + } } else { requestUrl = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` } - https.get(requestUrl, res => { + https.get(requestUrl, options, res => { let body = "" if (res.statusCode == 404) From 03ad6a706dc5c79d1665e05fa145b4df5ed36505 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Thu, 3 Dec 2020 21:47:37 +0300 Subject: [PATCH 09/20] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cf858b0..67bccdc 100644 --- a/index.js +++ b/index.js @@ -112,7 +112,7 @@ class Action { console.log(`Package Name: ${this.packageName}`) let requestUrl = "" - let options; + let options = {}; //small hack to get package versions from Github Package Registry if (this.sourceType === "GPR") { From e66cae9a95d01e6def7d3050ae7e9f2a80849113 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 00:36:51 +0300 Subject: [PATCH 10/20] fix --- index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b8046fb..79baf51 100644 --- a/index.js +++ b/index.js @@ -111,26 +111,29 @@ class Action { console.log(`Package Name: ${this.packageName}`) - let requestUrl = "" - let options = {}; + let url = "" + let options = { + method: "GET" + }; //small hack to get package versions from Github Package Registry if (this.sourceType === "GPR") { - requestUrl = `${this.nugetSource}/download/${this.packageName}/index.json` + url = `${this.nugetSource}/download/${this.packageName}/index.json` options = { + method: "GET", auth:{ user: this.githubUser, pass: this.nugetKey } } console.log(`This is GPR, changing url for versioning...`) - console.log(requestUrl) + console.log(url) } else { - requestUrl = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` + url = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` } - https.get(requestUrl, options, res => { + https.get(url, options, (res) => { let body = "" console.log(`Status code: ${res.statusCode}: ${res.statusMessage}`) From 7d7a6a90635374716ad11d436bc27fc276cbd5b1 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 00:40:48 +0300 Subject: [PATCH 11/20] fix --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 79baf51..147c110 100644 --- a/index.js +++ b/index.js @@ -122,8 +122,8 @@ class Action { options = { method: "GET", auth:{ - user: this.githubUser, - pass: this.nugetKey + user: `${this.githubUser}`, + pass: `${this.nugetKey}` } } console.log(`This is GPR, changing url for versioning...`) From 52ef63085e50f52325a2cd6972f67d107e3333f5 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 00:43:05 +0300 Subject: [PATCH 12/20] fix --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 147c110..c69725a 100644 --- a/index.js +++ b/index.js @@ -132,6 +132,9 @@ class Action { url = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` } + console.log("TEST!") + console.log(url); + console.log(options); https.get(url, options, (res) => { let body = "" From c77f422e5b48a00d8a0a7fbe7a8233ac71a55755 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 01:32:34 +0300 Subject: [PATCH 13/20] authentication fix --- index.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index c69725a..43c855d 100644 --- a/index.js +++ b/index.js @@ -112,19 +112,14 @@ class Action { console.log(`Package Name: ${this.packageName}`) let url = "" - let options = { - method: "GET" - }; + let options; //used for authentication //small hack to get package versions from Github Package Registry if (this.sourceType === "GPR") { url = `${this.nugetSource}/download/${this.packageName}/index.json` options = { method: "GET", - auth:{ - user: `${this.githubUser}`, - pass: `${this.nugetKey}` - } + auth:`${this.githubUser}:${this.nugetKey}` } console.log(`This is GPR, changing url for versioning...`) console.log(url) @@ -132,10 +127,6 @@ class Action { url = `${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json` } - console.log("TEST!") - console.log(url); - console.log(options); - https.get(url, options, (res) => { let body = "" From 106bd1ef09271986361344772f44afa89d8a5eb9 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 01:53:05 +0300 Subject: [PATCH 14/20] -- --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 43c855d..c35c683 100644 --- a/index.js +++ b/index.js @@ -23,15 +23,22 @@ class Action { this.includeSymbols = JSON.parse(process.env.INPUT_INCLUDE_SYMBOLS || process.env.INCLUDE_SYMBOLS) this.throwOnVersionExixts = process.env.INPUT_THOW_ERROR_IF_VERSION_EXISTS || process.env.THOW_ERROR_IF_VERSION_EXISTS + let addSourceCmd; if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { this.sourceType = "GPR" - const addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)} --username ${this.githubUser} --password ${this.nugetKey}` - this._executeCommand(addSourceCmd, { encoding: "utf-8" }) + console.log(this._executeCommand("dotnet nuget list source", { encoding: "utf-8" }).stdout) + addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)} --username ${this.githubUser} --password ${this.nugetKey}` } else { this.sourceType = "NuGet" - const addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)}` - this._executeCommand(addSourceCmd, { encoding: "utf-8" }) + addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${this.SOURCE_NAME}` } + this._executeCommand(addSourceCmd, { encoding: "utf-8" }); + const list1 = this._executeCommand("dotnet nuget list source", { encoding: "utf-8" }).stdout; + const enable = this._executeCommand(`dotnet nuget enable source "${this.SOURCE_NAME}"`, { encoding: "utf-8" }).stdout; + const list2 = this._executeCommand("dotnet nuget list source", { encoding: "utf-8" }).stdout; + console.log(list1); + console.log(enable); + console.log(list2); } _printErrorAndExit(msg) { From 85d80479eb53e73478f15787345e7c0bbace9602 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 02:31:37 +0300 Subject: [PATCH 15/20] fix --- index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index c35c683..5c84927 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,11 @@ const os = require("os"), https = require("https"), spawnSync = require("child_process").spawnSync +const SOURCE_NAME = "default"; + class Action { - SOURCE_NAME = "default"; + constructor() { @@ -26,19 +28,17 @@ class Action { let addSourceCmd; if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { this.sourceType = "GPR" - console.log(this._executeCommand("dotnet nuget list source", { encoding: "utf-8" }).stdout) - addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)} --username ${this.githubUser} --password ${this.nugetKey}` + addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey}` } else { this.sourceType = "NuGet" - addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${this.SOURCE_NAME}` + addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${SOURCE_NAME}` } - this._executeCommand(addSourceCmd, { encoding: "utf-8" }); - const list1 = this._executeCommand("dotnet nuget list source", { encoding: "utf-8" }).stdout; - const enable = this._executeCommand(`dotnet nuget enable source "${this.SOURCE_NAME}"`, { encoding: "utf-8" }).stdout; - const list2 = this._executeCommand("dotnet nuget list source", { encoding: "utf-8" }).stdout; + + console.log(this._executeCommand(addSourceCmd, { encoding: "utf-8" }).stdout) + const list1 = this._executeCommand("dotnet nuget list source", { encoding: "utf8" }).stdout; + const enable = this._executeCommand(`dotnet nuget enable source ${SOURCE_NAME}`, { encoding: "utf8" }).stdout; console.log(list1); console.log(enable); - console.log(list2); } _printErrorAndExit(msg) { @@ -87,7 +87,7 @@ class Action { const packages = fs.readdirSync(".").filter(fn => fn.endsWith("nupkg")) console.log(`Generated Package(s): ${packages.join(", ")}`) - const pushCmd = `dotnet nuget push *.nupkg -s ${(this.SOURCE_NAME)} ${this.nugetSource !== "GPR"? `-k ${this.nugetKey}`: ""} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}` + const pushCmd = `dotnet nuget push *.nupkg -s ${(SOURCE_NAME)} ${this.nugetSource !== "GPR"? `-k ${this.nugetKey}`: ""} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}` const pushOutput = this._executeCommand(pushCmd, { encoding: "utf-8" }).stdout From ceceb188983d8097c4b2250ed50129ec81e2d7e6 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 02:35:48 +0300 Subject: [PATCH 16/20] storing password in clear text --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5c84927..fde030d 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ class Action { let addSourceCmd; if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { this.sourceType = "GPR" - addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey}` + addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey} --store-password-in-clear-text` } else { this.sourceType = "NuGet" addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${SOURCE_NAME}` From 684a73c8d2b93624ba4c2407963cf3c7afb4d5e9 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 18:19:07 +0300 Subject: [PATCH 17/20] added restore --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index fde030d..5399312 100644 --- a/index.js +++ b/index.js @@ -80,6 +80,8 @@ class Action { fs.readdirSync(".").filter(fn => /\.s?nupkg$/.test(fn)).forEach(fn => fs.unlinkSync(fn)) + this._executeInProcess(`dotnet restore ${this.projectFile}`) + this._executeInProcess(`dotnet build -c Release ${this.projectFile}`) this._executeInProcess(`dotnet pack ${this.includeSymbols ? "--include-symbols -p:SymbolPackageFormat=snupkg" : ""} --no-build -c Release ${this.projectFile} -o .`) From 7c3d498fb912ac5157f9363cc80aa69b329c7980 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 18:56:01 +0300 Subject: [PATCH 18/20] fixed src --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5399312..d0efff5 100644 --- a/index.js +++ b/index.js @@ -28,10 +28,10 @@ class Action { let addSourceCmd; if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { this.sourceType = "GPR" - addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey} --store-password-in-clear-text` + addSourceCmd = `dotnet nuget add source ${this.nugetSource}/v3/index.json --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey} --store-password-in-clear-text` } else { this.sourceType = "NuGet" - addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name=${SOURCE_NAME}` + addSourceCmd = `dotnet nuget add source ${this.nugetSource}/v3/index.json --name=${SOURCE_NAME}` } console.log(this._executeCommand(addSourceCmd, { encoding: "utf-8" }).stdout) @@ -88,7 +88,7 @@ class Action { const packages = fs.readdirSync(".").filter(fn => fn.endsWith("nupkg")) console.log(`Generated Package(s): ${packages.join(", ")}`) - + const pushCmd = `dotnet nuget push *.nupkg -s ${(SOURCE_NAME)} ${this.nugetSource !== "GPR"? `-k ${this.nugetKey}`: ""} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}` const pushOutput = this._executeCommand(pushCmd, { encoding: "utf-8" }).stdout From 25a8dad7d3af435dd3d83293a777bd39d0aefaed Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 19:02:50 +0300 Subject: [PATCH 19/20] fixed gpr source --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index d0efff5..d54ac53 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ class Action { let addSourceCmd; if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { this.sourceType = "GPR" - addSourceCmd = `dotnet nuget add source ${this.nugetSource}/v3/index.json --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey} --store-password-in-clear-text` + addSourceCmd = `dotnet nuget add source ${this.nugetSource}/index.json --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey} --store-password-in-clear-text` } else { this.sourceType = "NuGet" addSourceCmd = `dotnet nuget add source ${this.nugetSource}/v3/index.json --name=${SOURCE_NAME}` @@ -79,8 +79,6 @@ class Action { console.log(`NuGet Source: ${this.nugetSource}`) fs.readdirSync(".").filter(fn => /\.s?nupkg$/.test(fn)).forEach(fn => fs.unlinkSync(fn)) - - this._executeInProcess(`dotnet restore ${this.projectFile}`) this._executeInProcess(`dotnet build -c Release ${this.projectFile}`) From 9787e1e0816cb3ead0132a5a34aef568ddaf94c4 Mon Sep 17 00:00:00 2001 From: Rebel028 Date: Fri, 4 Dec 2020 19:16:10 +0300 Subject: [PATCH 20/20] fixed package sources handling --- index.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 43c855d..59c0a2a 100644 --- a/index.js +++ b/index.js @@ -4,11 +4,10 @@ const os = require("os"), https = require("https"), spawnSync = require("child_process").spawnSync +const SOURCE_NAME = "default"; + class Action { - SOURCE_NAME = "default"; - - constructor() { this.projectFile = process.env.INPUT_PROJECT_FILE_PATH this.packageName = process.env.INPUT_PACKAGE_NAME || process.env.PACKAGE_NAME @@ -23,15 +22,20 @@ class Action { this.includeSymbols = JSON.parse(process.env.INPUT_INCLUDE_SYMBOLS || process.env.INCLUDE_SYMBOLS) this.throwOnVersionExixts = process.env.INPUT_THOW_ERROR_IF_VERSION_EXISTS || process.env.THOW_ERROR_IF_VERSION_EXISTS + let addSourceCmd; if (this.nugetSource.startsWith(`https://nuget.pkg.github.com/`)) { this.sourceType = "GPR" - const addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)} --username ${this.githubUser} --password ${this.nugetKey}` - this._executeCommand(addSourceCmd, { encoding: "utf-8" }) + addSourceCmd = `dotnet nuget add source ${this.nugetSource}/index.json --name=${(SOURCE_NAME)} --username=${this.githubUser} --password=${this.nugetKey} --store-password-in-clear-text` } else { this.sourceType = "NuGet" - const addSourceCmd = `dotnet nuget add source ${this.nugetSource} --name ${(this.SOURCE_NAME)}` - this._executeCommand(addSourceCmd, { encoding: "utf-8" }) + addSourceCmd = `dotnet nuget add source ${this.nugetSource}/v3/index.json --name=${SOURCE_NAME}` } + + console.log(this._executeCommand(addSourceCmd, { encoding: "utf-8" }).stdout) + const list1 = this._executeCommand("dotnet nuget list source", { encoding: "utf8" }).stdout; + const enable = this._executeCommand(`dotnet nuget enable source ${SOURCE_NAME}`, { encoding: "utf8" }).stdout; + console.log(list1); + console.log(enable); } _printErrorAndExit(msg) { @@ -80,8 +84,8 @@ class Action { const packages = fs.readdirSync(".").filter(fn => fn.endsWith("nupkg")) console.log(`Generated Package(s): ${packages.join(", ")}`) - const pushCmd = `dotnet nuget push *.nupkg -s ${(this.SOURCE_NAME)} ${this.nugetSource !== "GPR"? `-k ${this.nugetKey}`: ""} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}` - + const pushCmd = `dotnet nuget push *.nupkg -s ${(SOURCE_NAME)} ${this.nugetSource !== "GPR"? `-k ${this.nugetKey}`: ""} --skip-duplicate ${!this.includeSymbols ? "-n 1" : ""}` + const pushOutput = this._executeCommand(pushCmd, { encoding: "utf-8" }).stdout console.log(pushOutput)