From 83a2c81290efe8a8c38ffcbce4b447eabcda37b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Wed, 16 Nov 2022 16:01:23 -0300 Subject: [PATCH 1/3] feat: add latest releases downloads logic --- src/components/UI/downloads/DownloadsHero.tsx | 10 +- src/constants.ts | 16 +++ src/pages/downloads.tsx | 103 +++++++++++++++--- 3 files changed, 107 insertions(+), 22 deletions(-) diff --git a/src/components/UI/downloads/DownloadsHero.tsx b/src/components/UI/downloads/DownloadsHero.tsx index 2c01270953..7e7f241f5c 100644 --- a/src/components/UI/downloads/DownloadsHero.tsx +++ b/src/components/UI/downloads/DownloadsHero.tsx @@ -5,7 +5,7 @@ import NextLink from 'next/link'; import { DOWNLOAD_HEADER_BUTTONS } from '../../../constants'; interface DownloadsHero { - currentBuildName: string; + currentBuild: string; currentBuildVersion: string; linuxBuildURL: string; macOSBuildURL: string; @@ -15,7 +15,7 @@ interface DownloadsHero { } export const DownloadsHero: FC = ({ - currentBuildName, + currentBuild, currentBuildVersion, linuxBuildURL, macOSBuildURL, @@ -45,7 +45,7 @@ export const DownloadsHero: FC = ({ lineHeight='21px' mb={8} > - {currentBuildName} ({currentBuildVersion}) + {currentBuild} @@ -70,7 +70,7 @@ export const DownloadsHero: FC = ({ For {DOWNLOAD_HEADER_BUTTONS[key].name} - geth {currentBuildName} + geth {currentBuildVersion} @@ -80,7 +80,7 @@ export const DownloadsHero: FC = ({ - Release notes for {currentBuildName} {currentBuildVersion} + Release notes for {currentBuild} diff --git a/src/constants.ts b/src/constants.ts index 274b4fae6e..e7002d00cc 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -66,3 +66,19 @@ export const DOWNLOAD_OPENPGP_DEVELOPER_HEADERS = [ 'OpenPGP Key', 'Fingerprint' ]; + +// GitHub urls +export const LATEST_GETH_RELEASE_URL = + 'https://api.github.com/repos/ethereum/go-ethereum/releases/latest'; +export const ALL_GETH_RELEASES_URL = 'https://api.github.com/repos/ethereum/go-ethereum/releases'; +export const ALL_GETH_COMMITS_URL = 'https://api.github.com/repos/ethereum/go-ethereum/commits/'; + +export const LINUX_BINARY_BASE_URL = + 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-'; +export const MACOS_BINARY_BASE_URL = + 'https://gethstore.blob.core.windows.net/builds/geth-darwin-amd64-'; +export const WINDOWS_BINARY_BASE_URL = + 'https://gethstore.blob.core.windows.net/builds/geth-windows-amd64-'; + +export const LATEST_SOURCES_BASE_URL = 'https://github.com/ethereum/go-ethereum/archive/'; +export const RELEASE_NOTES_BASE_URL = 'https://github.com/ethereum/go-ethereum/releases/tag/'; diff --git a/src/pages/downloads.tsx b/src/pages/downloads.tsx index c612af2d6c..7766c931bc 100644 --- a/src/pages/downloads.tsx +++ b/src/pages/downloads.tsx @@ -1,22 +1,92 @@ import { Code, Link, ListItem, Stack, Text, UnorderedList } from '@chakra-ui/react'; -import type { NextPage } from 'next'; +import type { GetServerSideProps, NextPage } from 'next'; import { useState } from 'react'; import { DownloadsHero, DownloadsSection, DownloadsTable } from '../components/UI/downloads'; import { DataTable } from '../components/UI'; import { + ALL_GETH_COMMITS_URL, DEFAULT_BUILD_AMOUNT_TO_SHOW, DOWNLOAD_OPENPGP_BUILD_HEADERS, DOWNLOAD_OPENPGP_DEVELOPER_HEADERS, - GETH_REPO_URL + GETH_REPO_URL, + LATEST_GETH_RELEASE_URL, + LATEST_SOURCES_BASE_URL, + LINUX_BINARY_BASE_URL, + MACOS_BINARY_BASE_URL, + RELEASE_NOTES_BASE_URL, + WINDOWS_BINARY_BASE_URL } from '../constants'; import { testDownloadData } from '../data/test/download-testdata'; import { pgpBuildTestData } from '../data/test/pgpbuild-testdata'; import { pgpDeveloperTestData } from '../data/test/pgpdeveloper-testdata'; -const DownloadsPage: NextPage = () => { +export const getServerSideProps: GetServerSideProps = async () => { + // Latest release version number + const versionNumber = await fetch(LATEST_GETH_RELEASE_URL) + .then(response => response.json()) + .then(release => release.tag_name); + // Latest release name + const releaseName = await fetch(LATEST_GETH_RELEASE_URL) + .then(response => response.json()) + .then(release => release.name); + // Latest release commit hash + const commit = await fetch(`${ALL_GETH_COMMITS_URL}/${versionNumber}`) + .then(response => response.json()) + .then(commit => commit.sha.slice(0, 8)); + + // Latest binaries urls + const LATEST_LINUX_BINARY_URL = `${LINUX_BINARY_BASE_URL}${versionNumber.slice( + 1 + )}-${commit}.tar.gz`; + const LATEST_MACOS_BINARY_URL = `${MACOS_BINARY_BASE_URL}${versionNumber.slice( + 1 + )}-${commit}.tar.gz`; + const LATEST_WINDOWS_BINARY_URL = `${WINDOWS_BINARY_BASE_URL}${versionNumber.slice( + 1 + )}-${commit}.exe`; + + // Sources urls + const LATEST_SOURCES_URL = `${LATEST_SOURCES_BASE_URL}${versionNumber}.tar.gz`; + const RELEASE_NOTES_URL = `${RELEASE_NOTES_BASE_URL}${versionNumber}`; + + const LATEST_RELEASES_DATA = { + versionNumber, + releaseName, + urls: { + LATEST_LINUX_BINARY_URL, + LATEST_MACOS_BINARY_URL, + LATEST_WINDOWS_BINARY_URL, + LATEST_SOURCES_URL, + RELEASE_NOTES_URL + } + }; + + return { + props: { + data: LATEST_RELEASES_DATA + } + }; +}; + +interface Props { + data: { + // TODO: define interface + versionNumber: string; + releaseName: string; + urls: { + LATEST_LINUX_BINARY_URL: string; + LATEST_MACOS_BINARY_URL: string; + LATEST_WINDOWS_BINARY_URL: string; + LATEST_SOURCES_URL: string; + RELEASE_NOTES_URL: string; + }; + }; +} + +const DownloadsPage: NextPage = ({ data }) => { const [amountStableReleases, updateAmountStables] = useState(DEFAULT_BUILD_AMOUNT_TO_SHOW); const [amountDevelopBuilds, updateAmountDevelopBuilds] = useState(DEFAULT_BUILD_AMOUNT_TO_SHOW); @@ -28,27 +98,22 @@ const DownloadsPage: NextPage = () => { updateAmountDevelopBuilds(amountDevelopBuilds + 10); }; + const { releaseName, versionNumber, urls } = data; + return ( <> {/* TODO: add PageMetadata */}
- {/* TODO: replace hardcoded strings with build information */} { gpg --verify geth-linux-amd64-1.5.0-d0c820ac.tar.gz.asc + +
+
{JSON.stringify(data, null, 2)}
+
From d7ed9e4d5b92e8df2a24b07d113e12d8a3113d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Wed, 16 Nov 2022 19:52:03 -0300 Subject: [PATCH 2/3] chore: move urls to constants --- src/pages/downloads.tsx | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/pages/downloads.tsx b/src/pages/downloads.tsx index 7766c931bc..e6bc578c30 100644 --- a/src/pages/downloads.tsx +++ b/src/pages/downloads.tsx @@ -66,22 +66,24 @@ export const getServerSideProps: GetServerSideProps = async () => { return { props: { - data: LATEST_RELEASES_DATA + data: { LATEST_RELEASES_DATA } } }; }; interface Props { data: { - // TODO: define interface - versionNumber: string; - releaseName: string; - urls: { - LATEST_LINUX_BINARY_URL: string; - LATEST_MACOS_BINARY_URL: string; - LATEST_WINDOWS_BINARY_URL: string; - LATEST_SOURCES_URL: string; - RELEASE_NOTES_URL: string; + // TODO: define interfaces + LATEST_RELEASES_DATA: { + versionNumber: string; + releaseName: string; + urls: { + LATEST_LINUX_BINARY_URL: string; + LATEST_MACOS_BINARY_URL: string; + LATEST_WINDOWS_BINARY_URL: string; + LATEST_SOURCES_URL: string; + RELEASE_NOTES_URL: string; + }; }; }; } @@ -98,7 +100,9 @@ const DownloadsPage: NextPage = ({ data }) => { updateAmountDevelopBuilds(amountDevelopBuilds + 10); }; - const { releaseName, versionNumber, urls } = data; + const { + LATEST_RELEASES_DATA: { releaseName, versionNumber, urls } + } = data; return ( <> @@ -270,10 +274,6 @@ const DownloadsPage: NextPage = ({ data }) => { gpg --verify geth-linux-amd64-1.5.0-d0c820ac.tar.gz.asc - -
-
{JSON.stringify(data, null, 2)}
-
From 832ad6bab048748791cac1ef3b2880e5ccaad1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Thu, 17 Nov 2022 00:14:43 -0300 Subject: [PATCH 3/3] chore: reduce release name & version to a single request --- src/pages/downloads.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pages/downloads.tsx b/src/pages/downloads.tsx index 79de247dc2..c0d1ab2156 100644 --- a/src/pages/downloads.tsx +++ b/src/pages/downloads.tsx @@ -29,14 +29,15 @@ import { pgpBuildTestData } from '../data/test/pgpbuild-testdata'; import { pgpDeveloperTestData } from '../data/test/pgpdeveloper-testdata'; export const getServerSideProps: GetServerSideProps = async () => { - // Latest release version number - const versionNumber = await fetch(LATEST_GETH_RELEASE_URL) + // Latest release name & version number + const { versionNumber, releaseName } = await fetch(LATEST_GETH_RELEASE_URL) .then(response => response.json()) - .then(release => release.tag_name); - // Latest release name - const releaseName = await fetch(LATEST_GETH_RELEASE_URL) - .then(response => response.json()) - .then(release => release.name); + .then(release => { + return { + versionNumber: release.tag_name, + releaseName: release.name + }; + }); // Latest release commit hash const commit = await fetch(`${ALL_GETH_COMMITS_URL}/${versionNumber}`) .then(response => response.json())