Skip to content

[release/9.0.1xx] [Github Actions] Remove Branch Lockdown Labels on Branding Merge #48181

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
wants to merge 8 commits into
base: release/9.0.1xx
Choose a base branch
from
Open
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
74 changes: 74 additions & 0 deletions .github/workflows/remove-lockdown-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Remove Lockdown Label from PRs

on:
pull_request:
types: [closed]

permissions:
actions: write
pull-requests: write

jobs:
remove-labels:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'Branding')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: PR's only change is <VersionFeature> in eng/Versions.props
id: only_version_feature_changed
uses: actions/github-script@v4
with:
script: |
const otherChangesMessage = "❌ Changes in eng/Versions.props other than <VersionFeature> found";
const onlyVersionFeatureMessage = "✅ PR's only change is <VersionFeature> in eng/Versions.props";
const prNumber = context.payload.pull_request.number;
const { data: files } = await github.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
// If files other than eng/Versions.props are changed, output message and exit
if (files.some(file => file.filename !== "eng/Versions.props")) {
console.log(otherChangesMessage);
core.exportVariable("only_version_feature_changed", "false");
return;
}
// Iterate through the patch of eng/Versions.props to check for changes other than <VersionFeature>
const versionsPropsFile = files.find(file => file.filename === "eng/Versions.props");
const patchLines = versionsPropsFile.patch.split("\n").filter(l => l.startsWith("+") || l.startsWith("-"));
for (const line of patchLines) {
if (!line.includes("<VersionFeature>")) {
console.log(otherChangesMessage);
core.exportVariable("only_version_feature_changed", "false");
return;
}
}
console.log(onlyVersionFeatureMessage);
core.exportVariable("only_version_feature_changed", "true");

- name: Remove Branch Lockdown label from other PRs targeting this branch
if: steps.only_version_feature_changed.outputs.only_version_feature_changed == 'true'
uses: actions/github-script@v4
with:
script: |
const prs = await github.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
base: github.event.pull_request.base.ref,
per_page: 300
});
const filtered_prs = prs.data
.filter(pr => pr.number !== github.context.payload.pull_request.number)
.filter(pr => pr.labels.map(label => label.name).includes('Branch Lockdown'));
for (const pr of filtered_prs) {
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: 'Branch Lockdown'
});
console.log(`Removed Branch Lockdown label from PR #${pr.number}`);
}
Loading