89 lines
5.3 KiB
YAML
89 lines
5.3 KiB
YAML
name: Release PR CI
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [ release-* ]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
validate-pr:
|
|
runs-on: [ default ]
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v3
|
|
- name: Check if link to original PR is added in PR body
|
|
run: |
|
|
ORIGINAL_PR_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -o "https://github.cmd.navi-tech.in/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
|
|
ORIGINAL_PR_URL="https://github.cmd.navi-tech.in/${{ github.repository }}/pull/$ORIGINAL_PR_NUMBER"
|
|
|
|
echo "Original PR Number extracted: $ORIGINAL_PR_NUMBER"
|
|
echo "Original PR Url generated: $ORIGINAL_PR_URL"
|
|
echo "Pull request body: ${{ github.event.pull_request.body }}"
|
|
|
|
if [[ "${{ github.event.pull_request.body }}" != *"$ORIGINAL_PR_URL"* ]]; then
|
|
echo "Link to original PR raised against development branch not found in current PR body"
|
|
exit 1
|
|
fi
|
|
- name: Check if PR title matches original PR title
|
|
run: |
|
|
ORIGINAL_PR_NUMBER=$(echo ${{ github.event.pull_request.body }} | grep -o "https://github.cmd.navi-tech.in/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
|
|
ORIGINAL_PR_TITLE=$(curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r .title)
|
|
|
|
echo "PR Number extracted: $ORIGINAL_PR_NUMBER"
|
|
echo "Original PR title generated: $ORIGINAL_PR_TITLE"
|
|
echo "Current PR title extracted: ${{ github.event.pull_request.title }}"
|
|
|
|
if [[ "${{ github.event.pull_request.title }}" != "$ORIGINAL_PR_TITLE" ]]; then
|
|
echo "Current PR title does not match original PR title raised against development branch"
|
|
exit 1
|
|
fi
|
|
- name: Check if original PR is merged in development branch
|
|
run: |
|
|
ORIGINAL_PR_NUMBER=$(echo ${{ github.event.pull_request.body }} | grep -o "https://github.cmd.navi-tech.in/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
|
|
ORIGINAL_PR_IS_MERGED=$(curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r '.merged')
|
|
BASE_REF_BRANCH=$(curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/repos/${{ github.repository }}/pulls/$ORIGINAL_PR_NUMBER" | jq -r '.base.ref')
|
|
if [[ "$ORIGINAL_PR_IS_MERGED" == "true" && "$BASE_REF_BRANCH" == "development" ]]; then
|
|
echo "Original PR is merged into development 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 development branch."
|
|
exit 1
|
|
fi
|
|
- name: Check if current PR changes are subset of original PR changes
|
|
run: |
|
|
ORIGINAL_PR_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -o "https://github.cmd.navi-tech.in/${{ github.repository }}/pull/[0-9]*" | grep -o "[0-9]*")
|
|
ORIGINAL_PR_COMMITS=$(curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/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.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/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' ' ')
|
|
|
|
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.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/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.GITHUB_TOKEN }}" "https://github.cmd.navi-tech.in/api/v3/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"
|
|
exit 1
|
|
fi
|