Website: fix failing GitHub workflows (#9285)

Changes:
- Updated the `build-static-content` script to use a GitHub API token
for requests if one is provided e.g., `sails run build-static-content
--githubAccessToken="foo"`
- Updated the `build-for-prod` npm script to run the
`build-static-content` script with a variable named `BUILD_SCRIPT_ARGS`.
- Updated the "Deploy Fleet website" and "Test Fleet website" workflows
to run the `build-for-prod` script with a GitHub API token
. .

Co-authored-by: Mike McNeil <mikermcneil@users.noreply.github.com>
This commit is contained in:
Eric
2023-01-11 13:31:20 -06:00
committed by GitHub
co-authored by Mike McNeil
parent c1e54397d1
commit 47d43d5307
4 changed files with 16 additions and 5 deletions
+13 -2
View File
@@ -10,10 +10,11 @@ module.exports = {
inputs: {
dry: { type: 'boolean', description: 'Whether to make this a dry run. (.sailsrc file will not be overwritten. HTML files will not be generated.)' },
skipGithubRequests: { type: 'boolean', description: 'Whether to minimize requests to the GitHub API which usually can be skipped during local development, such as requests used for fetching GitHub avatar URLs'},
githubAccessToken: { type: 'string', description: 'If provided, A GitHub token will be used to authenticate requests to the GitHub API'},
},
fn: async function ({ dry, skipGithubRequests }) {
fn: async function ({ dry, skipGithubRequests, githubAccessToken }) {
let path = require('path');
let YAML = require('yaml');
@@ -113,10 +114,20 @@ module.exports = {
query.contributors = contributorProfiles;
}
} else {// If the --skipGithubRequests flag was not provided, we'll query GitHub's API to get additional information about each contributor.
let baseHeadersForGithubRequests = {
'User-Agent': 'Fleet-Standard-Query-Library',
'Accept': 'application/vnd.github.v3+json',
};
if(githubAccessToken) {
// If a GitHub access token was provided, add it to the baseHeadersForGithubRequests object.
baseHeadersForGithubRequests['Authorization'] = `token ${githubAccessToken}`;
}
await sails.helpers.flow.simultaneouslyForEach(githubUsernames, async(username)=>{
githubDataByUsername[username] = await sails.helpers.http.get.with({
url: 'https://api.github.com/users/' + encodeURIComponent(username),
headers: { 'User-Agent': 'Fleet-Standard-Query-Library', Accept: 'application/vnd.github.v3+json' }
headers: baseHeadersForGithubRequests,
}).catch((err)=>{// If the above GET requests return a non 200 response we'll look for signs that the user has hit their GitHub API rate limit.
if (err.raw.statusCode === 403 && err.raw.headers['x-ratelimit-remaining'] === '0') {// If the user has reached their GitHub API rate limit, we'll throw an error that suggest they run this script with the `--skipGithubRequests` flag.
throw new Error('GitHub API rate limit exceeded. If you\'re running this script in a development environment, use the `--skipGithubRequests` flag to skip querying the GitHub API. See full error for more details:\n'+err);