Files
super-app/.github/workflows/release-pr.yml
2025-06-12 07:05:51 +00:00

120 lines
5.9 KiB
YAML

name: Release PR CI
on:
pull_request:
branches: [ release-* ]
types: [ opened, reopened, synchronize, ready_for_review, converted_to_draft ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
build:
if: github.event.pull_request.draft == false
uses: ./.github/workflows/generate-build-and-run-unit-tests.yml
with:
environment: qa
type: debug
output: APK
secrets: inherit
compare-master-pr:
runs-on: [ default ]
steps:
- name: Create GitHub App Token
uses: navi-synced-actions/actions-create-github-app-token@v1
id: get-token
with:
private-key: ${{ secrets.GH_APP_NAVI_ANDROID_PEM }}
app-id: ${{ secrets.GH_APP_NAVI_ANDROID_ID }}
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up PR Number
if: always()
run: |
CURRENT_PR_BODY=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq -r '.body')
echo "CURRENT_PR_BODY: $CURRENT_PR_BODY"
echo "CURRENT_PR_BODY=$CURRENT_PR_BODY" >> $GITHUB_ENV
CURRENT_PR_NUMBER=${{ github.event.pull_request.number }}
echo "CURRENT_PR_NUMBER: $CURRENT_PR_NUMBER"
echo "CURRENT_PR_NUMBER=$CURRENT_PR_NUMBER" >> $GITHUB_ENV
ORIGINAL_PR_NUMBER=$(echo $CURRENT_PR_BODY | grep -o "https://github.com/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
echo "ORIGINAL_PR_NUMBER: $ORIGINAL_PR_NUMBER"
echo "ORIGINAL_PR_NUMBER=$ORIGINAL_PR_NUMBER" >> $GITHUB_ENV
- name: Verification Step 1 - link to master PR is added in release PR body
if: always()
run: |
ORIGINAL_PR_URL="https://github.com/${{ github.repository }}/pull/$ORIGINAL_PR_NUMBER"
echo "ORIGINAL_PR_URL: $ORIGINAL_PR_URL"
if [[ "$CURRENT_PR_BODY" != *"$ORIGINAL_PR_URL"* ]]; then
echo "Link to original PR raised against master branch not found in current PR body"
exit 1
fi
- name: Verification Step 2 - release PR title matches master PR title
if: always()
run: |
CURRENT_PR_TITLE=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$CURRENT_PR_NUMBER" | jq -r .title)
echo "CURRENT_PR_TITLE: $CURRENT_PR_TITLE"
ORIGINAL_PR_TITLE=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r .title)
echo "ORIGINAL_PR_TITLE: $ORIGINAL_PR_TITLE"
if [[ "$CURRENT_PR_TITLE" != "$ORIGINAL_PR_TITLE" ]]; then
echo "Current PR title does not match original PR title raised against master branch"
exit 1
fi
- name: Verification Step 3 - master PR is merged
if: always()
run: |
ORIGINAL_PR_IS_MERGED=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r '.merged')
BASE_REF_BRANCH=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r '.base.ref')
if [[ "$ORIGINAL_PR_IS_MERGED" == "true" && "$BASE_REF_BRANCH" == "master" ]]; then
echo "Original PR is merged into master branch"
else
echo "Original PR number: $ORIGINAL_PR_NUMBER"
echo "Original PR merge status: $ORIGINAL_PR_IS_MERGED"
echo "Base branch: $BASE_REF_BRANCH"
echo "Status: Fail. Original PR is not merged in master branch."
exit 1
fi
- name: Verification Step 4 - release PR is exactly same as master PR
if: always()
run: |
# Get the JSON response for the first pull request
response_pr_master=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER/files")
files_pr_master=$(echo "$response_pr_master" | jq -r '.[].filename')
# Get the JSON response for the second pull request
response_pr_release=$(curl -L -H "Authorization: Bearer ${{ steps.get-token.outputs.token }}" "https://api.github.com/repos/${{ github.repository }}/pulls/$CURRENT_PR_NUMBER/files")
files_pr_release=$(echo "$response_pr_release" | jq -r '.[].filename')
# Compare the lists of changed files
if [ "$files_pr_master" != "$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 $files_pr_master; do
details_pr_master=($(echo "$response_pr_master" | 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_master="${details_pr_master[0]}"
deleted_lines_pr_master="${details_pr_master[1]}"
added_lines_pr_release="${details_pr_release[0]}"
deleted_lines_pr_release="${details_pr_release[1]}"
if [ "$added_lines_pr_master" != "$added_lines_pr_release" ] || [ "$deleted_lines_pr_master" != "$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."