-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker images config from GitHub (#532)
* refactor saga to get docker image name from config * implement image picker dropdown * fix isCurrentOrNewerVersion * refactor dropdown and add verified badge * refactor getAvailableClientReleases
- Loading branch information
Showing
10 changed files
with
256 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import axios, {AxiosResponse} from "axios"; | ||
import {IGithubRelease} from "../../../../types/githubRelease.dto"; | ||
import {getDefaultsForClient} from "../eth2/client/defaults"; | ||
|
||
const gitHubReposInstance = axios.create({ | ||
baseURL: "https://api.github.com/repos/", | ||
timeout: 1000, | ||
}); | ||
|
||
export const getReleases = (owner: string, repo: string): Promise<AxiosResponse<IGithubRelease[]>> => | ||
gitHubReposInstance.get<IGithubRelease[]>(`/${owner}/${repo}/releases`); | ||
|
||
export const isCurrentOrNewerVersion = (current: string, comparingWith: string): boolean => { | ||
if (current === comparingWith) return true; | ||
|
||
const currentFragments = current.replace(/[^\d.-]/g, "").split("."); | ||
const comparingWithFragments = comparingWith.replace(/[^\d.-]/g, "").split("."); | ||
|
||
const length = | ||
currentFragments.length > comparingWithFragments.length | ||
? currentFragments.length | ||
: comparingWithFragments.length; | ||
for (let i = 0; i < length; i++) { | ||
if ((Number(currentFragments[i]) || 0) === (Number(comparingWithFragments[i]) || 0)) continue; | ||
return (Number(comparingWithFragments[i]) || 0) > (Number(currentFragments[i]) || 0); | ||
} | ||
return true; | ||
}; | ||
|
||
export const getAvailableClientReleases = async (client: string): Promise<string[]> => { | ||
const { | ||
beacon: {dockerImage, owner, repo}, | ||
} = getDefaultsForClient(client); | ||
const response = await getReleases(owner, repo); | ||
const currentTag = dockerImage.split(":")[1]; | ||
return ( | ||
response.data | ||
.filter( | ||
// eslint-disable-next-line camelcase, @typescript-eslint/camelcase | ||
({tag_name, draft, prerelease}) => | ||
!draft && !prerelease && isCurrentOrNewerVersion(currentTag, tag_name), | ||
) | ||
// eslint-disable-next-line camelcase, @typescript-eslint/camelcase | ||
.map(({tag_name}) => dockerImage.split(":")[0] + ":" + tag_name) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {isCurrentOrNewerVersion} from "../../../src/renderer/services/utils/githubReleases"; | ||
|
||
describe("GitHub Releases", () => { | ||
describe("isCurrentOrNewerVersion", () => { | ||
it("test with 'v' prefix", () => { | ||
expect(isCurrentOrNewerVersion("v1.3.2", "v1.3.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("v1.3.2", "v1.3.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("v1.3.2", "v2.3.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("v1.3.2", "v2.1.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("v1.3", "v1.3.0")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("v1.3", "v1.3.3")).toBeTruthy(); | ||
|
||
expect(isCurrentOrNewerVersion("v1.3.2", "v1.3.1")).toBeFalsy(); | ||
expect(isCurrentOrNewerVersion("v1.4.2", "v1.3.11")).toBeFalsy(); | ||
expect(isCurrentOrNewerVersion("v1.3.2", "v1.3")).toBeFalsy(); | ||
expect(isCurrentOrNewerVersion("v1.3.2", "v0.2.1")).toBeFalsy(); | ||
}); | ||
|
||
it("test without v prefix", () => { | ||
expect(isCurrentOrNewerVersion("1.3.2", "1.3.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("1.3.2", "1.3.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("1.3.2", "2.3.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("1.3.2", "2.1.2")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("1.3", "1.3.0")).toBeTruthy(); | ||
expect(isCurrentOrNewerVersion("1.3", "1.3.3")).toBeTruthy(); | ||
|
||
expect(isCurrentOrNewerVersion("1.3.2", "1.3.1")).toBeFalsy(); | ||
expect(isCurrentOrNewerVersion("1.4.2", "1.3.11")).toBeFalsy(); | ||
expect(isCurrentOrNewerVersion("1.3.2", "1.3")).toBeFalsy(); | ||
expect(isCurrentOrNewerVersion("1.3.2", "0.2.1")).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.