Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/put-pull-requests-into-milestones.yml
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."

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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 '.'?

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."
40 changes: 40 additions & 0 deletions .github/workflows/remind-hotfix-milestone.yml
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
)"
117 changes: 117 additions & 0 deletions .github/workflows/rotate-release-milestone.yml
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
Loading