From 719686690cbef54a52bd7f8f6212bd3e963f889b Mon Sep 17 00:00:00 2001 From: Timothee Date: Thu, 2 Nov 2023 17:45:42 +0100 Subject: [PATCH] fetching version from release and not master --- .github/workflows/nightly.yml | 1 + server/src/routes/index.ts | 5 ++++- server/src/tools/apis/githubApi.ts | 18 +++++++++++------- server/tsconfig.json | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c9f720e0..31d4c63a 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -9,6 +9,7 @@ on: - server/** branches: - master + - release/* jobs: build: diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 93b785a0..70b205a3 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -197,7 +197,10 @@ router.get('/version', logged, async (_, res) => { return res.status(200).send({ update: false, version: '1.0.0' }); } try { - const version = await GithubAPI.lastPackageJsonVersion(); + const version = await GithubAPI.lastVersion(); + if (!version) { + return res.status(200).send({ update: false, version: '1.0.0' }); + } if (version.isNewerThan(Version.thisOne())) { return res .status(200) diff --git a/server/src/tools/apis/githubApi.ts b/server/src/tools/apis/githubApi.ts index feb706c5..ceff12f0 100644 --- a/server/src/tools/apis/githubApi.ts +++ b/server/src/tools/apis/githubApi.ts @@ -48,8 +48,8 @@ export interface Release { name: string; draft: boolean; prerelease: boolean; - created_at: Date; - published_at: Date; + created_at: string; + published_at: string; tarball_url: string; zipball_url: string; body: string; @@ -65,10 +65,14 @@ export class GithubAPI { return releases as Release[]; } - static async lastPackageJsonVersion() { - const { data: file } = await axios.get( - 'https://raw.githubusercontent.com/Yooooomi/your_spotify/master/server/package.json', - ); - return Version.from(file.version); + static async lastVersion() { + const lastGithubTag = (await this.releases()).sort( + (a, b) => + new Date(b.published_at).getTime() - new Date(a.published_at).getTime(), + )[0]?.tag_name; + if (!lastGithubTag) { + return undefined; + } + return Version.from(lastGithubTag); } } diff --git a/server/tsconfig.json b/server/tsconfig.json index 56283eb8..dc3e8cde 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -93,7 +93,7 @@ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */