Skip to content

Commit

Permalink
fetching version from release and not master
Browse files Browse the repository at this point in the history
  • Loading branch information
Yooooomi committed Nov 2, 2023
1 parent 4769477 commit 7196866
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- server/**
branches:
- master
- release/*

jobs:
build:
Expand Down
5 changes: 4 additions & 1 deletion server/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions server/src/tools/apis/githubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 7196866

Please sign in to comment.