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

Commit 48ea7dd

Browse files
author
Rohith Reddy
committed
fix #4 to fail on nuget errors & fix git tag check
1 parent 7c32ffb commit 48ea7dd

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function run() {
66
// check fetch-depth
77
const commitCount = parseInt(runCap("git rev-list --count HEAD"))
88
if (commitCount < 2) {
9-
failure("😤 commit history needs to be >= 2")
9+
failed("😤 git commit history must be >= 2")
1010
return
1111
}
1212

@@ -16,7 +16,7 @@ function run() {
1616
projFiles = readdirSync(projDir).filter(f => f.endsWith(".csproj"))
1717

1818
if (projFiles.length === 0) {
19-
failure("😭 project not found")
19+
failed("😭 project not found")
2020
return
2121
}
2222

@@ -28,21 +28,21 @@ function run() {
2828
isVersionChanged = versionRegex.test(gitDiff)
2929

3030
if (!isVersionChanged) {
31-
console.log(`🥱 no version change in ${projName}`)
31+
console.log(`🥱 no version change for ${projName}`)
3232
return
3333
}
3434

35-
console.log(`👍 found version change in ${projName}`)
35+
console.log(`👍 found a new version for ${projName}`)
3636

3737
// create tag
3838
const projContents = readFileSync(projPath, { encoding: "utf-8" }),
3939
newVersion = versionRegex.exec(projContents)[1],
4040
tagFormat = process.env.INPUT_TAG_FORMAT,
4141
tag = tagFormat.replace("*", newVersion),
42-
istagPresent = runCap("git tag -l --contains").indexOf(tag) >= 0
42+
istagPresent = runCap(`git ls-remote --tags origin ${tag}`).indexOf(tag) >= 0
4343

4444
if (istagPresent) {
45-
console.log(`😢 tag named ${newVersion} already exists`)
45+
console.log(`##[warning]😢 tag ${newVersion} already exists`)
4646
return
4747
}
4848

@@ -53,17 +53,21 @@ function run() {
5353
const nugetKey = process.env.INPUT_NUGET_KEY
5454

5555
if (!nugetKey) {
56-
console.log(`😢 no nuget_key input supplied`)
56+
console.log(`##[warning]😢 nuget_key not found`)
5757
return
5858
}
5959

6060
if (!runCap("dotnet --version")) {
61-
failure("😭 dotnet not found")
61+
failed("😭 dotnet not found")
6262
return
6363
}
6464

6565
runProc(`dotnet pack -c Release ${projPath} -o .`)
66-
runProc(`dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${nugetKey}`)
66+
const out = runCap(`dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${nugetKey}`)
67+
const errorRegex = /(error: Response status code does not indicate success.*)/
68+
69+
if (errorRegex.test(out))
70+
failed(`😭 ${errorRegex.exec(out)[1]}`)
6771
}
6872

6973
function runCap(cmd) { return runCmd(cmd, { encoding: "utf-8" }).stdout }
@@ -75,9 +79,9 @@ function runCmd(cmd, options) {
7579
return spawnSync(tool, args, options)
7680
}
7781

78-
function failure(msg) {
82+
function failed(msg) {
7983
process.exitCode = 1
80-
console.log(msg)
84+
console.log(`##[error]${msg}`)
8185
}
8286

8387
run()

0 commit comments

Comments
 (0)