TP-52884 | Validate Release PR Fixes (#9642)

This commit is contained in:
Shivam Goyal
2024-02-06 01:57:25 +05:30
committed by GitHub
parent 845e3a3432
commit 9420409793

View File

@@ -15,10 +15,14 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up PR Number
if: always()
run: |
echo "ORIGINAL_PR_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -o "https://github.com/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")" >> $GITHUB_ENV
echo "CURRENT_PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Verification Step 1 - Link to development PR is added in release PR Body
if: always()
run: |
ORIGINAL_PR_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -o "https://github.com/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
ORIGINAL_PR_URL="https://github.com/${{ github.repository }}/pull/$ORIGINAL_PR_NUMBER"
echo "Original PR Number extracted: $ORIGINAL_PR_NUMBER"
@@ -32,7 +36,6 @@ jobs:
- name: Verification Step 2 - release PR Title matches development PR Title
if: always()
run: |
ORIGINAL_PR_NUMBER=$(echo ${{ github.event.pull_request.body }} | grep -o "https://github.com/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
ORIGINAL_PR_TITLE=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r .title)
echo "PR Number extracted: $ORIGINAL_PR_NUMBER"
@@ -46,7 +49,6 @@ jobs:
- name: Verification Step 3 - development PR is Merged
if: always()
run: |
ORIGINAL_PR_NUMBER=$(echo ${{ github.event.pull_request.body }} | grep -o "https://github.com/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
ORIGINAL_PR_IS_MERGED=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r '.merged')
BASE_REF_BRANCH=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r '.base.ref')
@@ -59,36 +61,38 @@ jobs:
echo "Status: Fail. Original PR is not merged in development branch."
exit 1
fi
- name: Verification Step 4 - release PR is subset of development PR
- name: Verification Step 4 - release PR is exactly same as development PR
if: always()
run: |
ORIGINAL_PR_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -o "https://github.com/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
ORIGINAL_PR_COMMITS=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER/commits" | jq -r '.[].sha')
ORIGINAL_PR_FILES=()
for COMMIT_SHA in $ORIGINAL_PR_COMMITS; do
COMMIT_FILES=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/commits/$COMMIT_SHA" | jq -r '.files[].filename')
ORIGINAL_PR_FILES+=($COMMIT_FILES)
done
ORIGINAL_PR_FILES=$(echo "${ORIGINAL_PR_FILES[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
# Get the JSON response for the first pull request
response_pr_development=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER/files")
files_pr_development=$(echo "$response_pr_development" | jq -r '.[].filename')
# Get the JSON response for the second pull request
response_pr_release=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$CURRENT_PR_NUMBER/files")
files_pr_release=$(echo "$response_pr_release" | jq -r '.[].filename')
echo "Original PR number extracted: $ORIGINAL_PR_NUMBER"
echo "Original PR commits: $ORIGINAL_PR_COMMITS"
echo "Original PR files: $ORIGINAL_PR_FILES"
CURRENT_PR_NUMBER="${{ github.event.pull_request.number }}"
CURRENT_PR_COMMITS=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$CURRENT_PR_NUMBER/commits" | jq -r '.[].sha')
CURRENT_PR_FILES=()
for COMMIT_SHA in $CURRENT_PR_COMMITS; do
COMMIT_FILES=$(curl -L -H "Authorization: Bearer ${{ secrets.GH_PAT_RO }}" "https://api.github.com/repos/${{ github.repository }}/commits/$COMMIT_SHA" | jq -r '.files[].filename')
CURRENT_PR_FILES+=($COMMIT_FILES)
done
CURRENT_PR_FILES=$(echo "${CURRENT_PR_FILES[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
echo "Current PR number: $CURRENT_PR_NUMBER"
echo "Current PR commits: $CURRENT_PR_COMMITS"
echo "Current PR files: $CURRENT_PR_FILES"
if [[ ! "$ORIGINAL_PR_FILES" =~ (^|[[:space:]])"$CURRENT_PR_FILES"($|[[:space:]]) ]]; then
echo "Current pull request changes are not a strict subset of original pull request changes"
# Compare the lists of changed files
if [ "$files_pr_development" != "$files_pr_release" ]; then
echo "Pull requests have different sets of changed files."
exit 1
fi
# Loop through each file and compare added and deleted lines
for file in $details_pr_development; do
details_pr_development=($(echo "$response_pr_development" | jq -r --arg file "$file" '.[] | select(.filename == $file) | .additions, .deletions'))
details_pr_release=($(echo "$response_pr_release" | jq -r --arg file "$file" '.[] | select(.filename == $file) | .additions, .deletions'))
added_lines_pr_development="${details_pr_development[0]}"
deleted_lines_pr_development="${details_pr_development[1]}"
added_lines_pr_release="${details_pr_release[0]}"
deleted_lines_pr_release="${details_pr_release[1]}"
if [ "$added_lines_pr_development" != "$added_lines_pr_release" ] || [ "$deleted_lines_pr_development" != "$deleted_lines_pr_release" ]; then
echo "File $file has different added or deleted lines in the two pull requests."
exit 1
fi
done
echo "The pull requests have the same changes."