finalize repo

This commit is contained in:
Tyler Wilding
2021-09-27 21:45:01 -04:00
parent 54e454d198
commit bbd9bbfa3c
17 changed files with 35490 additions and 3 deletions

2
scripts/build-metadata/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
package-lock.json

View File

@@ -0,0 +1,126 @@
// Enumerate through a collection of builds and aggregate the following:
// - file path to build
// - version number
// - commit author (if git)
// - commit full sha (if git)
// - commit message (if git)
// - associated PR (if git)
// - commit date (if git)
// This is slow as hell because it's linear, but theres no reason to be fancy on a one off script imo
import { Octokit } from "@octokit/rest";
import { throttling } from "@octokit/plugin-throttling";
import { retry } from "@octokit/plugin-retry";
Octokit.plugin(throttling);
Octokit.plugin(retry);
import chalk from 'chalk';
import dotenv from 'dotenv'
dotenv.config();
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
userAgent: 'PCSX2/archive',
log: {
debug: () => { },
info: () => { },
warn: console.warn,
error: console.error
},
throttle: {
onRateLimit: (retryAfter, options) => {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);
// Retry twice after hitting a rate limit error, then give up
if (options.request.retryCount <= 2) {
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
},
}
})
const BUILD_DIR = `./../../builds/1.7 dev cycle/`
// Find all builds
import * as fs from 'fs';
let dirCont = fs.readdirSync(BUILD_DIR);
let files = dirCont.filter(function (elm) { return elm.match(/.*\.(7z?)/ig); });
console.log(chalk.blue(`Found ${files.length} builds. One of which is - ${files[0]}`));
let failures = [];
let builds = [];
await processBuilds(files);
// Save JSON to a file
fs.writeFileSync('out/failures.json', JSON.stringify(failures, null, 2));
fs.writeFileSync('out/build-metadata.json', JSON.stringify(builds, null, 2));
async function processBuilds(buildList) {
for (var i = 0; i < buildList.length; i++) {
console.log(chalk.yellow(`[${i+1}/${buildList.length}]`) + ` Processing Builds`);
let fileName = buildList[i];
let buildProps = fileName.split("-");
let semverComponents = buildProps[1].substring(1).split(".");
let semverMajor = semverComponents[0];
let semverMinor = semverComponents[1];
let patchVer = buildProps[3];
let shortHash = buildProps[4].substring(1);
try {
const { data: commit } = await octokit.rest.repos.getCommit({
owner: "PCSX2",
repo: "pcsx2",
ref: shortHash,
});
const { data: associatedPulls } = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
owner: "PCSX2",
repo: "pcsx2",
commit_sha: commit.sha,
});
let associatedPRs = [];
for (var j = 0; j < associatedPulls.length; j++) {
associatedPRs.push({
title: associatedPulls[j].title,
url: associatedPulls[j].html_url
});
}
builds.push({
fileName: fileName,
versionNumber: `v${semverMajor}.${semverMinor}.${patchVer}`,
commitAuthor: commit.commit.author.name,
commitFullSha: commit.sha,
commitMessage: commit.commit.message,
commitAuthoredDate: commit.commit.author.date,
commitCommitterDate: commit.commit.committer.date,
associatedPullRequests: associatedPRs
})
} catch (e) {
console.log(chalk.red(`- Failed to Retrieve Info - ${e}`));
failures.push(fileName + " " + e);
builds.push({
fileName: fileName,
versionNumber: `v${semverMajor}.${semverMinor}.${patchVer}`,
commitAuthor: null,
commitFullSha: null,
commitMessage: null,
commitAuthoredDate: null,
commitCommitterDate: null,
associatedPullRequests: null
})
}
}
}

View File

@@ -0,0 +1,19 @@
{
"name": "build-metadata",
"version": "1.0.0",
"description": "",
"main": "main.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^3.5.2",
"@octokit/rest": "^18.11.1",
"chalk": "^4.1.2",
"dotenv": "^10.0.0"
}
}

2
scripts/build-readmes/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
package-lock.json

View File

@@ -0,0 +1,29 @@
// Enumerate through build metadata generated from the other script
// Which has associated each file with all the information needed to construct a useful description
// This is slow as hell because it's linear, but theres no reason to be fancy on a one off script imo
const METADATA_FILE = `./../../metadata/1.7/build-metadata.json`
import * as fs from 'fs';
let markdown = "";
let buildMetadata = JSON.parse(fs.readFileSync(METADATA_FILE));
let patchNums = []
for (var i = 0; i < buildMetadata.length; i++) {
let metadata = buildMetadata[i];
let semverProps = metadata.versionNumber.substring(1).split(".");
let patchNum = semverProps[2];
patchNums.push(parseInt(patchNum));
}
patchNums.sort((a, b) => b - a);
for (var i = 0; i < patchNums.length; i++) {
markdown += `- [v1.7.${patchNums[i]}](https://github.com/PCSX2/archive/releases/tag/v1.7.${patchNums[i]})\n`;
}
fs.writeFileSync('out/markdown.md', markdown);

View File

@@ -0,0 +1,19 @@
{
"name": "draft-releases",
"version": "1.0.0",
"description": "",
"main": "main.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^3.5.2",
"@octokit/rest": "^18.11.1",
"chalk": "^4.1.2",
"dotenv": "^10.0.0"
}
}

2
scripts/draft-releases/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
package-lock.json

View File

@@ -0,0 +1,107 @@
// Enumerate through build metadata generated from the other script
// Which has associated each file with all the information needed to construct a useful description
// This is slow as hell because it's linear, but theres no reason to be fancy on a one off script imo
import { Octokit } from "@octokit/rest";
import { throttling } from "@octokit/plugin-throttling";
import { retry } from "@octokit/plugin-retry";
Octokit.plugin(throttling);
Octokit.plugin(retry);
import chalk from 'chalk';
import dotenv from 'dotenv'
dotenv.config();
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
userAgent: 'PCSX2/archive',
log: {
debug: () => { },
info: () => { },
warn: console.warn,
error: console.error
},
throttle: {
onRateLimit: (retryAfter, options) => {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);
// Retry twice after hitting a rate limit error, then give up
if (options.request.retryCount <= 2) {
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
},
}
})
const BUILD_DIR = `./../../builds/1.7 dev cycle/`
const METADATA_FILE = `./../../metadata/1.7/build-metadata.json`
import * as fs from 'fs';
import * as path from 'path';
let buildMetadata = JSON.parse(fs.readFileSync(METADATA_FILE));
console.log(chalk.blue(`Found ${buildMetadata.length} build metadata entries. The first of which is: \n${JSON.stringify(buildMetadata[0], null, 2)}`));
let failures = [];
for (var i = 0; i < buildMetadata.length; i++) {
console.log(chalk.yellow(`[${i+1}/${buildMetadata.length}]`) + ` Processing Metadata and Uploading Build`);
let metadata = buildMetadata[i];
try {
var releaseBody = "This release corresponds to a commit that no longer exists.";
if (metadata.commitFullSha != null) {
releaseBody = `### Commit Information\n\n- **Author** - ${metadata.commitAuthor}\n- **Full SHA** - [${metadata.commitFullSha}](https://github.com/PCSX2/pcsx2/commit/${metadata.commitFullSha})\n- **Authored Date** - ${metadata.commitAuthoredDate}\n- **Committed Date** - ${metadata.commitCommitterDate}\n- **Commit Message**:\n\`\`\`\n${metadata.commitMessage}\n\`\`\`\n\n### Associated PRs\n\n`;
if (metadata.associatedPullRequests.length == 0) {
releaseBody += `- No Associated Pull Requests Found!`
} else {
for(var j = 0; j < metadata.associatedPullRequests.length; j++) {
var pr = metadata.associatedPullRequests[j];
var prNum = pr.url.split("/").slice(-1)[0];
releaseBody += `- [${pr.title} - #${prNum}](${pr.url})`
}
}
releaseBody += "\n";
}
const { data: release } = await octokit.rest.repos.createRelease({
owner: "PCSX2",
repo: "archive",
tag_name: metadata.versionNumber,
body: releaseBody,
prerelease: true
});
var releaseId = release.id;
var buildPath = path.join(BUILD_DIR, metadata.fileName);
var assetBytes = fs.readFileSync(buildPath, null);
const { data: uploadAsset } = await octokit.rest.repos.uploadReleaseAsset({
owner: "PCSX2",
repo: "archive",
release_id: releaseId,
name: metadata.fileName,
data: assetBytes,
});
// Add some delay
await new Promise(resolve => setTimeout(resolve, 2500));
} catch (e) {
console.log(chalk.red(`- Failed to Create Release - ${e}`));
failures.push(metadata.fileName + " " + e);
}
}
// Save JSON to a file
fs.writeFileSync('out/failures.json', JSON.stringify(failures, null, 2));

View File

@@ -0,0 +1,19 @@
{
"name": "draft-releases",
"version": "1.0.0",
"description": "",
"main": "main.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^3.5.2",
"@octokit/rest": "^18.11.1",
"chalk": "^4.1.2",
"dotenv": "^10.0.0"
}
}