Use Github API to fetch the latest version of Apollo Router (#5618)

This commit is contained in:
Kamil Kisiela 2024-09-24 01:22:56 -07:00 committed by GitHub
parent 2f644df579
commit 2f053088f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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');