mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
Use Github API to fetch the latest version of Apollo Router (#5618)
This commit is contained in:
parent
2f644df579
commit
2f053088f8
1 changed files with 10 additions and 20 deletions
|
|
@ -2,8 +2,6 @@ import { readFile } from 'node:fs/promises';
|
|||
import { join } from 'node:path';
|
||||
import { setOutput } from '@actions/core';
|
||||
|
||||
const GITHUB_REPOSITORY = ensureEnv('GITHUB_REPOSITORY');
|
||||
|
||||
const [localVersion, latestStableVersion] = await Promise.all([
|
||||
fetchLocalVersion(),
|
||||
fetchLatestVersion(),
|
||||
|
|
@ -41,27 +39,19 @@ function ensureEnv(name: string): string {
|
|||
}
|
||||
|
||||
async function fetchLatestVersion() {
|
||||
const versionsResponse = await fetch('https://crates.io/api/v1/crates/apollo-router/versions', {
|
||||
method: 'GET',
|
||||
});
|
||||
const latestResponse = await fetch(
|
||||
'https://api.github.com/repos/apollographql/router/releases/latest',
|
||||
{
|
||||
method: 'GET',
|
||||
},
|
||||
);
|
||||
|
||||
if (!versionsResponse.ok) {
|
||||
if (!latestResponse.ok) {
|
||||
throw new Error('Failed to fetch versions');
|
||||
}
|
||||
|
||||
const { versions } = await versionsResponse.json();
|
||||
|
||||
let latestStableVersion: string | undefined;
|
||||
const stableRegex = /^(\d+\.\d+\.\d+)$/;
|
||||
|
||||
for (const version of versions) {
|
||||
if (!stableRegex.test(version.num)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
latestStableVersion = version.num;
|
||||
break;
|
||||
}
|
||||
const latest = await latestResponse.json();
|
||||
const latestStableVersion = latest.name.replace('v', '');
|
||||
|
||||
if (!latestStableVersion) {
|
||||
throw new Error('Failed to find latest stable version');
|
||||
|
|
@ -95,7 +85,7 @@ async function isPullRequestOpen(latestStableVersion: string) {
|
|||
|
||||
setOutput('title', prTitle);
|
||||
|
||||
const prResponse = await fetch(`https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls`);
|
||||
const prResponse = await fetch(`https://api.github.com/repos/apollographql/router/pulls`);
|
||||
|
||||
if (!prResponse.ok) {
|
||||
throw new Error('Failed to fetch PRs');
|
||||
|
|
|
|||
Loading…
Reference in a new issue