Skip to content

Commit e5a8ab0

Browse files
edvilmegithub-actions
authored andcommitted
Update diff with js
1 parent ef7c821 commit e5a8ab0

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

.github/workflows/remove-lockdown-label.yml

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,36 @@ jobs:
1515
steps:
1616
- name: Checkout repository
1717
uses: actions/checkout@v2
18-
- name: PR's only change is <VersionFeature> in eng/Versions.props
19-
run: |
20-
git fetch --depth=2
21-
changes=$(git diff HEAD^ HEAD -- eng/Versions.props | grep '^[-+]')
22-
changes_without_version_feature=$(echo "$changes" | grep -v '<VersionFeature>')
23-
has_changes_without_version_feature=$(echo "$changes_without_version_feature" | wc -l)
24-
if [ "$has_changes_without_version_feature" -eq 0 ]; then
25-
echo "only_version_feature_changed=true" >> $GITHUB_ENV
26-
echo "✅ Only change in eng/Versions.props is <VersionFeature>"
27-
else
28-
echo "only_version_feature_changed=false" >> $GITHUB_ENV
29-
echo "❌ Changes in eng/Versions.props other than <VersionFeature> found"
18+
19+
# flagged user-visible change: replaced shell script with JS to check <VersionFeature>user-visible change: replaced shell script with JS to check <VersionFeature>
20+
- name: PR's only change is <VersionFeature> in eng/Versions.propsly change is <VersionFeature> in eng/Versions.props
21+
uses: actions/github-script@v4
22+
with:
23+
script: |
24+
const prNumber = context.payload.pull_request.number;
25+
const { data: files } = await github.pulls.listFiles({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo, repo: context.repo.repo,
28+
pull_number: prNumber
29+
});
30+
// If files other than eng/Versions.props are changed, output message and exit
31+
if (files.any(file => file.filename !== "eng/Versions.props")) {
32+
console.log("❌ Changes in eng/Versions.props other than <VersionFeature> found");
33+
core.exportVariable("only_version_feature_changed", "false");
34+
return;
35+
}
36+
// Iterate through the patch of eng/Versions.props to check for changes other than <VersionFeature>
37+
const versionsPropsFile = files.find(file => file.filename === "eng/Versions.props");
38+
const patchLines = versionsPropsFile.patch.split("\n").filter(l => l.startsWith("+") || l.startsWith("-"));
39+
for (const line of patchLines) {
40+
if (!line.includes("<VersionFeature>")) {
41+
console.log("❌ Changes in eng/Versions.props other than <VersionFeature> found");
42+
core.exportVariable("only_version_feature_changed", "false");
43+
return;
44+
}
45+
}
46+
console.log("✅ PR's only change is <VersionFeature> in eng/Versions.props");
47+
core.exportVariable("only_version_feature_changed", "true");
3048
3149
- name: Remove Branch Lockdown label from other PRs targeting this branch
3250
if: steps.PR_has_Branding_label.outputs.has_branding_label == 'true' && steps.PR_only_change_is_VersionFeature_in_eng_Versions_props.outputs.only_version_feature_changed == 'true'

0 commit comments

Comments
 (0)