From 4ed6beee6ff8502f61d6b7513accc49fccf5c1be Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Tue, 20 Oct 2020 13:45:09 +0300 Subject: [PATCH 1/4] added THOW_ERROR_IF_VERSION_EXISTS flag --- action.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9dc71b2..71c0ee9 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: Flag to toggle pushing symbols along with nuget package to the server, disabled by default required: false default: false + THOW_ERROR_IF_VERSION_EXISTS: + description: Flag to throw an error when trying to publish an existing version of a package + required: false + default: false outputs: VERSION: @@ -61,4 +65,4 @@ runs: branding: icon: package - color: blue \ No newline at end of file + color: blue From e66e1e551090186abfb2b990a5d14fa89912bea6 Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:08:38 +0300 Subject: [PATCH 2/4] throwing error if trying to push existing version (optional) --- index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index db47a6d..f123d67 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ class Action { 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) + this.throwOnVersionExixts = process.env.INPUT_THOW_ERROR_IF_VERSION_EXISTS || process.env.THOW_ERROR_IF_VERSION_EXISTS } _printErrorAndExit(msg) { @@ -97,16 +98,29 @@ class Action { https.get(`${this.nugetSource}/v3-flatcontainer/${this.packageName}/index.json`, res => { let body = "" - if (res.statusCode == 404) + if (res.statusCode == 404){ + console.log(`No packages found. Pushing initial version...`) this._pushPackage(this.version, this.packageName) + } if (res.statusCode == 200) { res.setEncoding("utf8") res.on("data", chunk => body += chunk) res.on("end", () => { const existingVersions = JSON.parse(body) - if (existingVersions.versions.indexOf(this.version) < 0) + if (existingVersions.versions.indexOf(this.version) < 0) { + console.log(`This version is new, pushing...`) this._pushPackage(this.version, this.packageName) + } + else + { + let errorMsg = `Version ${this.version} already exists`; + console.log(errorMsg) + + if(this.throwOnVersionExixts) { + this._printErrorAndExit(`error: ${errorMsg}`) + } + } }) } }).on("error", e => { From fd09e91d0a81aa9b3544ac3b844192fad0081623 Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:10:39 +0300 Subject: [PATCH 3/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7f46d67..2992a1d 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ jobs: # Flag to toggle pushing symbols along with nuget package to the server, disabled by default # INCLUDE_SYMBOLS: false + + # Flag to throw an error when trying to publish an existing version of a package + # THOW_ERROR_IF_VERSION_EXISTS: false ``` - Project gets published only if there's a `NUGET_KEY` configured in the repository @@ -74,6 +77,7 @@ TAG_FORMAT | `v*` | Format of the git tag, `[*]` gets replaced with actual versi NUGET_KEY | | API key to authenticate with NuGet server 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 +THOW_ERROR_IF_VERSION_EXISTS | `false` | Flag to throw an error when trying to publish an existing version of a package ## Outputs From 25ac019ecb0d3f7a2746a81ee12a8aa525cc0d8e Mon Sep 17 00:00:00 2001 From: Anton <27502053+Rebel028@users.noreply.github.com> Date: Thu, 20 May 2021 16:45:51 +0300 Subject: [PATCH 4/4] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f123d67..dd85690 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ class Action { 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) - this.throwOnVersionExixts = process.env.INPUT_THOW_ERROR_IF_VERSION_EXISTS || process.env.THOW_ERROR_IF_VERSION_EXISTS + this.throwOnVersionExixts = JSON.parse(process.env.INPUT_THOW_ERROR_IF_VERSION_EXISTS || process.env.THOW_ERROR_IF_VERSION_EXISTS) } _printErrorAndExit(msg) {