TC-3 Update main.yml #49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate Pull Request | |
on: | |
pull_request: # Trigger on pull request events | |
jobs: | |
validate: | |
runs-on: ubuntu-latest # Run the workflow on Ubuntu virtual machine | |
steps: | |
- uses: actions/checkout@v3 # Checkout the repository code | |
- name: Check PR Description | |
run: | | |
if [[ -z "${{ github.event.pull_request.body }}" ]]; then | |
echo "❌ Pull Request description is missing. Please provide a description of your changes." | |
exit 1 | |
elif [[ ! "${{ github.event.pull_request.body }}" =~ ^https:\/\/thousandgreens\.atlassian\.net\/browse\/TG- ]]; then | |
echo "❌ Pull Request description must contain a link to the JIRA ticket (e.g., https://thousandgreens.atlassian.net/browse/TG-123)" | |
exit 1 | |
fi | |
- name: Check PR Approval | |
id: pr_approvals | |
uses: octokit/[email protected] | |
with: | |
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews | |
headers: 'token ${{ secrets.GITHUB_TOKEN }}' | |
- name: Verify Approval | |
run: | | |
const reviews = JSON.parse('${{ steps.pr_approvals.outputs.data }}'); | |
if (reviews.length < 1 || !reviews.some(review => review.state === 'APPROVED')) { | |
core.setFailed('PR must be approved by at least 1 person before merging.'); | |
} |