-
Notifications
You must be signed in to change notification settings - Fork 4
111 lines (90 loc) · 3.96 KB
/
run-build.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Compare Build Logs
on:
pull_request:
types: [opened, synchronize, reopened, edited]
jobs:
compare-build-logs:
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
contents: write
issues: read
steps:
- name: Checkout repository
uses: actions/[email protected]
with:
fetch-depth: 0 # Fetch all history for accurate comparisons
- name: Checkout dev branch
run: git checkout dev
- name: Install dependencies (dev branch)
run: npm install
- name: Build project (dev branch) and save log
run: npm run build > dev-build-log.txt 2>&1
- name: Extract relevant section from dev log
run: |
sed -n '/building for production.../,/modules transformed./p' dev-build-log.txt > relevant-dev-log.txt
- name: Clean up ANSI color codes from dev log
run: |
sed -r 's/\x1B\[[0-9;]*[mGKH]//g' relevant-dev-log.txt > cleaned-dev-log.txt
- name: Save extracted and cleaned dev log as artifact
uses: actions/[email protected]
with:
name: relevant-cleaned-dev-log
path: cleaned-dev-log.txt
- name: Checkout PR branch
run: git checkout ${{ github.head_ref }}
- name: Install dependencies (PR branch)
run: npm install
- name: Build project (PR branch) and save log
run: npm run build > pr-build-log.txt 2>&1
- name: Extract relevant section from PR log
run: |
sed -n '/building for production.../,/modules transformed./p' pr-build-log.txt > relevant-pr-log.txt
- name: Clean up ANSI color codes from PR log
run: |
sed -r 's/\x1B\[[0-9;]*[mGKH]//g' relevant-pr-log.txt > cleaned-pr-log.txt
- name: Save extracted and cleaned PR log as artifact
uses: actions/[email protected]
with:
name: relevant-cleaned-pr-log
path: cleaned-pr-log.txt
- name: Compare cleaned logs for differences
id: diff_check
run: |
echo "Comparing cleaned logs for differences..."
# Use diff and ignore lines containing "modules transformed"
diff -I "modules transformed" cleaned-dev-log.txt cleaned-pr-log.txt > log-diff.txt || true
# Check if diff output is non-empty
if [ -s log-diff.txt ]; then
echo "Differences detected."
echo "diff_found=true" >> $GITHUB_ENV
else
echo "No differences found." > log-diff.txt
echo "diff_found=false" >> $GITHUB_ENV
fi
- name: Upload diff as artifact for review
uses: actions/[email protected]
with:
name: build-log-diff
path: log-diff.txt
- name: Read log-diff.txt content
id: read_diff
run: |
if [ -f log-diff.txt ]; then
echo "DIFF_CONTENT<<EOF" >> $GITHUB_ENV
cat log-diff.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "No diff file found." >> $GITHUB_ENV
fi
- name: Comment PR with build log differences
if: env.diff_found == 'true'
uses: mshick/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: |
**Build Log Differences Found**:
```diff
${{ env.DIFF_CONTENT }}
```