Skip to content

Commit

Permalink
remove gift dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Dec 16, 2021
1 parent 34df32d commit de207f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 117 deletions.
75 changes: 0 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -66,7 +66,6 @@
"eth-sig-util": "^3.0.0",
"ethereumjs-util": "^7.0.7",
"ethereumjs-wallet": "^1.0.1",
"gift": "^0.10.2",
"glob": "^7.2.0",
"graphlib": "^2.1.8",
"hardhat": "^2.0.6",
Expand Down
70 changes: 29 additions & 41 deletions scripts/release/update-comment.js
@@ -1,49 +1,37 @@
const fs = require('fs');
const git = require('gift');
const proc = require('child_process');
const semver = require('semver');

const { version } = require('../../package.json');

function check(error, message) {
if (error) {
console.error(message ?? error);
process.exit(1);
}
const status = proc.execFileSync('git', ['status', '--porcelain', '-uno', 'contracts/**/*.sol']);
if (status.length > 0) {
console.error('Contracts directory is not clean');
process.exit(1);
}

const repo = git('.');

repo.git('status --porcelain -uno contracts/**/*.sol', (error, status) => {
check(error);
check(!!status, 'Contracts directory is not clean');

repo.tags((error, tags) => {
check(error);

const [ tag ] = tags
.map(({ name }) => name)
.filter(v => semver.valid(v) && semver.lte(v, version))
.sort(semver.rcompare);

repo.diff('master', tag, (error, diffs) => {
check(error);

diffs
.filter(({ b_path: path }) => path.startsWith('contracts/'))
.filter(({ b_path: path }) => !path.startsWith('contracts/mocks'))
.filter(({ b_path: path }) => path.endsWith('.sol'))
.forEach(({ b_path: path }) => {
const current = fs.readFileSync(path, 'utf8');
const updated = current.replace(
/(\/\/ SPDX-License-Identifier:.*)$(\n\/\/ OpenZeppelin Contracts v.*$)?/m,
`$1\n// Last updated in OpenZeppelin Contracts v${version} (${path.replace('contracts/', '')})`,
);
fs.writeFileSync(path, updated);
});
const [ tag ] = proc.execFileSync('git', ['tag'])
.toString()
.split(/\r?\n/)
.filter(v => semver.valid(v) && semver.lte(v, version))
.sort(semver.rcompare);

// Ordering tag → HEAD is important here.
// Is it right to use HEAD ?
const diffs = proc.execFileSync('git', ['diff', tag, 'HEAD', '--name-only'])
.toString()
.split(/\r?\n/)
.filter(path => path.startsWith('contracts/'))
.filter(path => !path.startsWith('contracts/mocks'))
.filter(path => path.endsWith('.sol'));

for (const file of diffs) {
const current = fs.readFileSync(file, 'utf8');
const updated = current.replace(
/(\/\/ SPDX-License-Identifier:.*)$(\n\/\/ OpenZeppelin Contracts v.*$)?/m,
`$1\n// Last updated in OpenZeppelin Contracts v${version} (${file.replace('contracts/', '')})`,
);
fs.writeFileSync(file, updated);
}

repo.git('add --update contracts', (error) => {
check(error);
});
});
});
});
proc.execFileSync('git', ['add', '--update', 'contracts']);

0 comments on commit de207f0

Please sign in to comment.