Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

PR for a feature described in issue #43 #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -61,4 +65,4 @@ runs:

branding:
icon: package
color: blue
color: blue
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = JSON.parse(process.env.INPUT_THOW_ERROR_IF_VERSION_EXISTS || process.env.THOW_ERROR_IF_VERSION_EXISTS)
}

_printErrorAndExit(msg) {
Expand Down Expand Up @@ -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 => {
Expand Down