Try to prevent 403 when accessing the GitHub API (#168)

* Repeat request on error (while logging it)

* Test one change at a time

* Conditionally authorize requests

This seems to affect Windows builds, so might not be the best solution,
but we're trying to isolate the issue to move forward

* Act on CI results

* Ease consumption via a JSON.parse wrapper

We still throw the error, but in a more controlled manner

* Act on CI results
This commit is contained in:
Paulo F. Oliveira
2023-01-04 07:27:57 +00:00
committed by GitHub
parent 2d314bc413
commit 37ac1c5116
5 changed files with 82 additions and 53 deletions
+4 -1
View File
@@ -9,6 +9,9 @@ on:
branches:
- main
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
jobs:
check_integrity:
name: Expected local npm actions
@@ -28,7 +31,7 @@ jobs:
- run: npm run yamllint
- run: npm run jslint
- name: Check if build left artifacts
run: git diff --exit-code
run: git diff --exit-code --ignore-space-at-eol
unit_tests_ubuntu:
name: Unit tests (Ubuntu)
+3
View File
@@ -9,6 +9,9 @@ on:
branches:
- main
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
jobs:
integration_test:
name: >
+3
View File
@@ -9,6 +9,9 @@ on:
branches:
- main
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
jobs:
integration_test:
name: >
+21 -11
View File
@@ -7440,7 +7440,7 @@ async function getOTPVersions(osVersion) {
})
} else if (process.platform === 'win32') {
otpVersionsListings.forEach((otpVersionsListing) => {
JSON.parse(otpVersionsListing)
jsonParse(otpVersionsListing)
.map((x) => x.assets)
.flat()
.filter((x) => x.name.match(/^otp_win64_.*.exe$/))
@@ -7487,7 +7487,7 @@ async function getGleamVersions() {
)
const gleamVersionsListing = []
resultJSONs.forEach((resultJSON) => {
JSON.parse(resultJSON)
jsonParse(resultJSON)
.map((x) => x.tag_name)
.sort()
.forEach((v) => gleamVersionsListing.push(v))
@@ -7502,7 +7502,7 @@ async function getRebar3Versions() {
)
const rebar3VersionsListing = []
resultJSONs.forEach((resultJSON) => {
JSON.parse(resultJSON)
jsonParse(resultJSON)
.map((x) => x.tag_name)
.sort()
.forEach((v) => rebar3VersionsListing.push(v))
@@ -7609,16 +7609,17 @@ async function get(url0, pageIdxs) {
function getPage(pageIdx) {
return new Promise((resolve, reject) => {
const url = new URL(url0)
const headers = {
'user-agent': 'setup-beam',
}
if (process.env.GITHUB_TOKEN) {
headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}`
}
if (pageIdx !== null) {
url.searchParams.append('page', pageIdx)
}
https
.get(
url,
{
headers: { 'user-agent': 'setup-beam' },
},
(res) => {
.get(url, { headers }, (res) => {
let data = ''
res.on('data', (chunk) => {
data += chunk
@@ -7634,8 +7635,7 @@ async function get(url0, pageIdxs) {
resolve(data)
}
})
},
)
})
.on('error', (err) => {
reject(err)
})
@@ -7716,6 +7716,16 @@ function parseVersionFile(versionFilePath0) {
return appVersions
}
function jsonParse(maybeJson) {
try {
return JSON.parse(maybeJson)
} catch (exc) {
throw new Error(
`Got an exception when trying to parse non-JSON ${maybeJson}: ${exc}`,
)
}
}
module.exports = {
getOTPVersion,
getElixirVersion,
+21 -11
View File
@@ -247,7 +247,7 @@ async function getOTPVersions(osVersion) {
})
} else if (process.platform === 'win32') {
otpVersionsListings.forEach((otpVersionsListing) => {
JSON.parse(otpVersionsListing)
jsonParse(otpVersionsListing)
.map((x) => x.assets)
.flat()
.filter((x) => x.name.match(/^otp_win64_.*.exe$/))
@@ -294,7 +294,7 @@ async function getGleamVersions() {
)
const gleamVersionsListing = []
resultJSONs.forEach((resultJSON) => {
JSON.parse(resultJSON)
jsonParse(resultJSON)
.map((x) => x.tag_name)
.sort()
.forEach((v) => gleamVersionsListing.push(v))
@@ -309,7 +309,7 @@ async function getRebar3Versions() {
)
const rebar3VersionsListing = []
resultJSONs.forEach((resultJSON) => {
JSON.parse(resultJSON)
jsonParse(resultJSON)
.map((x) => x.tag_name)
.sort()
.forEach((v) => rebar3VersionsListing.push(v))
@@ -416,16 +416,17 @@ async function get(url0, pageIdxs) {
function getPage(pageIdx) {
return new Promise((resolve, reject) => {
const url = new URL(url0)
const headers = {
'user-agent': 'setup-beam',
}
if (process.env.GITHUB_TOKEN) {
headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}`
}
if (pageIdx !== null) {
url.searchParams.append('page', pageIdx)
}
https
.get(
url,
{
headers: { 'user-agent': 'setup-beam' },
},
(res) => {
.get(url, { headers }, (res) => {
let data = ''
res.on('data', (chunk) => {
data += chunk
@@ -441,8 +442,7 @@ async function get(url0, pageIdxs) {
resolve(data)
}
})
},
)
})
.on('error', (err) => {
reject(err)
})
@@ -523,6 +523,16 @@ function parseVersionFile(versionFilePath0) {
return appVersions
}
function jsonParse(maybeJson) {
try {
return JSON.parse(maybeJson)
} catch (exc) {
throw new Error(
`Got an exception when trying to parse non-JSON ${maybeJson}: ${exc}`,
)
}
}
module.exports = {
getOTPVersion,
getElixirVersion,