Change release script to only update version comment for changed files (#3033)

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
(cherry picked from commit 1ffcb10bd2)
This commit is contained in:
Hadrien Croubois
2021-12-22 23:21:45 +01:00
committed by Francisco Giordano
parent 6bd6b76d11
commit 66436cbb4e
3 changed files with 278 additions and 483 deletions

734
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -78,6 +78,7 @@
"prettier": "^2.3.0", "prettier": "^2.3.0",
"prettier-plugin-solidity": "^1.0.0-beta.16", "prettier-plugin-solidity": "^1.0.0-beta.16",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"semver": "^7.3.5",
"solhint": "^3.3.6", "solhint": "^3.3.6",
"solidity-ast": "^0.4.25", "solidity-ast": "^0.4.25",
"solidity-coverage": "^0.7.11", "solidity-coverage": "^0.7.11",

24
scripts/release/update-comment.js Executable file → Normal file
View File

@ -1,11 +1,10 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs'); const fs = require('fs');
const glob = require('glob');
const proc = require('child_process'); const proc = require('child_process');
const semver = require('semver');
const run = (cmd, ...args) => proc.execFileSync(cmd, args, { encoding: 'utf8' }).trim();
const gitStatus = proc.execFileSync('git', ['status', '--porcelain', '-uno', 'contracts/**/*.sol']); const gitStatus = run('git', 'status', '--porcelain', '-uno', 'contracts/**/*.sol');
if (gitStatus.length > 0) { if (gitStatus.length > 0) {
console.error('Contracts directory is not clean'); console.error('Contracts directory is not clean');
process.exit(1); process.exit(1);
@ -13,15 +12,24 @@ if (gitStatus.length > 0) {
const { version } = require('../../package.json'); const { version } = require('../../package.json');
const files = glob.sync('contracts/!(mocks)/**/*.sol'); // Get latest tag according to semver.
const [ tag ] = run('git', 'tag')
.split(/\r?\n/)
.filter(v => semver.lt(semver.coerce(v), version)) // only consider older tags, ignore current prereleases
.sort(semver.rcompare);
// Ordering tag → HEAD is important here.
const files = run('git', 'diff', tag, 'HEAD', '--name-only', 'contracts/**/*.sol')
.split(/\r?\n/)
.filter(file => file && !file.match(/mock/i));
for (const file of files) { for (const file of files) {
const current = fs.readFileSync(file, 'utf8'); const current = fs.readFileSync(file, 'utf8');
const updated = current.replace( const updated = current.replace(
/(\/\/ SPDX-License-Identifier:.*)$(\n\/\/ OpenZeppelin Contracts v.*$)?/m, /(\/\/ SPDX-License-Identifier:.*)$(\n\/\/ OpenZeppelin Contracts .*$)?/m,
`$1\n// OpenZeppelin Contracts v${version} (${file.replace('contracts/', '')})`, `$1\n// OpenZeppelin Contracts (last updated v${version}) (${file.replace('contracts/', '')})`,
); );
fs.writeFileSync(file, updated); fs.writeFileSync(file, updated);
} }
proc.execFileSync('git', ['add', '--update', 'contracts']); run('git', 'add', '--update', 'contracts');