-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10516 from marmelab/release-tooling
[chore] Improve release tooling
- Loading branch information
Showing
9 changed files
with
918 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GITHUB_ACCESS_TOKEN=your_github_access_token |
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 |
---|---|---|
|
@@ -23,3 +23,4 @@ cypress/screenshots | |
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
.env |
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,98 @@ | ||
import 'dotenv/config'; | ||
import { Octokit } from '@octokit/core'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import escapeRegExp from 'lodash/escapeRegExp'; | ||
|
||
const main = async () => { | ||
if (process.env.RELEASE_DRY_RUN) { | ||
console.log('Dry run mode is enabled'); | ||
} | ||
|
||
if (!process.env.GITHUB_ACCESS_TOKEN) { | ||
console.error( | ||
'Please provide the GITHUB_ACCESS_TOKEN variable in the .env file' | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const version = process.argv[2]; | ||
|
||
if (!version || !version.match(/^\d{1,2}\.\d{1,2}\.\d{1,2}$/)) { | ||
console.error(`Invalid version provided: ${version}`); | ||
console.error('Usage: yarn run create-github-release <version>'); | ||
process.exit(1); | ||
} | ||
|
||
const tag_name = `v${version}`; | ||
|
||
const octokit = new Octokit({ | ||
auth: process.env.GITHUB_ACCESS_TOKEN, | ||
}); | ||
|
||
console.log(`Fetching latest releases`); | ||
const releases = await octokit.request( | ||
'GET /repos/{owner}/{repo}/releases', | ||
{ | ||
owner: 'marmelab', | ||
repo: 'react-admin', | ||
} | ||
); | ||
|
||
const alreadyExistingRelease = releases.data.find( | ||
release => release.tag_name === tag_name | ||
); | ||
|
||
if (alreadyExistingRelease) { | ||
console.log(`Release ${version} already exists.`); | ||
return; | ||
} | ||
|
||
console.log(`Parsing changelog for release ${version}`); | ||
|
||
// Read the changelog file | ||
const changelogFilePath = path.join(__dirname, '../CHANGELOG.md'); | ||
const changelogContent = fs.readFileSync(changelogFilePath, 'utf-8'); | ||
|
||
// Create a regular expression to capture the changelog entries for the specified version | ||
const safeVersion = escapeRegExp(version); | ||
const regex = new RegExp(`## ${safeVersion}\n\n([\\s\\S]*?)\n##`, 'g'); | ||
const match = regex.exec(changelogContent); | ||
|
||
if (!match) { | ||
console.error( | ||
`Could not find changelog entries for version ${version}` | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const changelogEntries = match[1].trim(); | ||
|
||
console.log(`Creating release ${version} from tag ${tag_name}`); | ||
|
||
if (process.env.RELEASE_DRY_RUN) { | ||
console.log( | ||
'Would have called GitHub API with', | ||
'POST /repos/{owner}/{repo}/releases', | ||
{ | ||
owner: 'marmelab', | ||
repo: 'react-admin', | ||
tag_name, | ||
name: version, | ||
body: changelogEntries, | ||
} | ||
); | ||
} else { | ||
await octokit.request('POST /repos/{owner}/{repo}/releases', { | ||
owner: 'marmelab', | ||
repo: 'react-admin', | ||
tag_name, | ||
name: version, | ||
body: changelogEntries, | ||
}); | ||
} | ||
|
||
console.log(`Release ${version} created successfully.`); | ||
}; | ||
|
||
main(); |
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,87 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
info() { | ||
echo -e "\033[1;34m$1\033[0m" | ||
} | ||
|
||
step() { | ||
echo "" | ||
info "$1" | ||
} | ||
|
||
if [ ! -z "$RELEASE_DRY_RUN" ]; then | ||
echo "Dry run mode is enabled" | ||
fi | ||
|
||
info "Starting the release process" | ||
|
||
step "make install" | ||
make install | ||
|
||
step "make build" | ||
make build | ||
|
||
step "manual tests: Run the EE tests" | ||
echo "Copy the the packages folder content inside the node_modules of ra-enterprise, then run a full build and run the tests" | ||
echo "Tip: You can use the 'copy-ra-oss-packages-to-ee.sh' script if you have it" | ||
echo "Press Enter when this is done" | ||
read | ||
|
||
step "manual tests: Run the demos" | ||
echo "Test the 3 demos (simple, e-commerce, crm): check console & UI" | ||
echo "Press Enter when this is done" | ||
read | ||
|
||
step "manual task: Update the create-react-admin dependencies" | ||
echo "[Minor version only] Update the dependencies to RA packages in the create-react-admin templates && commit" | ||
echo "Press Enter when this is done" | ||
read | ||
|
||
step "lerna version" | ||
./node_modules/.bin/lerna version --force-publish --no-push | ||
|
||
# Get the version from package.json | ||
npm_package_version=$(jq -r '.version' ./packages/react-admin/package.json) | ||
|
||
step "update-changelog" | ||
yarn run update-changelog ${npm_package_version} | ||
echo "Please review the ./CHANGELOG.md file and update it if needed." | ||
echo "Press Enter when this is done" | ||
read | ||
if [ -z "$RELEASE_DRY_RUN" ]; then | ||
echo "Committing the changelog" | ||
git add CHANGELOG.md | ||
git commit -m "Update changelog for version ${npm_package_version}" | ||
fi | ||
|
||
step "git push" | ||
if [ -z "$RELEASE_DRY_RUN" ]; then | ||
echo "Pushing commits and tags to git" | ||
git push origin HEAD | ||
git push origin --tags | ||
else | ||
echo "dry mode -- skipping git push" | ||
fi | ||
|
||
step "lerna publish" | ||
if [ -z "$RELEASE_DRY_RUN" ]; then | ||
# explicitly publish packages where the latest version is not present in the registry | ||
./node_modules/.bin/lerna publish from-package | ||
else | ||
echo "dry mode -- skipping lerna publish" | ||
fi | ||
|
||
step "update-milestones" | ||
yarn run update-milestones ${npm_package_version} | ||
|
||
step "create-github-release" | ||
yarn run create-github-release ${npm_package_version} | ||
|
||
step "manual step: Update the documentation" | ||
echo "You can use the 'copy-ra-oss-docs.sh' script if you have it" | ||
echo "Press Enter when this is done" | ||
read | ||
|
||
step "The release is done! 🎉" |
Oops, something went wrong.