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
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,47 @@ The dappnode SDK ueses the following internal dependencies to avoid code duplica

In order to have a better developing experience these modules lives inside the DNP_DAPPMANAGER repository

## VSCode debugging

The DappNode SDK can be run and debugged in VSCode.
This run configurations can be configured via de `.vscode/launch.json`

Example `launh.json`
```json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run dappnodesdk",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"start",
"github-action",
"bump-upstream",
"--dir",
"${workspaceFolder}/../dummy", // Path to the DappNode package
"--skip_build"
],
"cwd": "${workspaceFolder}",
"env": {
"GITHUB_TOKEN": "ghp_XXX", // Your github API key
"SKIP_COMMIT": "true"
},
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"console": "integratedTerminal"
}
]
}
```

## License

This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"lint": "eslint . --ext .ts --fix",
"build": "tsc",
"prepublish": "npm run build",
"pre-commit": "npm run lint && npm run test"
"pre-commit": "npm run lint && npm run test",
"cli": "node dist/dappnodesdk.js",
"start": "yarn cli"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -94,4 +96,4 @@
"engines": {
"node": ">=20.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import { Github } from "../../../../providers/github/Github.js";
import { isValidRelease } from "./isValidRelease.js";
import { components } from '@octokit/openapi-types';

type Release = components["schemas"]["release"];
export async function fetchGithubUpstreamVersion(
repo: string
): Promise<string | null> {
try {
const newVersion = await fetchGithubLatestTag(repo);
if (!isValidRelease(newVersion)) {
console.log(
`This is not a valid release (probably a release candidate) - ${repo}: ${newVersion}`
`This is not a valid release (probably a release candidate) - ${repo}: ${newVersion.tag_name}`
);
return null;
}

console.log(`Fetch latest version(s) - ${repo}: ${newVersion}`);
return newVersion;
console.log(`Fetch latest version(s) - ${repo}: ${newVersion.tag_name}`);
return newVersion.tag_name;
} catch (e) {
console.error("Error fetching upstream repo versions:", e);
throw e;
}
}

async function fetchGithubLatestTag(repo: string): Promise<string> {
async function fetchGithubLatestTag(repo: string): Promise<Release> {
const [owner, repoName] = repo.split("/");
const githubRepo = new Github({ owner, repo: repoName });

const releases = await githubRepo.listReleases();
const latestRelease = releases[0];
if (!latestRelease) throw Error(`No release found for ${repo}`);

return latestRelease.tag_name;
// Check if is empty
if (!releases || releases.length === 0) {
throw Error(`No releases found for ${repo}`);
}

// Filter out draft and prerelease
const validReleases = releases.filter(
release => !release.draft && !release.prerelease
);
if (validReleases.length === 0) {
throw Error(`No valid releases found for ${repo}`);
}

const latestRelease = validReleases[0];

return latestRelease;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import semver from "semver";
import type { components } from "@octokit/openapi-types";

export function isValidRelease(version: string): boolean {
export function isValidRelease(version: components["schemas"]["release"]): boolean {
const tagName = version.tag_name;
// Nightly builds are not considered valid releases (not taken into account by semver)
if (version.includes("nightly")) return false;
if (tagName.includes("nightly")) return false;

if (semver.valid(version)) {
const preReleases = semver.prerelease(version);
if (semver.valid(tagName)) {
const preReleases = semver.prerelease(tagName);

// A version is considered a valid release if it has no pre-release components.
return preReleases === null || preReleases.length === 0;
Expand Down
Loading