Repository navigation
GHA for putting PR into milestone and for staging cutoff #46703
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
Fildrance
wants to merge
8
commits into
space-wizards:master
Choose a base branch
from
Fildrance:feature/put-prs-into-milestones
base: master
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.
+210
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dfc2014
feat: GHA for putting batches of PRs from SHA range into milestone
Fildrance 72f87ba
refactor: add PR into milestone on merge
Fildrance c4ddbcb
refactor: account for CONTAINS not equal to YYYY.MM in milestone name
Fildrance 363ee3d
feat: cutoff github action
Fildrance 20e4ca7
Merge branch 'master' into feature/put-prs-into-milestones
Fildrance 8108bde
refactor: add notice for stable / staging
Fildrance 0614b1a
refactor: whitespaces
Fildrance ed25062
Apply suggestion from @kontakt
Fildrance 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,53 @@ | ||
| name: Assign merged PRs to release milestone | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [ closed ] | ||
|
|
||
| permissions: | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| assign: | ||
| name: Assign PR to latest release milestone | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master' }} | ||
| steps: | ||
| - name: Assign PR to latest open release milestone | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| set -euo pipefail | ||
| export LC_ALL=C | ||
|
|
||
| # A release milestone carries the release date in its title, we search for pattern: `*YYYY-MM` | ||
| MILESTONES=$(gh api --paginate "repos/${REPO}/milestones?state=open&per_page=100" \ | ||
| --jq '.[] | "\(.title)\t\(.number)"' \ | ||
| | awk -F'\t' ' | ||
| match($1, /[0-9][0-9][0-9][0-9][.-][0-9][0-9]/) { | ||
| month = substr($1, RSTART, 7) | ||
| gsub(/-/, ".", month) | ||
| hotfix = 0 | ||
| tail = substr($1, RSTART + 7) | ||
| if (match(tail, /-v[0-9]+/)) | ||
| hotfix = substr(tail, RSTART + 2) + 0 | ||
| printf "%s-%04d\t%s\n", month, hotfix, $2 | ||
| }' \ | ||
| | sort -r) | ||
|
|
||
| LATEST_MILESTONE="${MILESTONES%%$'\n'*}" | ||
|
|
||
| if [[ -z "${LATEST_MILESTONE}" ]]; then | ||
| echo "::warning::No open release milestone (a title containing a YYYY.MM date) found in ${REPO}, PR #${PR_NUMBER} was not assigned to a milestone." | ||
| exit 0 | ||
| fi | ||
|
|
||
| MILESTONE_NUMBER="${LATEST_MILESTONE##*$'\t'}" | ||
|
|
||
| gh api --method PATCH "repos/${REPO}/issues/${PR_NUMBER}" \ | ||
| -F milestone="${MILESTONE_NUMBER}" >/dev/null | ||
|
|
||
| echo "Done." | ||
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,40 @@ | ||
| name: Remind hotfix PRs to assign a milestone manually | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [ closed ] | ||
| branches: [ staging, stable ] | ||
|
|
||
| permissions: | ||
| issues: write | ||
|
|
||
| jobs: | ||
| remind: | ||
| name: Comment with milestone reminder | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.pull_request.merged == true }} | ||
| steps: | ||
| - name: Remind PR author to assign a release milestone | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| gh pr comment "${PR_NUMBER}" --repo "${REPO}" --body "$(cat <<EOF | ||
| This PR was merged into \`${BASE_BRANCH}\` and was not automatically assigned to a release milestone. | ||
|
|
||
| Please add it to the appropriate milestone manually: | ||
|
|
||
| **For the staging branch:** | ||
| Use the latest closed milestone (by date in its name). | ||
|
|
||
| **For the stable branch:** | ||
| - If hotfixing a release that has not yet been published, use the same milestone as other PRs in the release. | ||
| - If hotfixing an already published release (creating a new release), create a new milestone, assign only this PR to it, and close the milestone. (look at release procedure for milestone naming) | ||
|
|
||
| **Important:** Do not reopen closed milestones. You can assign PRs to closed milestones directly. | ||
| EOF | ||
| )" |
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,117 @@ | ||
| name: Staging cutoff | ||
|
|
||
| # Merges master into stable, and rotates the release milestones | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| new_milestone: | ||
| description: "Title of next release milestone to open (for all new PRs after cutoff), e.g. wizards-2026.12-v1" | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: write | ||
| issues: write | ||
|
|
||
| concurrency: | ||
| group: rotate-release-milestone | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| rotate: | ||
| name: Do staging cutoff, rotate release milestones | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| RELEASE_BRANCH: staging | ||
| steps: | ||
| - name: Checkout the release branch | ||
| uses: actions/checkout@v7 | ||
| with: | ||
| ref: staging | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Cut and rotate | ||
| env: | ||
| # Pushes with the default token are attributed to `github-actions` and can be | ||
| # blocked by branch protection, so prefer the token the publish workflow uses. | ||
| GH_TOKEN: ${{ secrets.CL_ACCESS_TOKEN || github.token }} | ||
| REPO: ${{ github.repository }} | ||
| NEW_TITLE: ${{ inputs.new_milestone }} | ||
| run: | | ||
| set -euo pipefail | ||
| export LC_ALL=C | ||
|
|
||
| git config user.name "Space-Wizards-Bot" | ||
| git config user.email "bot@spacestation14.com" | ||
|
|
||
| # A release milestone carries its release date in the title in format of `*YYYY.MM*`, | ||
| OPEN=$(gh api --paginate "repos/${REPO}/milestones?state=open&per_page=100" \ | ||
| --jq '.[] | "\(.title)\t\(.number)"' \ | ||
| | awk -F'\t' 'match($1, /[0-9][0-9][0-9][0-9][.-][0-9][0-9]/)') | ||
|
|
||
| OPEN_COUNT=$(printf '%s' "${OPEN}" | grep -c . || true) | ||
| if [[ "${OPEN_COUNT}" -gt 1 ]]; then | ||
| echo "::error::Found ${OPEN_COUNT} open release milestones (with *YYYY.MM* pattern in name), expected at most one - close or rename the extra ones first:" | ||
| printf '%s\n' "${OPEN}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| CURRENT_TITLE=$(printf '%s\n' "${OPEN}" | head -n 1 | cut -f1) | ||
| CURRENT_NUMBER=$(printf '%s\n' "${OPEN}" | head -n 1 | cut -f2) | ||
|
|
||
| OLDEST=$(git rev-parse HEAD) | ||
| git fetch --no-tags origin "master:refs/remotes/origin/master" | ||
| NEWEST=$(git rev-parse origin/master) | ||
|
|
||
| if git merge-base --is-ancestor "${NEWEST}" "${OLDEST}"; then | ||
| echo "::error::Nothing to cut: master (${NEWEST}) is already part of '${RELEASE_BRANCH}', so this run would do nothing. Nothing was pushed and no milestone was touched; if the cut has been done by hand already, rotate the milestones by hand too: close '${CURRENT_TITLE:-<current release milestone>}' and open '${NEW_TITLE}'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # A conflict aborts the merge and the job | ||
| git merge --no-ff -m "Merge master into ${RELEASE_BRANCH} for ${NEW_TITLE}" origin/master | ||
| git -c http.https://github.com/.extraheader= \ | ||
| push "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" \ | ||
| "HEAD:refs/heads/${RELEASE_BRANCH}" | ||
| echo "Merged master into '${RELEASE_BRANCH}' and pushed." | ||
|
|
||
| # Open the new milestone | ||
| NEW_NUMBER=$(gh api --method POST "repos/${REPO}/milestones" \ | ||
| -f title="${NEW_TITLE}" -f state=open --jq '.number') | ||
| echo "Created milestone '${NEW_TITLE}' (#${NEW_NUMBER})." | ||
|
|
||
| # Close the current milestone | ||
| if [[ -n "${CURRENT_NUMBER}" ]]; then | ||
| gh api --method PATCH "repos/${REPO}/milestones/${CURRENT_NUMBER}" -f state=closed >/dev/null | ||
| echo "Closed milestone '${CURRENT_TITLE}' (#${CURRENT_NUMBER})." | ||
| else | ||
| echo "No open release milestone found, so nothing was closed." | ||
| fi | ||
|
|
||
| # Report the commit range and the PRs shipping in this release | ||
| if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then | ||
| PR_SUBJECTS=$(git log --first-parent --reverse --pretty=format:'%s' "${OLDEST}..${NEWEST}") | ||
| PR_COUNT=$(printf '%s\n' "${PR_SUBJECTS}" | grep -c . || true) | ||
|
|
||
| { | ||
| echo "<details><summary>Release Review Thread skeleton</summary>" | ||
| echo "" | ||
| echo '```' | ||
| echo "YYYY-MM-DD Release Review Thread" | ||
| echo "commit range: ${OLDEST} - ${NEWEST}" | ||
| echo "compare: https://github.com/${REPO}/compare/${OLDEST}...${NEWEST}" | ||
| echo "outline doc: <link to the Outline doc>" | ||
| echo '```' | ||
| echo "" | ||
| echo "</details>" | ||
| echo "" | ||
| echo "<details><summary>PRs merged into master in this range</summary>" | ||
| echo "" | ||
| echo '```' | ||
| printf '%s\n' "${PR_SUBJECTS}" | nl -ba -w 3 -s '. ' | ||
| echo '```' | ||
| echo "" | ||
| echo "</details>" | ||
| } >> "${GITHUB_STEP_SUMMARY}" | ||
| fi |
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.
You're searching both YYYY.MM and YYYY-MM?
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.
Eh, at some point i thought that we should not fail if person just messed up format a tiny-little bit. But i see flaws within this logic.
Considering we will be going for milestone using same-ish name as tag version we want - we probably should go with only '.'?