Skip to content

Commit 4322fa6

Browse files
Merge pull request #109 from VirdocsSoftware/release/v2.21.0
release v2.21.0 to main
2 parents ae38b7c + b49eaa8 commit 4322fa6

File tree

4 files changed

+68
-42
lines changed

4 files changed

+68
-42
lines changed

.github/actions/auto-pr-description/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ A reusable GitHub Action that automatically generates pull request descriptions
2121
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
2222
github-token: ${{ secrets.GITHUB_TOKEN }}
2323
pr-number: ${{ github.event.pull_request.number }}
24-
base-sha: ${{ github.event.pull_request.base.sha }}
25-
head-sha: ${{ github.event.pull_request.head.sha }}
2624
```
2725
2826
### Complete Workflow Example
@@ -48,17 +46,13 @@ jobs:
4846
contents: read
4947
steps:
5048
- uses: actions/checkout@v4
51-
with:
52-
fetch-depth: 0
5349

5450
- name: Generate PR Description
5551
uses: ./.github/actions/auto-pr-description
5652
with:
5753
gemini-api-key: ${{ secrets.GEMINI_API_KEY }}
5854
github-token: ${{ secrets.GITHUB_TOKEN }}
5955
pr-number: ${{ github.event.pull_request.number }}
60-
base-sha: ${{ github.event.pull_request.base.sha }}
61-
head-sha: ${{ github.event.pull_request.head.sha }}
6256
jira-ticket-url-prefix: 'https://yourcompany.atlassian.net/browse/'
6357
```
6458
@@ -69,8 +63,6 @@ jobs:
6963
| `gemini-api-key` | The API key for the Gemini API | ✅ | - |
7064
| `github-token` | GitHub token for PR operations | ✅ | - |
7165
| `pr-number` | Pull request number | ✅ | - |
72-
| `base-sha` | Base commit SHA for diff comparison | ✅ | - |
73-
| `head-sha` | Head commit SHA for diff comparison | ✅ | - |
7466
| `jira-ticket-url-prefix` | JIRA ticket URL prefix | ❌ | `https://virdocs.atlassian.net/browse/` |
7567

7668
## Outputs
@@ -148,7 +140,7 @@ The action handles various error scenarios:
148140
- API rate limits and timeouts
149141
- Large diffs that exceed API limits
150142
- Network connectivity issues
151-
- Invalid PR numbers or SHAs
143+
- Invalid PR numbers
152144

153145
## Customization
154146

@@ -182,6 +174,7 @@ The action handles various error scenarios:
182174
2. **Permission Denied**: Check that workflow has `pull-requests: write` permission
183175
3. **Large Diffs**: Very large changes might exceed API limits - consider smaller PRs
184176
4. **Rate Limits**: Gemini API has rate limits - add delays between calls if needed
177+
5. **Invalid PR Number**: Ensure the PR number is valid and accessible
185178

186179
### Debug Mode
187180

.github/actions/auto-pr-description/action.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ inputs:
1010
pr-number:
1111
description: 'Pull request number'
1212
required: true
13-
base-sha:
14-
description: 'Base commit SHA for diff comparison'
15-
required: true
16-
head-sha:
17-
description: 'Head commit SHA for diff comparison'
18-
required: true
1913
jira-ticket-url-prefix:
2014
description: 'JIRA ticket URL prefix (e.g., https://company.atlassian.net/browse/)'
2115
required: false
@@ -42,11 +36,14 @@ runs:
4236
npm install
4337
working-directory: ${{ github.action_path }}
4438

45-
- name: Generate git diff
39+
- name: Generate PR diff from GitHub
4640
shell: bash
41+
env:
42+
GH_TOKEN: ${{ inputs.github-token }}
43+
PR_NUMBER: ${{ inputs.pr-number }}
4744
run: |
48-
git fetch origin ${{ inputs.base-sha }} --depth=1
49-
git diff ${{ inputs.base-sha }}... > pr.diff
45+
# Get the PR diff directly from GitHub using gh CLI
46+
gh pr diff ${{ inputs.pr-number }} > pr.diff
5047
echo "Generated diff file with $(wc -l < pr.diff) lines"
5148
5249
- name: Generate PR description

.github/actions/static-analysis/layer_dependency_analysis.js

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ class LayerDependencyAnalysis {
9898
this.comparator = comparator;
9999
}
100100

101-
run(layerPackageJson, domainPackageJsons) {
102-
console.log('Running layer dependency analysis');
101+
run(layerPackageJson, domainPackageJsons, outputFormat = 'console') {
102+
if (outputFormat !== 'json') {
103+
console.log('Running layer dependency analysis');
104+
}
103105

104106
const reports = domainPackageJsons.map(domainPackageJson => {
105107
return {
@@ -110,36 +112,66 @@ class LayerDependencyAnalysis {
110112

111113
const reportsWithWarnings = reports.filter(report => report.report.mismatches.length > 0);
112114

113-
if (reportsWithWarnings.length > 0) {
114-
console.log('Reports with mismatched dependencies:');
115-
reportsWithWarnings.forEach(report => {
116-
// output warning to github actions
117-
console.log(`::warning file=${report.project}/package.json::${this.comparator.formatReport(report.report)}`);
118-
});
115+
if (outputFormat === 'json') {
116+
// Output structured JSON data for piping to other scripts
117+
const jsonOutput = {
118+
timestamp: new Date().toISOString(),
119+
layerPackageJson: layerPackageJson.name || 'unknown',
120+
totalDomainsAnalyzed: domainPackageJsons.length,
121+
domainsWithMismatches: reportsWithWarnings.length,
122+
reports: reports.map(report => ({
123+
project: report.project,
124+
hasMismatches: report.report.mismatches.length > 0,
125+
mismatches: report.report.mismatches,
126+
missingInFirst: report.report.missingInFirst,
127+
missingInSecond: report.report.missingInSecond,
128+
formattedReport: this.comparator.formatReport(report.report)
129+
}))
130+
};
131+
132+
console.log(JSON.stringify(jsonOutput, null, 2));
119133
} else {
120-
console.log('No mismatched dependencies found');
134+
// Original console output behavior
135+
if (reportsWithWarnings.length > 0) {
136+
console.log('Reports with mismatched dependencies:');
137+
reportsWithWarnings.forEach(report => {
138+
// output warning to github actions
139+
console.log(`::warning file=${report.project}/package.json::${this.comparator.formatReport(report.report)}`);
140+
});
141+
} else {
142+
console.log('No mismatched dependencies found');
143+
}
121144
}
122145
}
123146
}
124147

125148
function main() {
126-
if (process.argv.length < 4) {
127-
console.error('Usage: node layer_dependency_analysis.js <layer-package-json> <domains>');
149+
const args = process.argv.slice(2);
150+
const jsonOutput = args.includes('--json');
151+
const filteredArgs = args.filter(arg => arg !== '--json');
152+
153+
if (filteredArgs.length < 2) {
154+
console.error('Usage: node layer_dependency_analysis.js [--json] <layer-package-json> <domains>');
155+
console.error(' --json: Output structured JSON data instead of console warnings');
128156
process.exit(1);
129157
}
130158

131-
console.log('Layer package.json:', process.argv[2]);
132-
console.log('Domains:', process.argv[3]);
133-
console.log('Current working directory:', process.cwd());
159+
if (!jsonOutput) {
160+
console.log('Layer package.json:', filteredArgs[0]);
161+
console.log('Domains:', filteredArgs[1]);
162+
console.log('Current working directory:', process.cwd());
163+
}
134164

135165
// Example usage:
136166
const comparator = new PackageJsonDependencyComparator();
137167

138168
const layerDependencyAnalysis = new LayerDependencyAnalysis(comparator);
139169

140-
console.log('Reading layer package.json:', process.cwd() + '/' + process.argv[2]);
141-
const layerPackageJson = JSON.parse(fs.readFileSync(process.cwd() + '/' + process.argv[2], 'utf8'));
142-
const domains = JSON.parse(process.argv[3]); // {"include": [{"project": "domain1"}, {"project": "domain2"}]}
170+
if (!jsonOutput) {
171+
console.log('Reading layer package.json:', process.cwd() + '/' + filteredArgs[0]);
172+
}
173+
const layerPackageJson = JSON.parse(fs.readFileSync(process.cwd() + '/' + filteredArgs[0], 'utf8'));
174+
const domains = JSON.parse(filteredArgs[1]); // {"include": [{"project": "domain1"}, {"project": "domain2"}]}
143175

144176
const domainPackageJsons = domains.include.filter(domain => domain.project != '.').map(domain => {
145177
try {
@@ -149,18 +181,22 @@ function main() {
149181
packageJson
150182
};
151183
} catch (error) {
152-
console.error('Error parsing package.json for domain:', domain.project, error);
184+
if (!jsonOutput) {
185+
console.error('Error parsing package.json for domain:', domain.project, error);
186+
}
153187
return undefined;
154188
}
155189
}).filter(domain => domain !== undefined);
156190

157191
// print the test plan
158-
console.log('Test plan:');
159-
console.log('Layer package.json:', layerPackageJson);
160-
console.log('Domains:', domains);
161-
// console.log('Domain package.json:', JSON.stringify(domainPackageJsons, null, 2));
192+
if (!jsonOutput) {
193+
console.log('Test plan:');
194+
console.log('Layer package.json:', layerPackageJson);
195+
console.log('Domains:', domains);
196+
// console.log('Domain package.json:', JSON.stringify(domainPackageJsons, null, 2));
197+
}
162198

163-
layerDependencyAnalysis.run(layerPackageJson, domainPackageJsons);
199+
layerDependencyAnalysis.run(layerPackageJson, domainPackageJsons, jsonOutput ? 'json' : 'console');
164200
}
165201

166202
main();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-actions",
3-
"version": "2.19.0",
3+
"version": "2.21.0",
44
"description": "Used to store GitHub actions for use across the enterprise",
55
"scripts": {
66
"test": "./tooling/scripts/run_tests.sh",

0 commit comments

Comments
 (0)