Skip to content
Draft
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
73 changes: 62 additions & 11 deletions .github/workflows/valid-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,67 @@ jobs:
PR_URL: ${{ github.event.pull_request.url }}
run: ./.github/workflows/scripts/pr-check-checklist.sh

validate-milestone:
name: Milestone
validate-branch-milestone:
name: Branch Milestone
runs-on: ubuntu-latest
steps:
- name: Validate milestone
if: github.event.pull_request.milestone == null
run: |
echo "PR does not have a milestone"
exit 1

- name: Milestone Found
if: github.event.pull_request.milestone != null
run: echo "PR has a milestone"
- name: Checkout Repository
uses: actions/checkout@v5
# We only need to fetch the file on the default branch (where it usually lives)
# to ensure we get the latest configuration file.
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 1

- name: Check PR Milestone against Branch Config
uses: actions/github-script@v7
id: milestone-check
with:
script: |
const fs = require('fs');

// 1. Define the path to your configuration file
const configFilePath = 'branches-metadata.json';

// 2. Get the PR details
const prTargetBranch = context.payload.pull_request.base.ref;
const prMilestone = context.payload.pull_request.milestone;

if (!prMilestone) {
core.setFailed(`❌ Pull Request must have a milestone assigned.`);
return;
}

const prMilestoneTitle = prMilestone.title;
core.info(`Target Branch: ${prTargetBranch}`);
core.info(`PR Milestone: ${prMilestoneTitle}`);

// 3. Load and parse the configuration file
let config;
try {
const configFileContent = fs.readFileSync(configFilePath, 'utf8');
config = JSON.parse(configFileContent);
} catch (error) {
core.setFailed(`❌ Failed to read or parse config file at ${configFilePath}: ${error.message}`);
return;
}

// 4. Look up the expected milestone for the target branch
const branchConfig = config.branches[prTargetBranch];

if (!branchConfig) {
// If the branch is not found in the config, it might be a new or unsupported branch.
// You can choose to fail here or allow it. Allowing it by default for flexibility.
core.warning(`⚠️ Target branch '${prTargetBranch}' not found in the config file. Skipping milestone check.`);
return;
}

const expectedMilestone = branchConfig.milestone;
core.info(`Expected Milestone for branch '${prTargetBranch}': ${expectedMilestone}`);

// 5. Compare the milestones
if (prMilestoneTitle === expectedMilestone) {
core.info(`✅ Milestone '${prMilestoneTitle}' matches the expected branch milestone '${expectedMilestone}'.`);
} else {
core.setFailed(`❌ Pull Request milestone '${prMilestoneTitle}' does not match the expected milestone '${expectedMilestone}' for the target branch '${prTargetBranch}'. Please update the PR milestone.`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
core.setFailed(`❌ Pull Request milestone '${prMilestoneTitle}' does not match the expected milestone '${expectedMilestone}' for the target branch '${prTargetBranch}'. Please update the PR milestone.`);
core.setFailed(`❌ Pull Request milestone '${prMilestoneTitle}' does not match the required milestone '${expectedMilestone}' for the target branch '${prTargetBranch}'`);

}
46 changes: 46 additions & 0 deletions branches-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"branches": {
"master": {
"milestone": "v2.14.0",
"e2e": {
"docker-image": "rancher/rancher:head"
},
"rancher-rancher-repo": {
"main": {
"settings": {
"ui-dashboard-index": "https://releases.rancher.com/dashboard/latest/index.html",
"ui-index": "https://releases.rancher.com/ui/latest2/index.html"
}
}
}
},
"release-2.13": {
"milestone": "v2.13.1",
"e2e": {
"docker-image": "rancher/rancher:release-2.13"
},
"rancher-rancher-repo": {
"main": {
"settings": {
"ui-dashboard-index": "https://releases.rancher.com/dashboard/release-2.13/index.html",
"ui-index": "https://releases.rancher.com/ui/release-2.13/index.html"
}
}
}
},
"release-2.12": {
"milestone": "v2.12.5",
"e2e": {
"docker-image": "rancher/rancher:release-2.12"
},
"rancher-rancher-repo": {
"main": {
"settings": {
"ui-dashboard-index": "https://releases.rancher.com/dashboard/release-2.12/index.html",
"ui-index": "https://releases.rancher.com/ui/release-2.12/index.html"
}
}
}
}
}
}
Loading