Skip to content

[automated] Merge branch 'release/10.0' => 'main' #18

[automated] Merge branch 'release/10.0' => 'main'

[automated] Merge branch 'release/10.0' => 'main' #18

name: Auto-approve dependency-only codeflow PRs
on:
pull_request_target:
types: [opened, synchronize]
permissions:
pull-requests: write
jobs:
auto-approve-codeflow:
if: github.event.pull_request.user.login == 'dotnet-maestro[bot]'
runs-on: ubuntu-latest
steps:
- name: Validate and auto-approve
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
REPO="${GITHUB_REPOSITORY}"
PR="${PR_NUMBER}"
echo "Validating codeflow PR #${PR}..."
# Get all changed files with their patches
files_json=$(gh api "repos/${REPO}/pulls/${PR}/files" --paginate | jq -s 'add')
file_count=$(echo "$files_json" | jq 'length')
echo "PR modifies ${file_count} file(s)"
if [[ "$file_count" -eq 0 ]]; then
echo "::error::PR has no changed files"
exit 1
fi
for ((i = 0; i < file_count; i++)); do
filename=$(echo "$files_json" | jq -r ".[$i].filename")
status=$(echo "$files_json" | jq -r ".[$i].status")
patch=$(echo "$files_json" | jq -r ".[$i].patch // \"\"")
echo "::group::Validating ${filename}"
# 1. File must be in the allowed set
case "$filename" in
NuGet.config|eng/Version.Details.xml|eng/Version.Details.props|global.json)
;;
*)
echo "::error::File '${filename}' is not in the allowed set for dependency-only codeflow PRs"
exit 1
;;
esac
# 2. Only modified files are expected
if [[ "$status" != "modified" ]]; then
echo "::error::File '${filename}' has status '${status}' (expected 'modified')"
exit 1
fi
# 3. Patch data must be present
if [[ -z "$patch" ]]; then
echo "::error::File '${filename}' has no patch data"
exit 1
fi
# 4. Validate each changed line in the diff
while IFS= read -r line; do
[[ -z "$line" ]] && continue
# Only check added (+) and removed (-) lines
if [[ "$line" != +* && "$line" != -* ]]; then
continue
fi
# Get the content (strip the +/- prefix)
content="${line:1}"
# Skip empty/whitespace-only lines
if [[ "$content" =~ ^[[:space:]]*$ ]]; then
continue
fi
case "$filename" in
"eng/Version.Details.xml")
# Allowed: <Source> element with Sha/BarId, <Sha> elements, <Dependency> opening tags with Version
if [[ "$content" =~ ^[[:space:]]*\<Source[[:space:]]+Uri=\"https://github\.com/dotnet/dotnet\"[[:space:]]+Mapping=\"efcore\"[[:space:]]+Sha=\"[0-9a-f]+\"[[:space:]]+BarId=\"[0-9]+\"[[:space:]]*/\> ]]; then
:
elif [[ "$content" =~ ^[[:space:]]*\<Sha\>[0-9a-f]+\</Sha\> ]]; then
:
elif [[ "$content" =~ ^[[:space:]]*\<Dependency[[:space:]]+Name=\"[^\"]+\"[[:space:]]+Version=\"[^\"]+\" ]]; then
:
else
echo "::error::Unexpected change in ${filename}: ${content}"
exit 1
fi
;;
"eng/Version.Details.props")
# Allowed: package version property elements like <SomethingVersion>value</SomethingVersion>
if [[ "$content" =~ ^[[:space:]]*\<[A-Za-z0-9]+Version\>[^<]+\</[A-Za-z0-9]+Version\> ]]; then
:
else
echo "::error::Unexpected change in ${filename}: ${content}"
exit 1
fi
;;
"global.json")
# Allowed: msbuild-sdks version entries only
if [[ "$content" =~ ^[[:space:]]*\"Microsoft\.DotNet\.(Arcade|Helix)\.Sdk\":[[:space:]]*\"[^\"]+\" ]]; then
:
else
echo "::error::Unexpected change in ${filename}: ${content}"
exit 1
fi
;;
"NuGet.config")
# Allowed: darc-* package source entries pointing to Azure DevOps NuGet feeds
if [[ "$content" =~ ^[[:space:]]*\<add[[:space:]]+key=\"darc-[^\"]+\"[[:space:]]+value=\"https://pkgs\.dev\.azure\.com/dnceng/(public|internal)/_packaging/darc-[^\"]+/nuget/v3/index\.json\"[[:space:]]*/\> ]]; then
:
else
echo "::error::Unexpected change in ${filename}: ${content}"
exit 1
fi
;;
esac
done <<< "$patch"
echo " ✅ Validated"
echo "::endgroup::"
done
echo ""
echo "All files contain only expected dependency update changes."
echo "Approving PR..."
gh pr review "$PR" --repo "$REPO" --approve \
--body "Auto-approved: this codeflow PR contains only dependency version updates."