forked from pranjay-poddar/Dev-Geeks
-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (58 loc) · 2.19 KB
/
analyze-pr-files.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: PR File Analyzer
on:
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
check_files:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: List all changed files
id: list_files
run: |
git diff --name-only origin/main ${{ github.event.pull_request.head.sha }} > changed_files.txt
cat changed_files.txt
- name: Check for graphical assets
id: check_graphical_assets
run: |
if grep -E -i ".*\.(png|jpg|jpeg|gif|mp4|svg|ico|webp)" changed_files.txt
then
echo "Found graphical assets! Please remove them from the PR."
exit 1
fi
- name: Check for non-code files
id: check_non_code_files
run: |
if grep -E -i ".*\.(html|css|js|jsx|tsx|json)" changed_files.txt
then
echo "All good! Code files present in the PR."
else
echo "No code-related files found! Please add code-related files (HTML, CSS, JS, JSX, TSX, JSON) to the PR."
exit 1
fi
- name: Add comment to PR
if: steps.check_graphical_assets.outputs.exit-code == '1' || steps.check_non_code_files.outputs.exit-code == '1'
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (steps.check_graphical_assets.outputs.exit-code == '1') {
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "It looks like you have included graphical asset files in this pull request. Please remove them to keep the PR focused on code changes."
});
}
if (steps.check_non_code_files.outputs.exit-code == '1') {
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "It seems that no code-related files (HTML, CSS, JS, JSX, TSX, JSON) were included in this pull request. Please add the appropriate code files for review."
});
}