Skip to content

Commit 4cdbf85

Browse files
committed
Improved bumpUpstream relese validation logic
Addesd documentation to use VSCode Debugging
1 parent 35150c4 commit 4cdbf85

4 files changed

Lines changed: 73 additions & 13 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,47 @@ The dappnode SDK ueses the following internal dependencies to avoid code duplica
131131

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

134+
## VSCode debugging
135+
136+
The DappNode SDK can be run and debugged in VSCode.
137+
This run configurations can be configured via de `.vscode/launch.json`
138+
139+
Example `launh.json`
140+
```json
141+
{
142+
"version": "0.2.0",
143+
"configurations": [
144+
{
145+
"type": "node",
146+
"request": "launch",
147+
"name": "Run dappnodesdk",
148+
"runtimeExecutable": "yarn",
149+
"runtimeArgs": [
150+
"start",
151+
"github-action",
152+
"bump-upstream",
153+
"--dir",
154+
"${workspaceFolder}/../dummy", // Path to the DappNode package
155+
"--skip_build"
156+
],
157+
"cwd": "${workspaceFolder}",
158+
"env": {
159+
"GITHUB_TOKEN": "ghp_XXX", // Your github API key
160+
"SKIP_COMMIT": "true"
161+
},
162+
"skipFiles": [
163+
"<node_internals>/**"
164+
],
165+
"preLaunchTask": "tsc: build - tsconfig.json",
166+
"outFiles": [
167+
"${workspaceFolder}/dist/**/*.js"
168+
],
169+
"console": "integratedTerminal"
170+
}
171+
]
172+
}
173+
```
174+
134175
## License
135176

136177
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"lint": "eslint . --ext .ts --fix",
1313
"build": "tsc",
1414
"prepublish": "npm run build",
15-
"pre-commit": "npm run lint && npm run test"
15+
"pre-commit": "npm run lint && npm run test",
16+
"cli": "node dist/dappnodesdk.js",
17+
"start": "yarn cli"
1618
},
1719
"repository": {
1820
"type": "git",
@@ -94,4 +96,4 @@
9496
"engines": {
9597
"node": ">=20.0.0"
9698
}
97-
}
99+
}
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
import { Github } from "../../../../providers/github/Github.js";
22
import { isValidRelease } from "./isValidRelease.js";
3+
import { components } from '@octokit/openapi-types';
34

5+
type Release = components["schemas"]["release"];
46
export async function fetchGithubUpstreamVersion(
57
repo: string
68
): Promise<string | null> {
79
try {
810
const newVersion = await fetchGithubLatestTag(repo);
911
if (!isValidRelease(newVersion)) {
1012
console.log(
11-
`This is not a valid release (probably a release candidate) - ${repo}: ${newVersion}`
13+
`This is not a valid release (probably a release candidate) - ${repo}: ${newVersion.tag_name}`
1214
);
1315
return null;
1416
}
1517

16-
console.log(`Fetch latest version(s) - ${repo}: ${newVersion}`);
17-
return newVersion;
18+
console.log(`Fetch latest version(s) - ${repo}: ${newVersion.tag_name}`);
19+
return newVersion.tag_name;
1820
} catch (e) {
1921
console.error("Error fetching upstream repo versions:", e);
2022
throw e;
2123
}
2224
}
2325

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

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

32-
return latestRelease.tag_name;
32+
// Check if is empty
33+
if (!releases || releases.length === 0) {
34+
throw Error(`No releases found for ${repo}`);
35+
}
36+
37+
// Filter out draft and prerelease
38+
const validReleases = releases.filter(
39+
release => !release.draft && !release.prerelease
40+
);
41+
if (validReleases.length === 0) {
42+
throw Error(`No valid releases found for ${repo}`);
43+
}
44+
45+
const latestRelease = validReleases[0];
46+
47+
return latestRelease;
3348
}

src/commands/githubActions/bumpUpstream/github/isValidRelease.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import semver from "semver";
2+
import type { components } from "@octokit/openapi-types";
23

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

7-
if (semver.valid(version)) {
8-
const preReleases = semver.prerelease(version);
9+
if (semver.valid(tagName)) {
10+
const preReleases = semver.prerelease(tagName);
911

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

0 commit comments

Comments
 (0)