Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@
patches: false
purpose: "node"

- repository_org: "AssetMantle"
repository_name: "node"
project_name: "assetmantle"
architecture: "x86_64"
binaries:
- "mantleNode"
builder: "go"
builder_version: "1.24.3"
cpu: "generic"
patches: false
purpose: "node"

# TOOLS
- repository: "tmkms"
project_name: "tmkms"
Expand Down
13 changes: 13 additions & 0 deletions scripts/assetmantle/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

cd "${DEPOT_PROJECT_NAME}"
mkdir bin

CGO_ENABLED=0 make LEDGER_ENABLED=false all

build_binaries="$(deno run --allow-read --allow-env ../utils/binaries.ts)"

echo "${build_binaries}" | jq -r 'to_entries[] | "\(.key) \(.value)"' | while read -r binary_name path; do
mv -v "build/${binary_name}" "${path}"
done
39 changes: 35 additions & 4 deletions utils/binaries.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { getConfig } from "./config.ts";
import { DepotProject } from "./types.ts";

import { DEPOT_CONFIG_PATH, DEPOT_REPO_NAME, GITHUB_WORKSPACE } from "./config.ts";
import { DEPOT_CONFIG_PATH, DEPOT_REPO_NAME, DEPOT_REPOSITORY_ORG, GITHUB_WORKSPACE } from "./config.ts";

export const getBinaries = async (repositoryName: string): Promise<Record<string, string>> => {
const config = await getConfig(DEPOT_CONFIG_PATH) as DepotProject[];
const project = config.find((project) => project.repository === repositoryName);

let project: DepotProject | undefined;

if (repositoryName.includes('/')) {
const [org, repo] = repositoryName.split('/');
project = config.find((project) =>
project.repository_org === org && project.repository_name === repo
);
}

// LEGACY
if (!project) {
project = config.find((project) => project.repository === repositoryName);
}

if (!project) {
throw new Error(`Project ${repositoryName} not found in config file`);
Expand All @@ -25,7 +38,19 @@ export const getBinaries = async (repositoryName: string): Promise<Record<string

export const getDockerBinaries = async (repositoryName: string): Promise<string> => {
const config = await getConfig(DEPOT_CONFIG_PATH) as DepotProject[];
const project = config.find((project) => project.repository === repositoryName);

let project: DepotProject | undefined;

if (repositoryName.includes('/')) {
const [org, repo] = repositoryName.split('/');
project = config.find((project) =>
project.repository_org === org && project.repository_name === repo
);
}
// LEGACY
if (!project) {
project = config.find((project) => project.repository === repositoryName);
}

if (!project) {
throw new Error(`Project ${repositoryName} not found in config file`);
Expand All @@ -35,7 +60,13 @@ export const getDockerBinaries = async (repositoryName: string): Promise<string>
}

if (DEPOT_REPO_NAME) {
console.log(JSON.stringify(await getBinaries(DEPOT_REPO_NAME)));
let repositoryIdentifier = DEPOT_REPO_NAME;

if (DEPOT_REPOSITORY_ORG && DEPOT_REPOSITORY_ORG !== "") {
repositoryIdentifier = `${DEPOT_REPOSITORY_ORG}/${DEPOT_REPO_NAME}`;
}

console.log(JSON.stringify(await getBinaries(repositoryIdentifier)));
} else {
console.error("DEPOT_REPOSITORY_NAME is not set");
Deno.exit(1);
Expand Down
1 change: 1 addition & 0 deletions utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const GITHUB_WORKSPACE = Deno.env.get("GITHUB_WORKSPACE") ?? Deno.cwd();

export const DEPOT_CONFIG_PATH = `${GITHUB_WORKSPACE}/config.yml`;
export const DEPOT_REPO_NAME = Deno.env.get("DEPOT_REPOSITORY_NAME") ?? "sui";
export const DEPOT_REPOSITORY_ORG = Deno.env.get("DEPOT_REPOSITORY_ORG") ?? "sui";

export const getConfig = async (filepath: string) => {
try {
Expand Down
56 changes: 46 additions & 10 deletions utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { getConfig } from "./config.ts";
import { getBinaries, getDockerBinaries } from "./binaries.ts";

import { DEPOT_CONFIG_PATH, DEPOT_REPO_NAME, GITHUB_ENV_PATH, GITHUB_IS_CI } from "./config.ts";
import { DEPOT_CONFIG_PATH, DEPOT_REPO_NAME, DEPOT_REPOSITORY_ORG, GITHUB_ENV_PATH, GITHUB_IS_CI } from "./config.ts";
import { DepotProject } from "./types.ts";

const build = async (repositoryName: string): Promise<void> => {
const build = async (repositoryOrg: string, repositoryName: string): Promise<void> => {
const config = await getConfig(DEPOT_CONFIG_PATH) as DepotProject[];
const project = config.find((project) => project.repository === repositoryName);

let project = config.find((project) =>
project.repository_org === repositoryOrg && project.repository_name === repositoryName
);

if (!project) {
project = config.find((project) => project.repository === repositoryName);
}

if (!project) {
throw new Error(`Project ${repositoryName} not found in config file`);
throw new Error(`Project ${repositoryOrg}/${repositoryName} not found in config file`);
}

// Set automatic_builds to true by default
Expand All @@ -25,12 +33,29 @@ const build = async (repositoryName: string): Promise<void> => {
const runner = project.runner || "ubuntu-22.04-l";
await setEnv("DEPOT_RUNNER", runner);

// The binaries we need to build for given project.
// The binaries we need to build for given project.
if (runBuild === true) {
await setEnv("DEPOT_BINARIES", await getProjectBinaryNames(project, "name"));
await setEnv("DEPOT_BINARY_PATHS", await getProjectBinaryNames(project, "path"));
await setEnv("DEPOT_BINARY_BUILD_NAME", await getProjectBinaryNames(project, "build"));
await setEnv("DEPOT_DOCKER_BINARIES", await getDockerBinaries(repositoryName));

// Only get Docker binaries if Docker builds are enabled
if (project.run_docker_build === true) {
let dockerRepoIdentifier: string;
if (project.repository) {
// Legacy
dockerRepoIdentifier = project.repository;
} else if (project.repository_org && project.repository_name) {
dockerRepoIdentifier = `${project.repository_org}/${project.repository_name}`;
} else {
throw new Error(`Project ${project.project_name} has no valid repository identifier for docker binaries`);
}

await setEnv("DEPOT_DOCKER_BINARIES", await getDockerBinaries(dockerRepoIdentifier));
} else {
// Set empty docker binaries if Docker builds are disabled
await setEnv("DEPOT_DOCKER_BINARIES", "");
}
}

for (const key in project) {
Expand All @@ -55,7 +80,18 @@ const setEnv = async (key: string, value: string | string[] | boolean): Promise<
};

const getProjectBinaryNames = async (project: DepotProject, target: string): Promise<string> => {
const binaries = await getBinaries(project.repository);
let repoIdentifier: string;

if (project.repository) {
// Legacy
repoIdentifier = project.repository;
} else if (project.repository_org && project.repository_name) {
repoIdentifier = `${project.repository_org}/${project.repository_name}`;
} else {
throw new Error(`Project ${project.project_name} has no valid repository identifier`);
}

const binaries = await getBinaries(repoIdentifier);
return project.binaries.map((binary) => {
if (target == "name") {
return binaries[binary].split("/").pop();
Expand All @@ -71,9 +107,9 @@ const getRandomNumber = (): number => {
return Math.floor(100000 + Math.random() * 900000);
};

if (DEPOT_REPO_NAME) {
build(DEPOT_REPO_NAME);
if (DEPOT_REPO_NAME && DEPOT_REPOSITORY_ORG) {
build(DEPOT_REPOSITORY_ORG, DEPOT_REPO_NAME);
} else {
console.error("DEPOT_REPOSITORY_NAME is not set again");
console.error("DEPOT_REPOSITORY_ORG or DEPOT_REPOSITORY_NAME is not set");
Deno.exit(1);
}
4 changes: 3 additions & 1 deletion utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export type DepotProject = {
repository: string;
repository?: string;
repository_org?: string;
repository_name?: string;
automatic_builds?: boolean;
project_name: string;
architecture: string;
Expand Down