Rateuss1 #1141
Workflow file for this run
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: Check for Duplicates and Close Issues on PR Merge | |
on: | |
pull_request: | |
types: [opened, synchronize, closed] | |
jobs: | |
check-duplicates: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Check for duplicate entries in product.json | |
run: | | |
# Check for duplicate entries in product.json | |
jq -r '.[].productName' product.json | sort | uniq -d > duplicates.txt | |
if [ -s duplicates.txt ]; then | |
echo "Duplicate entries found in product.json:" | |
cat duplicates.txt | |
exit 1 | |
else | |
echo "No duplicate entries found." | |
fi | |
close-issues: | |
runs-on: ubuntu-latest | |
needs: check-duplicates | |
if: github.event.pull_request.merged == true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Close linked issues | |
run: | | |
ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -Eo '#[0-9]+' | tr -d '#') | |
for ISSUE in $ISSUES | |
do | |
echo "Closing issue #$ISSUE" | |
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE/comments \ | |
-d '{"body":"Closed by PR #${{ github.event.pull_request.number }}"}' | |
curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE \ | |
-d '{"state":"closed"}' | |
done |