Update docs
This commit is contained in:
153
scripts/release/release.sh
Executable file
153
scripts/release/release.sh
Executable file
@ -0,0 +1,153 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Exit script as soon as a command fails.
|
||||
set -o errexit
|
||||
|
||||
# Default the prerelease version suffix to rc
|
||||
: ${PRERELEASE_SUFFIX:=rc}
|
||||
|
||||
log() {
|
||||
# Print to stderr to prevent this from being 'returned'
|
||||
echo "$@" > /dev/stderr
|
||||
}
|
||||
|
||||
current_version() {
|
||||
echo "v$(node --print --eval "require('./package.json').version")"
|
||||
}
|
||||
|
||||
current_release_branch() {
|
||||
v="$(current_version)" # 3.3.0-rc.0
|
||||
vf="${v%-"$PRERELEASE_SUFFIX".*}" # 3.3.0
|
||||
r="${vf%.*}" # 3.3
|
||||
echo "release-$r"
|
||||
}
|
||||
|
||||
assert_current_branch() {
|
||||
current_branch="$(git symbolic-ref --short HEAD)"
|
||||
expected_branch="$1"
|
||||
if [[ "$current_branch" != "$expected_branch" ]]; then
|
||||
log "Current branch '$current_branch' is not '$expected_branch'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
push_release_branch_and_tag() {
|
||||
git push upstream "$(current_release_branch)" "$(current_version)"
|
||||
}
|
||||
|
||||
publish() {
|
||||
dist_tag="$1"
|
||||
|
||||
log "Publishing openzeppelin-solidity on npm"
|
||||
npm publish --tag "$dist_tag" --otp "$(prompt_otp)"
|
||||
|
||||
log "Publishing @openzeppelin/contracts on npm"
|
||||
cd contracts
|
||||
env ALREADY_COMPILED= \
|
||||
npm publish --tag "$dist_tag" --otp "$(prompt_otp)"
|
||||
cd ..
|
||||
|
||||
if [[ "$dist_tag" == "latest" ]]; then
|
||||
otp="$(prompt_otp)"
|
||||
npm dist-tag rm --otp "$otp" openzeppelin-solidity next
|
||||
npm dist-tag rm --otp "$otp" @openzeppelin/contracts next
|
||||
fi
|
||||
}
|
||||
|
||||
push_and_publish() {
|
||||
dist_tag="$1"
|
||||
|
||||
log "Pushing release branch and tags to upstream"
|
||||
push_release_branch_and_tag
|
||||
|
||||
publish "$dist_tag"
|
||||
}
|
||||
|
||||
prompt_otp() {
|
||||
log -n "Enter npm 2FA token: "
|
||||
read -r otp
|
||||
echo "$otp"
|
||||
}
|
||||
|
||||
environment_check() {
|
||||
if ! git remote get-url upstream &> /dev/null; then
|
||||
log "No 'upstream' remote found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if npm whoami &> /dev/null; then
|
||||
log "Will publish as '$(npm whoami)'"
|
||||
else
|
||||
log "Not logged in into npm, run 'npm login' first"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
environment_check
|
||||
|
||||
if [[ "$*" == "push" ]]; then
|
||||
push_and_publish next
|
||||
|
||||
elif [[ "$*" == "start minor" ]]; then
|
||||
log "Creating new minor pre-release"
|
||||
|
||||
assert_current_branch master
|
||||
|
||||
# Create temporary release branch
|
||||
git checkout -b release-temp
|
||||
|
||||
# This bumps minor and adds prerelease suffix, commits the changes, and tags the commit
|
||||
npm version preminor --preid="$PRERELEASE_SUFFIX"
|
||||
|
||||
# Rename the release branch
|
||||
git branch --move "$(current_release_branch)"
|
||||
|
||||
push_and_publish next
|
||||
|
||||
elif [[ "$*" == "start major" ]]; then
|
||||
log "Creating new major pre-release"
|
||||
|
||||
assert_current_branch master
|
||||
|
||||
# Create temporary release branch
|
||||
git checkout -b release-temp
|
||||
|
||||
# This bumps major and adds prerelease suffix, commits the changes, and tags the commit
|
||||
npm version premajor --preid="$PRERELEASE_SUFFIX"
|
||||
|
||||
# Rename the release branch
|
||||
git branch --move "$(current_release_branch)"
|
||||
|
||||
push_and_publish next
|
||||
|
||||
elif [[ "$*" == "rc" ]]; then
|
||||
log "Bumping pre-release"
|
||||
|
||||
assert_current_branch "$(current_release_branch)"
|
||||
|
||||
# Bumps prerelease number, commits and tags
|
||||
npm version prerelease
|
||||
|
||||
push_and_publish next
|
||||
|
||||
elif [[ "$*" == "final" ]]; then
|
||||
# Update changelog release date, remove prerelease suffix, tag, push to git, publish in npm, remove next dist-tag
|
||||
log "Creating final release"
|
||||
|
||||
assert_current_branch "$(current_release_branch)"
|
||||
|
||||
# This will remove the prerelease suffix from the version
|
||||
npm version patch
|
||||
|
||||
push_release_branch_and_tag
|
||||
|
||||
push_and_publish latest
|
||||
|
||||
npm deprecate 'openzeppelin-solidity@>=4.0.0' "This package is now published as @openzeppelin/contracts. Please change your dependency."
|
||||
|
||||
log "Remember to merge the release branch into master and push upstream"
|
||||
|
||||
else
|
||||
log "Unknown command: '$*'"
|
||||
exit 1
|
||||
fi
|
||||
16
scripts/release/synchronize-versions.js
Executable file
16
scripts/release/synchronize-versions.js
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Synchronizes the version in contracts/package.json with the one in package.json.
|
||||
// This is run automatically when npm version is run.
|
||||
|
||||
const fs = require('fs');
|
||||
const cp = require('child_process');
|
||||
|
||||
setVersion('contracts/package.json');
|
||||
|
||||
function setVersion (file) {
|
||||
const json = JSON.parse(fs.readFileSync(file));
|
||||
json.version = process.env.npm_package_version;
|
||||
fs.writeFileSync(file, JSON.stringify(json, null, 2) + '\n');
|
||||
cp.execFileSync('git', ['add', file]);
|
||||
}
|
||||
34
scripts/release/update-changelog-release-date.js
Executable file
34
scripts/release/update-changelog-release-date.js
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Sets the release date of the current release in the changelog.
|
||||
// This is run automatically when npm version is run.
|
||||
|
||||
const fs = require('fs');
|
||||
const cp = require('child_process');
|
||||
|
||||
const suffix = process.env.PRERELEASE_SUFFIX || 'rc';
|
||||
|
||||
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
|
||||
|
||||
// The changelog entry to be updated looks like this:
|
||||
// ## Unreleased
|
||||
// We need to add the version and release date in a YYYY-MM-DD format, so that it looks like this:
|
||||
// ## 2.5.3 (2019-04-25)
|
||||
|
||||
const pkg = require('../../package.json');
|
||||
const version = pkg.version.replace(new RegExp('-' + suffix + '\\..*'), '');
|
||||
|
||||
const header = new RegExp(`^## (Unreleased|${version})$`, 'm');
|
||||
|
||||
if (!header.test(changelog)) {
|
||||
console.error('Missing changelog entry');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const newHeader = pkg.version.indexOf(suffix) === -1
|
||||
? `## ${version} (${new Date().toISOString().split('T')[0]})`
|
||||
: `## ${version}`;
|
||||
|
||||
fs.writeFileSync('CHANGELOG.md', changelog.replace(header, newHeader));
|
||||
|
||||
cp.execSync('git add CHANGELOG.md', { stdio: 'inherit' });
|
||||
35
scripts/release/update-comment.js
Executable file
35
scripts/release/update-comment.js
Executable file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require('fs');
|
||||
const proc = require('child_process');
|
||||
const semver = require('semver');
|
||||
const run = (cmd, ...args) => proc.execFileSync(cmd, args, { encoding: 'utf8' }).trim();
|
||||
|
||||
const gitStatus = run('git', 'status', '--porcelain', '-uno', 'contracts/**/*.sol');
|
||||
if (gitStatus.length > 0) {
|
||||
console.error('Contracts directory is not clean');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { version } = require('../../package.json');
|
||||
|
||||
// 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) {
|
||||
const current = fs.readFileSync(file, 'utf8');
|
||||
const updated = current.replace(
|
||||
/(\/\/ SPDX-License-Identifier:.*)$(\n\/\/ OpenZeppelin Contracts .*$)?/m,
|
||||
`$1\n// OpenZeppelin Contracts (last updated v${version}) (${file.replace('contracts/', '')})`,
|
||||
);
|
||||
fs.writeFileSync(file, updated);
|
||||
}
|
||||
|
||||
run('git', 'add', '--update', 'contracts');
|
||||
9
scripts/release/version.sh
Executable file
9
scripts/release/version.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
scripts/release/update-changelog-release-date.js
|
||||
scripts/release/synchronize-versions.js
|
||||
scripts/release/update-comment.js
|
||||
|
||||
oz-docs update-version
|
||||
Reference in New Issue
Block a user