From 4cdbf857b28cb5c8eaf75182f5b659f85f953377 Mon Sep 17 00:00:00 2001 From: bot Date: Tue, 29 Jul 2025 09:10:19 +0200 Subject: [PATCH] Improved bumpUpstream relese validation logic Addesd documentation to use VSCode Debugging --- README.md | 41 +++++++++++++++++++ package.json | 6 ++- .../github/fetchGithubUpstreamVersion.ts | 29 +++++++++---- .../bumpUpstream/github/isValidRelease.ts | 10 +++-- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 23d58fec..45420101 100644 --- a/README.md +++ b/README.md @@ -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": [ + "/**" + ], + "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 diff --git a/package.json b/package.json index a4baf53b..e99a6683 100644 --- a/package.json +++ b/package.json @@ -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", @@ -94,4 +96,4 @@ "engines": { "node": ">=20.0.0" } -} +} \ No newline at end of file diff --git a/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts b/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts index 12217196..484a3579 100644 --- a/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts +++ b/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts @@ -1,6 +1,8 @@ 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 { @@ -8,26 +10,39 @@ export async function fetchGithubUpstreamVersion( 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 { +async function fetchGithubLatestTag(repo: string): Promise { 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; } diff --git a/src/commands/githubActions/bumpUpstream/github/isValidRelease.ts b/src/commands/githubActions/bumpUpstream/github/isValidRelease.ts index 3337c633..533e0c83 100644 --- a/src/commands/githubActions/bumpUpstream/github/isValidRelease.ts +++ b/src/commands/githubActions/bumpUpstream/github/isValidRelease.ts @@ -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;