ci: use the nuget api to get latest ABI
This commit is contained in:
parent
12c89c320d
commit
aaff7a2be7
@ -5,7 +5,8 @@ const { URL } = require('url');
|
|||||||
|
|
||||||
const repository = process.env.GITHUB_REPOSITORY;
|
const repository = process.env.GITHUB_REPOSITORY;
|
||||||
const version = process.env.VERSION;
|
const version = process.env.VERSION;
|
||||||
const targetAbi = "10.9.11.0";
|
let currentVersion = "";
|
||||||
|
let targetAbi = "";
|
||||||
|
|
||||||
// Read manifest.json
|
// Read manifest.json
|
||||||
const manifestPath = './manifest.json';
|
const manifestPath = './manifest.json';
|
||||||
@ -23,6 +24,9 @@ if (!fs.existsSync(readmePath)) {
|
|||||||
|
|
||||||
const jsonData = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
const jsonData = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
||||||
|
|
||||||
|
async function updateManifest() {
|
||||||
|
currentVersion = await getNugetPackageVersion('Jellyfin.Model', '10.*-*');
|
||||||
|
targetAbi = `${currentVersion}.0`
|
||||||
const newVersion = {
|
const newVersion = {
|
||||||
version,
|
version,
|
||||||
changelog: `- See the full changelog at [GitHub](https://github.com/${repository}/releases/tag/10.9/v${version})\n`,
|
changelog: `- See the full changelog at [GitHub](https://github.com/${repository}/releases/tag/10.9/v${version})\n`,
|
||||||
@ -31,8 +35,6 @@ const newVersion = {
|
|||||||
checksum: getMD5FromFile(),
|
checksum: getMD5FromFile(),
|
||||||
timestamp: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z')
|
timestamp: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z')
|
||||||
};
|
};
|
||||||
|
|
||||||
async function updateManifest() {
|
|
||||||
await validVersion(newVersion);
|
await validVersion(newVersion);
|
||||||
|
|
||||||
// Add the new version to the manifest
|
// Add the new version to the manifest
|
||||||
@ -107,18 +109,11 @@ function getMD5FromFile() {
|
|||||||
return crypto.createHash('md5').update(fileBuffer).digest('hex');
|
return crypto.createHash('md5').update(fileBuffer).digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReadMeVersion() {
|
|
||||||
let parts = targetAbi.split('.').map(Number);
|
|
||||||
parts.pop();
|
|
||||||
return parts.join(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateReadMeVersion() {
|
function updateReadMeVersion() {
|
||||||
const newVersion = getReadMeVersion();
|
|
||||||
const readMeContent = fs.readFileSync(readmePath, 'utf8');
|
const readMeContent = fs.readFileSync(readmePath, 'utf8');
|
||||||
|
|
||||||
const updatedContent = readMeContent
|
const updatedContent = readMeContent
|
||||||
.replace(/Jellyfin.*\(or newer\)/, `Jellyfin ${newVersion} (or newer)`)
|
.replace(/Jellyfin.*\(or newer\)/, `Jellyfin ${currentVersion} (or newer)`)
|
||||||
if (readMeContent != updatedContent) {
|
if (readMeContent != updatedContent) {
|
||||||
fs.writeFileSync(readmePath, updatedContent);
|
fs.writeFileSync(readmePath, updatedContent);
|
||||||
console.log('Updated README with new Jellyfin version.');
|
console.log('Updated README with new Jellyfin version.');
|
||||||
@ -160,6 +155,41 @@ function cleanUpOldReleases() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getNugetPackageVersion(packageName, versionPattern) {
|
||||||
|
// Convert package name to lowercase for the NuGet API
|
||||||
|
const url = `https://api.nuget.org/v3-flatcontainer/${packageName.toLowerCase()}/index.json`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Fetch data using the built-in fetch API
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch package information: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const versions = data.versions;
|
||||||
|
|
||||||
|
// Create a regular expression from the version pattern
|
||||||
|
const versionRegex = new RegExp(versionPattern.replace(/\./g, '\\.').replace('*', '.*'));
|
||||||
|
|
||||||
|
// Filter versions based on the provided pattern
|
||||||
|
const matchingVersions = versions.filter(version => versionRegex.test(version));
|
||||||
|
|
||||||
|
// Check if there are any matching versions
|
||||||
|
if (matchingVersions.length > 0) {
|
||||||
|
const latestVersion = matchingVersions[matchingVersions.length - 1];
|
||||||
|
console.log(`Latest version of ${packageName} matching ${versionPattern}: ${latestVersion}`);
|
||||||
|
return latestVersion;
|
||||||
|
} else {
|
||||||
|
console.log(`No versions of ${packageName} match the pattern ${versionPattern}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error fetching package information for ${packageName}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
await updateManifest();
|
await updateManifest();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user