Skip to content

Commit

Permalink
Switch back to https
Browse files Browse the repository at this point in the history
Seems like Node v16 does not support this just yet, and v18 is not avaiable in JavaScript GitHub Actions
  • Loading branch information
GerardSmit committed Mar 25, 2023
1 parent 16fc356 commit 7bf92f6
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const os = require("os"),
fs = require("fs"),
path = require("path"),
https = require("https"),
spawnSync = require("child_process").spawnSync

class Action {
Expand Down Expand Up @@ -102,7 +103,7 @@ class Action {
this._tagCommit(version)
}

async _checkForUpdate() {
_checkForUpdate() {
if (!this.packageName) {
this.packageName = path.basename(this.projectFile).split(".").slice(0, -1).join(".")
}
Expand All @@ -112,13 +113,32 @@ class Action {
let url = `${this.nugetSource}/v3-flatcontainer/${this.packageName.toLowerCase()}/index.json`
console.log(`Getting versions from ${url}`)

const response = await fetch(url);
const existingVersions = await response.json();

console.log(`Versions retrieved: ${existingVersions.versions}`)

if (existingVersions.versions.indexOf(this.version) < 0)
this._pushPackage(this.version, this.packageName)
return new Promise((resolve, reject) => {
https.get(url, res => {
let body = ""

if (res.statusCode == 404) {
console.log('404 response, assuming new package')
this._pushPackage(this.version, this.packageName)
resolve()
} else if (res.statusCode == 200) {
res.setEncoding("utf8")
res.on("data", chunk => body += chunk)
res.on("end", () => {
const existingVersions = JSON.parse(body)
console.log(`Versions retrieved: ${existingVersions.versions}`)
if (existingVersions.versions.indexOf(this.version) < 0)
this._pushPackage(this.version, this.packageName)

resolve()
})
} else {
reject(`invalid status code ${res.statusCode}`)
}
}).on("error", e => {
reject(`error retrieving versions: ${e.message}`)
})
});
}

async run() {
Expand Down Expand Up @@ -168,4 +188,4 @@ async function main() {
}
}

main()
main()

0 comments on commit 7bf92f6

Please sign in to comment.