Skip to content

Commit

Permalink
ci: Add milestone workflow (#3887)
Browse files Browse the repository at this point in the history
This is a GitHub Actions based alternative to the milestone bot that we run. The actions setup will

- When a PR is opened or reopened, and has no milestone associated, it will assign the `next` milestone
- When a PR is milestoned or demilestoned, it will add a status to the PR like the current bot does it.

This should allow us to require a milestone to be set before merging, without having to host the bot anymore.
  • Loading branch information
paulgessinger authored Nov 21, 2024
1 parent 3a033ae commit ca44b3f
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/milestone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Check PR milestone

on:
pull_request_target:
types: [milestoned, demilestoned, opened, reopened]
branches:
- main

jobs:
check_milestone:
if: ${{ github.event.issue.pull_request || github.event.pull_request }}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: "Check for milestone on PR"
uses: actions/github-script@v7
with:
script: |
let milestone = context.payload.pull_request.milestone;
if(context.payload.action === 'opened' || context.payload.action === 'reopened') {
if(milestone !== null) {
core.notice(`Milestone is ${milestone.title}`);
} else {
const milestones = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open"
});
for (const default_milestone of milestones.data) {
if (default_milestone.title === "next") {
core.notice(`No milestone set, setting default milestone: ${default_milestone.title}`);
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
milestone: default_milestone.number
});
return;
}
}
core.warning("Could not find default milestone named 'next'");
}
}
else {
if(milestone !== null) {
core.notice(`Milestone is ${milestone.title}`);
} else {
core.setFailed("No milestone: Please add a version milestone");
}
}

0 comments on commit ca44b3f

Please sign in to comment.