-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bouncer, auto bump spec version for runtime upgrades (#4143)
* feat: auto-bump spec version in noop-runtime-upgrade test * refactor: replace interactive test run with command line arg * chore: lints
- Loading branch information
Showing
3 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fs from 'fs'; | ||
|
||
export function bumpSpecVersion(filePath: string, nextSpecVersion?: number) { | ||
console.log('Bumping the spec version'); | ||
try { | ||
const fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
const lines = fileContent.split('\n'); | ||
|
||
let incrementedVersion; | ||
let foundMacro = false; | ||
for (let i = 0; i < lines.length; i++) { | ||
const line = lines[i]; | ||
|
||
if (line.trim() === '#[sp_version::runtime_version]') { | ||
foundMacro = true; | ||
} | ||
|
||
if (foundMacro && line.includes('spec_version:')) { | ||
const specVersionLine = line.match(/(spec_version:\s*)(\d+)/); | ||
|
||
if (specVersionLine) { | ||
if (nextSpecVersion) { | ||
incrementedVersion = nextSpecVersion; | ||
} else { | ||
incrementedVersion = parseInt(specVersionLine[2]) + 1; | ||
} | ||
lines[i] = ` spec_version: ${incrementedVersion},`; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!foundMacro) { | ||
console.error('spec_version within #[sp_version::runtime_version] not found.'); | ||
return; | ||
} | ||
|
||
const updatedContent = lines.join('\n'); | ||
fs.writeFileSync(filePath, updatedContent); | ||
|
||
console.log(`Successfully updated spec_version to ${incrementedVersion}.`); | ||
} catch (error) { | ||
console.error(`An error occurred: ${error.message}`); | ||
} | ||
} |