-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (117 loc) · 4.33 KB
/
impactifier.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Impactifier CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
impactifier:
runs-on: ubuntu-latest
steps:
# 1. Checkout the repository with full history
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches
# 2. Cache Cargo Registry
- name: Cache Cargo Registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
# 3. Cache Cargo Build
- name: Cache Cargo Build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
# 4. Build Impactifier
- name: Build Impactifier
run: |
cargo build --release --manifest-path Cargo.toml
# 5. Run Impactifier and generate diff.json
- name: Run Impactifier
id: run_impactifier
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./target/release/impactifier --tracing-level=0 --from-branch=main --to-branch=main
# 6. (Optional) Output diff.json for debugging
- name: Output diff.json (Debug)
if: ${{ github.event_name == 'pull_request' }}
run: |
cat diff.json
# 7. Post Comment on Pull Request with the diff
- name: Post Comment on Pull Request
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = 'diff.json'; // Path to the diff JSON file
// Check if the diff file exists
if (!fs.existsSync(path)) {
console.log('No diff.json file found.');
return;
}
// Read and parse the diff JSON
let diffData;
try {
const rawData = fs.readFileSync(path, 'utf8');
diffData = JSON.parse(rawData);
} catch (error) {
console.error('Failed to read or parse diff.json:', error);
return;
}
// Format the diff for the comment
let formattedDiff = '';
if (diffData.deltas && Array.isArray(diffData.deltas)) {
diffData.deltas.forEach(delta => {
if (delta.value) {
// Escape backticks in the delta.value to prevent breaking the Markdown
const safeValue = delta.value.replace(/`/g, '\\`');
formattedDiff += `${safeValue}\n`;
}
});
} else {
formattedDiff = 'No differences found.';
}
// Handle large diffs by truncating (optional)
const maxLength = 60000; // GitHub comment limit
let truncatedDiff = formattedDiff;
if (formattedDiff.length > maxLength) {
truncatedDiff = formattedDiff.substring(0, maxLength) + '\n... (diff truncated)';
}
// Create a summary based on the number of deltas
let summary = '';
if (diffData.deltas && diffData.deltas.length > 0) {
summary = `**Total Changes:** ${diffData.deltas.length} file(s) changed.\n\n`;
} else {
summary = 'No changes detected between the specified branches.\n\n';
}
// Create the comment body with summary and diff
const commentBody = `## Impactifier Report
${summary}
\`\`\`diff
${truncatedDiff}
\`\`\``;
// Post the comment to the pull request
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log('Impactifier report posted successfully.');
} catch (error) {
console.error('Failed to post Impactifier report:', error);
}