const fs = require('fs'); // Read csproj const csprojPath = './ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj'; if (!fs.existsSync(csprojPath)) { console.error('ConfusedPolarBear.Plugin.IntroSkipper.csproj file not found'); process.exit(1); } function updateCsprojVersion() { const newVersion = process.env.VERSION const csprojContent = fs.readFileSync(csprojPath, 'utf8'); const updatedContent = csprojContent .replace(/.*<\/AssemblyVersion>/, `${newVersion}`) .replace(/.*<\/FileVersion>/, `${newVersion}`); fs.writeFileSync(csprojPath, updatedContent); console.log('Updated .csproj file with new version.'); } // Function to increment version string function incrementVersion(version) { const parts = version.split('.').map(Number); parts[parts.length - 1] += 1; // Increment the last part of the version return parts.join('.'); } // Read the .csproj file fs.readFile(csprojPath, 'utf8', (err, data) => { if (err) { return console.error('Failed to read .csproj file:', err); } let newAssemblyVersion = null; let newFileVersion = null; // Use regex to find and increment versions const updatedData = data.replace(/(.*?)<\/AssemblyVersion>/, (match, version) => { newAssemblyVersion = incrementVersion(version); return `${newAssemblyVersion}`; }).replace(/(.*?)<\/FileVersion>/, (match, version) => { newFileVersion = incrementVersion(version); return `${newFileVersion}`; }); // Write the updated XML back to the .csproj file fs.writeFile(csprojPath, updatedData, 'utf8', (err) => { if (err) { return console.error('Failed to write .csproj file:', err); } console.log('Version incremented successfully!'); // Write the new versions to GitHub Actions environment files fs.appendFileSync(process.env.GITHUB_ENV, `NEW_ASSEMBLY_VERSION=${newAssemblyVersion}\n`); fs.appendFileSync(process.env.GITHUB_ENV, `NEW_FILE_VERSION=${newFileVersion}\n`); }); });