Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start preparing build-runtime job #127

Merged
merged 49 commits into from
Jun 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2addf30
Start moving things around
girazoki Jun 13, 2023
856d0eb
Dancebox introduction
girazoki Jun 13, 2023
50ac383
few cosmetic changesd
girazoki Jun 14, 2023
e08fa26
start preparing build-runtime job
girazoki Jun 19, 2023
ee42c02
start testing
girazoki Jun 19, 2023
af3afba
Add job
girazoki Jun 19, 2023
0e78b6a
modify rust toolchain to see if that passes
girazoki Jun 19, 2023
6a30336
Revert "modify rust toolchain to see if that passes"
girazoki Jun 19, 2023
ca74e20
Merge remote-tracking branch 'origin/master' into girazoki-runtime-jobs
girazoki Jun 19, 2023
c15e675
fix
girazoki Jun 19, 2023
fbc0ab1
fmt
girazoki Jun 19, 2023
558a13a
tools to publish wasm
girazoki Jun 19, 2023
4bc7ba8
Merge remote-tracking branch 'origin/master' into girazoki-dancebox-i…
girazoki Jun 19, 2023
5b7a417
Merge remote-tracking branch 'origin/girazoki-dancebox-introduction' …
girazoki Jun 19, 2023
87d8a7a
remove publish runtime
girazoki Jun 19, 2023
35c1c36
Merge remote-tracking branch 'origin/girazoki-dancebox-introduction' …
girazoki Jun 19, 2023
30aa8a4
modify tools
girazoki Jun 19, 2023
5c34ca8
trigger on push
girazoki Jun 19, 2023
8d134df
fmt
girazoki Jun 19, 2023
3fc4826
tsconfig
girazoki Jun 19, 2023
0e6b022
github-utils
girazoki Jun 19, 2023
577c91c
wip
girazoki Jun 19, 2023
9010fce
try-with-tags
girazoki Jun 20, 2023
7d02e19
revert and put it in correct place
girazoki Jun 20, 2023
081f89f
use new tag
girazoki Jun 20, 2023
f23dd44
Merge remote-tracking branch 'origin/master' into girazoki-dancebox-i…
girazoki Jun 20, 2023
3715c36
build runtime remove
girazoki Jun 20, 2023
0954ad8
dummycollator for full node
girazoki Jun 20, 2023
319ff62
Merge remote-tracking branch 'origin/girazoki-dancebox-introduction' …
girazoki Jun 20, 2023
7919413
add back build runtime
girazoki Jun 20, 2023
0d66e30
dancebox for orchestrator
girazoki Jun 20, 2023
859192d
revert back
girazoki Jun 20, 2023
bcbf86e
get back to dispatch flow
girazoki Jun 21, 2023
a832dce
npm for pnpm
girazoki Jun 21, 2023
1537e23
trigger to see if it works
girazoki Jun 21, 2023
c88f3e3
Revert "npm for pnpm"
girazoki Jun 21, 2023
751421b
Revert "Revert "npm for pnpm""
girazoki Jun 21, 2023
4129cc2
Revert "Revert "Revert "npm for pnpm"""
girazoki Jun 21, 2023
c6b4ce1
workflow dispatch
girazoki Jun 21, 2023
c27f6b7
fail job if docker image for sr-tool is not found
girazoki Jun 22, 2023
a475dc9
Comments on actions
girazoki Jun 22, 2023
4995b75
Merge remote-tracking branch 'origin/master' into girazoki-runtime-jobs
girazoki Jun 22, 2023
9fff59f
trigger on push
girazoki Jun 22, 2023
51d867b
rename
girazoki Jun 22, 2023
ad70101
Update cargo lock
girazoki Jun 22, 2023
5997334
Revert "trigger on push"
girazoki Jun 22, 2023
6401985
Merge remote-tracking branch 'origin/master' into girazoki-runtime-jobs
girazoki Jun 22, 2023
76bed86
remove pnpm
girazoki Jun 22, 2023
87169b6
fix yml
girazoki Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
github-utils
  • Loading branch information
girazoki committed Jun 19, 2023
commit 0e6b022c524a2d2313fe06368264d981e8b92527
111 changes: 111 additions & 0 deletions tools/github/github-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { Octokit } from "octokit";
import { execSync } from "child_process";

// Typescript 4 will support it natively, but not yet :(
type Await<T> = T extends PromiseLike<infer U> ? U : T;
type Commits = Await<ReturnType<Octokit["rest"]["repos"]["compareCommits"]>>["data"]["commits"];

export function getCompareLink(packageName: string, previousTag: string, newTag: string) {
const previousPackage = execSync(
`git show ${previousTag}:../Cargo.lock | grep ${packageName}? | head -1 | grep -o '".*"'`
).toString();
const previousCommit = /#([0-9a-f]*)/g.exec(previousPackage)[1].slice(0, 8);
const previousRepo = /(https:\/\/.*)\?/g.exec(previousPackage)[1];

const newPackage = execSync(
`git show ${newTag}:../Cargo.lock | grep ${packageName}? | head -1 | grep -o '".*"'`
).toString();
const newCommit = /#([0-9a-f]*)/g.exec(newPackage)[1].slice(0, 8);
const newRepo = /(https:\/\/.*)\?/g.exec(newPackage)[1];
const newRepoOrganization = /github.com\/([^\/]*)/g.exec(newRepo)[1];

const diffLink =
previousRepo !== newRepo
? `${previousRepo}/compare/${previousCommit}...${newRepoOrganization}:${newCommit}`
: `${previousRepo}/compare/${previousCommit}...${newCommit}`;

return diffLink;
}

export async function getCommitAndLabels(
octokit: Octokit,
owner: string,
repo: string,
previousTag: string,
newTag: string
): Promise<{ prByLabels: any; commits: any[] }> {
let commits: Commits = [];
let more = true;
let page = 0;
while (more) {
const compare = await octokit.rest.repos.compareCommitsWithBasehead({
owner,
repo,
basehead: previousTag + "..." + newTag,
per_page: 200,
page,
});
commits = commits.concat(compare.data.commits);
more = compare.data.commits.length == 200;
page++;
}

// Determine commits to exclude
// - commits reverted in the same range
const excludedCommits: number[] = [];
const revertedCommits: number[] = [];
for (let i = commits.length - 1; i >= 0; i--) {
const commitMessageFirstLine = commits[i].commit.message.split("\n")[0].trim();

if (revertedCommits[commitMessageFirstLine] != null) {
excludedCommits.push(i);
excludedCommits.push(revertedCommits[commitMessageFirstLine]);
} else {
const foundRevertedCommitName = commitMessageFirstLine.match(/Revert \"(.*)\"/);
if (foundRevertedCommitName?.length > 0) {
revertedCommits[foundRevertedCommitName[1]] = i;
}
}
}

const prByLabels = {};
for (let i = 0; i < commits.length; i++) {
const commitMessageFirstLine = commits[i].commit.message.split("\n")[0].trim();
if (!excludedCommits.includes(i)) {
const foundPrsNumbers = commitMessageFirstLine.match(/\(#([0-9]+)\)$/);
if (foundPrsNumbers && foundPrsNumbers.length > 1) {
// This will check current repo and if the PR is not found, will try the official repo
const repos = [
{ owner, repo },
{ owner: "moondance-labs", repo: "tanssi" },
];
for (const { owner, repo } of repos) {
try {
const pr = await octokit.rest.pulls.get({
owner,
repo,
pull_number: parseInt(foundPrsNumbers[1]),
});

if (pr.data.labels && pr.data.labels.length > 0) {
for (const label of pr.data.labels) {
prByLabels[label.name] = prByLabels[label.name] || [];
prByLabels[label.name].push(pr.data);
}
} else {
prByLabels[""] = prByLabels[""] || [];
prByLabels[""].push(pr);
}
break;
} catch (e) {
// PR not found... let's try the other repo
}
}
}
}
}
return {
prByLabels,
commits,
};
}