-
Notifications
You must be signed in to change notification settings - Fork 67
chore(release): add update milestones script #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShGKme
wants to merge
1
commit into
main
Choose a base branch
from
chore/post-release-milestones
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,124 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| const { blue, green, yellow, gray, red } = chalk | ||
|
|
||
| const confirm = async (message) => { | ||
| if (!argv.y && await question(yellow(`${message} (y/N)`)) !== 'y') { | ||
| process.exit(0) | ||
| } | ||
| } | ||
|
|
||
| if (os.platform() === 'win32') { | ||
| usePwsh() | ||
| } | ||
|
|
||
| // Verify that GitHub CLI is available and authenticated | ||
| await $`gh auth status` | ||
|
|
||
| /******** | ||
| * Help * | ||
| ********/ | ||
|
|
||
| if (argv.help) { | ||
| echo`Update milestones after the release: | ||
| 1. Renames the current milestone to the release milestone (Next Release -> v1.2.3) | ||
| 2. Creates the next milestone as a replacement for the current (Next Release) | ||
| 3. Moves all open issues and PRs from the current=release milestone to the new milestone (v1.2.3 -> Next Release) | ||
| 4. Closes the current=release milestone | ||
|
|
||
| USAGE: | ||
| npm run post-release:milestones | ||
| npm run post-release:milestones -- -y --current="🪴 Next Release" --release="v1.2.3" --next="🌵 Next Release" | ||
|
|
||
| ARGS: | ||
| --help - show help | ||
| -y - skip confirmation | ||
| --current - Optionally the current milestone to rename. Default is "🪴 Next Release". | ||
| --release - Optionally the release version to rename the source milestone to. Default is the v + package.json version. | ||
| --next - Optionally the new milestone to create. Default is --source, which is "🪴 Next Release". | ||
| ` | ||
| process.exit(0) | ||
| } | ||
|
|
||
| // Read the package.json | ||
| const packageJson = await fs.readJson(path.join(__dirname, '../package.json')) | ||
| // Read args with defaults | ||
| const currentMilestone = argv.current ?? '🪴 Next Release' | ||
| const releaseMilestone = argv.release ?? 'v' + packageJson.version | ||
| const nextMilestone = argv.next ?? currentMilestone | ||
|
|
||
| const { nameWithOwner, milestones } = await $`gh repo view --json nameWithOwner,milestones`.json() | ||
| echo(blue(`Maintain milestones after a release in ${nameWithOwner}`)) | ||
|
|
||
| /************************************** | ||
| * 1. Rename (Next Release -> v1.2.3) * | ||
| **************************************/ | ||
|
|
||
| const existingCurrentMilestone = milestones.find((milestone) => milestone.title === currentMilestone) | ||
| const existingReleaseMilestone = milestones.find((milestone) => milestone.title === releaseMilestone) | ||
|
|
||
| echo`1. Renaming milestone '${blue(currentMilestone)}' to '${blue(releaseMilestone)}'` | ||
| if (existingReleaseMilestone) { | ||
| echo(yellow(` Skipping: milestone '${blue(releaseMilestone)}' already exists`)) | ||
| } else if (existingCurrentMilestone) { | ||
| await confirm(` Rename milestone '${blue(currentMilestone)}' to '${blue(releaseMilestone)}'?`) | ||
| await $`gh api 'repos/{owner}/{repo}/milestones/${existingCurrentMilestone.number}' --method PATCH --field title=${releaseMilestone}` | ||
| existingCurrentMilestone.title = releaseMilestone | ||
| echo(green(` Renamed milestone '${blue(currentMilestone)}' to '${blue(releaseMilestone)}'`)) | ||
| } else { | ||
| echo(red(`Error: neither milestone '${blue(currentMilestone)}' nor '${blue(releaseMilestone)}' exist`)) | ||
| process.exit(1) | ||
| } | ||
|
|
||
| /******************************** | ||
| * 2. Create new 'Next Release' * | ||
| ********************************/ | ||
|
|
||
| const existingNextMilestone = milestones.find((milestone) => milestone.title === nextMilestone) | ||
|
|
||
| echo`2. Create a new milestone '${blue(nextMilestone)}'` | ||
| if (existingNextMilestone) { | ||
| echo(yellow(` Skipping: the next milestone '${blue(nextMilestone)}' already exists`)) | ||
| } else { | ||
| await confirm(` Create a new milestone '${blue(nextMilestone)}'?`) | ||
| await $`gh api '/repos/{owner}/{repo}/milestones' --method POST --field title=${nextMilestone}` | ||
| echo(green(` Created a new milestone '${blue(nextMilestone)}'`)) | ||
| } | ||
|
|
||
| /****************************************** | ||
| * 3. Move items (v1.2.3 -> Next Release) * | ||
| ******************************************/ | ||
|
|
||
| echo`3. Moving all issues and PRs to ${blue(nextMilestone)}` | ||
|
|
||
| const issues = await $`gh issue list --state=open --milestone=${releaseMilestone} --json=number,title --limit=1000`.json() | ||
| const prs = await $`gh pr list --state=open --search='milestone:"${releaseMilestone}"' --json=number,title --limit=1000`.json() | ||
| echo(gray(` Found ${issues.length} issues and ${prs.length} PRs:`)) | ||
| echo(gray(prs.map((pr) => ` - PR #${pr.number}: ${pr.title}`).join('\n'))) | ||
| echo(gray(issues.map((issue) => ` - Issue #${issue.number}: ${issue.title}`).join('\n'))) | ||
|
|
||
| await confirm(` Move ${issues.length + prs.length} items to '${blue(nextMilestone)}'?`) | ||
| // Sleep for a bit to avoid rate limiting (90 requests per minute) | ||
| await spinner(yellow(' Moving...'), async () => { | ||
| for (const issue of issues) { | ||
| await $`gh issue edit ${issue.number} --milestone=${nextMilestone}` | ||
| await sleep(100) | ||
| } | ||
| for (const pr of prs) { | ||
| await $`gh pr edit ${pr.number} --milestone=${nextMilestone}` | ||
| await sleep(100) | ||
| } | ||
| }) | ||
| echo(green(` ${issues.length + prs.length} items moved to '${blue(nextMilestone)}'`)) | ||
|
|
||
| /******************************* | ||
| * 4. Close milestone (v1.2.3) * | ||
| *******************************/ | ||
|
|
||
| echo`4. Closing milestone '${blue(releaseMilestone)}'` | ||
| await confirm(` Close milestone '${blue(releaseMilestone)}'?`) | ||
| await $`gh api 'repos/{owner}/{repo}/milestones/${existingReleaseMilestone.number}' --method PATCH --field state=closed` | ||
| echo(green(` Closed milestone '${releaseMilestone}'`)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you're using it later in step 4: