Repository navigation
ci: assign merged pull requests to their release line's milestone #1619
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
306ad18
ci: assign merged pull requests to their release line's milestone
lklimek 0687e8b
ci: pick the next release's milestone from the latest stable release
lklimek d6e67d7
Merge branch 'dev' into ci/milestone-on-merge
lklimek 4a72e31
Merge remote-tracking branch 'origin/dev' into ci/milestone-on-merge
lklimek a52c607
fix(ci): validate release and milestone versions strictly
lklimek 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| name: Milestone on merge | ||
| # Assigns a pull request merged into the default branch to the milestone of the | ||
| # next release: the open vX.Y milestone with the lowest version above the latest | ||
| # stable release. With v1.8.2 released and v1.8, v2.0, v2.1 and v3.0 open, that | ||
| # is v2.0; once v2.0.0 is released it becomes v2.1. No list is maintained here. | ||
| on: | ||
| pull_request_target: | ||
| types: [closed] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| milestone: | ||
| if: >- | ||
| github.event.pull_request.merged == true && | ||
| github.event.pull_request.base.ref == github.event.repository.default_branch | ||
| runs-on: ubuntu-slim | ||
| timeout-minutes: 5 | ||
| steps: | ||
| # No checkout: only the API is used. | ||
| - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| const pr = context.payload.pull_request; | ||
| const { owner, repo } = context.repo; | ||
| const releaseTag = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/; | ||
| const milestoneTitle = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)$/; | ||
| const parse = (text, pattern) => { | ||
| const m = pattern.exec(text); | ||
| return m && m[0] === text && | ||
| { major: +m[1], minor: +m[2], patch: +(m[3] ?? 0) }; | ||
| }; | ||
| const compare = (a, b) => | ||
| a.major - b.major || a.minor - b.minor || a.patch - b.patch; | ||
|
|
||
| // Latest non-prerelease, non-draft release. | ||
| const { data: release } = await github.rest.repos.getLatestRelease({ owner, repo }); | ||
| const stable = parse(release.tag_name, releaseTag); | ||
| if (!stable) { | ||
| core.warning(`Latest release tag ${release.tag_name} is not vX.Y.Z; milestone of #${pr.number} left unchanged.`); | ||
| return; | ||
| } | ||
|
|
||
| // Next line: lowest open milestone whose major.minor is above the stable | ||
| // release, so the stable line's own milestones (v1.8, v1.8.3) are skipped. | ||
| const open = await github.paginate(github.rest.issues.listMilestones, { | ||
| owner, repo, state: 'open', per_page: 100, | ||
| }); | ||
| const candidates = open | ||
| .map((m) => ({ milestone: m, version: parse(m.title, milestoneTitle) })) | ||
| .filter(({ version }) => version && | ||
| compare({ ...version, patch: 0 }, { ...stable, patch: 0 }) > 0) | ||
| .sort((a, b) => compare(a.version, b.version)); | ||
| if (candidates.length === 0) { | ||
| core.warning(`No open milestone above ${release.tag_name}; milestone of #${pr.number} left unchanged.`); | ||
| return; | ||
| } | ||
| const { milestone } = candidates[0]; | ||
|
|
||
| if (pr.milestone?.number === milestone.number) { | ||
| core.info(`#${pr.number} is already in ${milestone.title}.`); | ||
| return; | ||
| } | ||
| if (pr.milestone) { | ||
| core.notice(`#${pr.number} moves from ${pr.milestone.title} to ${milestone.title}, the next release after ${release.tag_name}.`); | ||
| } | ||
| await github.rest.issues.update({ | ||
| owner, repo, issue_number: pr.number, milestone: milestone.number, | ||
| }); | ||
| core.info(`#${pr.number} assigned to ${milestone.title} (latest stable release ${release.tag_name}).`); | ||
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
Oops, something went wrong.
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.
🟡 Suggestion: Use the repository's existing github-script pin
This workflow pins actions/github-script to the v8.0.0 commit, while the existing workflow in .github/workflows/docker.yml uses the v9.0.0 commit. The pull request description says this action is pinned to the same SHA as existing workflows, and the repository's dependency bump history updates the shared action version together. Keeping a second pin creates a divergent convention that future Dependabot or maintenance updates must handle separately.
source:
glm-5.3-flash(phase1-reviewer: general)