diff --git a/.github/workflows/put-pull-requests-into-milestones.yml b/.github/workflows/put-pull-requests-into-milestones.yml new file mode 100644 index 0000000000000..6e35cff9af7e4 --- /dev/null +++ b/.github/workflows/put-pull-requests-into-milestones.yml @@ -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." diff --git a/.github/workflows/remind-hotfix-milestone.yml b/.github/workflows/remind-hotfix-milestone.yml new file mode 100644 index 0000000000000..512a47b5f465d --- /dev/null +++ b/.github/workflows/remind-hotfix-milestone.yml @@ -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 <}' 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 "
Release Review Thread skeleton" + 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: " + echo '```' + echo "" + echo "
" + echo "" + echo "
PRs merged into master in this range" + echo "" + echo '```' + printf '%s\n' "${PR_SUBJECTS}" | nl -ba -w 3 -s '. ' + echo '```' + echo "" + echo "
" + } >> "${GITHUB_STEP_SUMMARY}" + fi