Skip to content

Commit 355a05d

Browse files
authored
fix: fix incorect languge slection based on repo config (#63)
* fix: fix incorect languge slection based on repo config
1 parent 09925c6 commit 355a05d

File tree

6 files changed

+329
-84
lines changed

6 files changed

+329
-84
lines changed

packages/codeql-action/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed Codeql configuration build
13+
1014
## [2.0.1]
1115

1216
### Fixed
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
import { applyLanguageConfigFallbacks } from '../scripts/generate-config.js';
2+
3+
describe('generate-config', () => {
4+
describe('applyLanguageConfigFallbacks', () => {
5+
test('returns inputs as-is when no language specified', () => {
6+
const inputs = {
7+
repo: 'owner/repo',
8+
language: '',
9+
buildMode: 'none',
10+
buildCommand: '',
11+
version: '2.0.0',
12+
distribution: 'ubuntu-latest',
13+
};
14+
const config = {
15+
languages_config: [],
16+
};
17+
18+
const result = applyLanguageConfigFallbacks(inputs, config);
19+
20+
expect(result).toEqual(inputs);
21+
});
22+
23+
test('returns inputs as-is when language config not found', () => {
24+
const inputs = {
25+
repo: 'owner/repo',
26+
language: 'java-kotlin',
27+
buildMode: 'manual',
28+
buildCommand: 'mvn compile',
29+
version: '2.0.0',
30+
distribution: 'ubuntu-latest',
31+
};
32+
const config = {
33+
languages_config: [
34+
{
35+
language: 'javascript',
36+
build_mode: 'none',
37+
},
38+
],
39+
};
40+
41+
const result = applyLanguageConfigFallbacks(inputs, config);
42+
43+
expect(result).toEqual(inputs);
44+
});
45+
46+
test('preserves input values even when config has fallbacks', () => {
47+
const inputs = {
48+
repo: 'owner/repo',
49+
language: 'java-kotlin',
50+
buildMode: 'manual',
51+
buildCommand: 'mvn compile',
52+
version: '2.0.0',
53+
distribution: 'ubuntu-latest',
54+
};
55+
const config = {
56+
languages_config: [
57+
{
58+
language: 'java-kotlin',
59+
build_mode: 'autobuild',
60+
build_command: 'gradle build',
61+
version: '1.0.0',
62+
distribution: 'debian-latest',
63+
},
64+
],
65+
};
66+
67+
const result = applyLanguageConfigFallbacks(inputs, config);
68+
69+
// Inputs should take precedence
70+
expect(result.buildMode).toBe('manual');
71+
expect(result.buildCommand).toBe('mvn compile');
72+
expect(result.version).toBe('2.0.0');
73+
expect(result.distribution).toBe('ubuntu-latest');
74+
});
75+
76+
test('applies config fallbacks for missing input values', () => {
77+
const inputs = {
78+
repo: 'owner/repo',
79+
language: 'java-kotlin',
80+
buildMode: undefined,
81+
buildCommand: undefined,
82+
version: undefined,
83+
distribution: undefined,
84+
};
85+
const config = {
86+
languages_config: [
87+
{
88+
language: 'java-kotlin',
89+
build_mode: 'autobuild',
90+
build_command: 'gradle build',
91+
version: '2.5.0',
92+
distribution: 'ubuntu-latest',
93+
},
94+
],
95+
};
96+
97+
const result = applyLanguageConfigFallbacks(inputs, config);
98+
99+
// Config fallbacks should be applied
100+
expect(result.buildMode).toBe('autobuild');
101+
expect(result.buildCommand).toBe('gradle build');
102+
expect(result.version).toBe('2.5.0');
103+
expect(result.distribution).toBe('ubuntu-latest');
104+
});
105+
106+
test('applies partial config fallbacks', () => {
107+
const inputs = {
108+
repo: 'owner/repo',
109+
language: 'swift',
110+
buildMode: 'manual',
111+
buildCommand: undefined,
112+
version: '2.0.0',
113+
distribution: undefined,
114+
};
115+
const config = {
116+
languages_config: [
117+
{
118+
language: 'swift',
119+
build_mode: 'autobuild',
120+
build_command: 'swift build',
121+
version: '1.0.0',
122+
distribution: 'macos-latest',
123+
},
124+
],
125+
};
126+
127+
const result = applyLanguageConfigFallbacks(inputs, config);
128+
129+
// Input values preserved
130+
expect(result.buildMode).toBe('manual');
131+
expect(result.version).toBe('2.0.0');
132+
// Config fallbacks applied
133+
expect(result.buildCommand).toBe('swift build');
134+
expect(result.distribution).toBe('macos-latest');
135+
});
136+
137+
test('handles empty config.languages_config array', () => {
138+
const inputs = {
139+
repo: 'owner/repo',
140+
language: 'java-kotlin',
141+
buildMode: 'manual',
142+
buildCommand: 'mvn compile',
143+
version: '2.0.0',
144+
distribution: 'ubuntu-latest',
145+
};
146+
const config = {
147+
languages_config: [],
148+
};
149+
150+
const result = applyLanguageConfigFallbacks(inputs, config);
151+
152+
// Should return inputs unchanged
153+
expect(result).toEqual(inputs);
154+
});
155+
156+
test('handles missing config.languages_config property', () => {
157+
const inputs = {
158+
repo: 'owner/repo',
159+
language: 'python',
160+
buildMode: 'none',
161+
};
162+
const config = {};
163+
164+
const result = applyLanguageConfigFallbacks(inputs, config);
165+
166+
// Should return inputs unchanged
167+
expect(result).toEqual(inputs);
168+
});
169+
170+
test('treats empty string as a value (not falsy for fallback)', () => {
171+
const inputs = {
172+
repo: 'owner/repo',
173+
language: 'javascript',
174+
buildMode: '',
175+
buildCommand: '',
176+
version: '',
177+
distribution: '',
178+
};
179+
const config = {
180+
languages_config: [
181+
{
182+
language: 'javascript',
183+
build_mode: 'none',
184+
build_command: 'npm build',
185+
version: '1.0.0',
186+
distribution: 'ubuntu-latest',
187+
},
188+
],
189+
};
190+
191+
const result = applyLanguageConfigFallbacks(inputs, config);
192+
193+
// Empty strings are falsy, so config fallbacks WILL be applied
194+
// This is current behavior - if we want to change it, we need to update the logic
195+
expect(result.buildMode).toBe('none');
196+
expect(result.buildCommand).toBe('npm build');
197+
expect(result.version).toBe('1.0.0');
198+
expect(result.distribution).toBe('ubuntu-latest');
199+
});
200+
201+
test('does not modify other input properties', () => {
202+
const inputs = {
203+
repo: 'owner/repo',
204+
language: 'go',
205+
buildMode: undefined,
206+
buildCommand: undefined,
207+
version: undefined,
208+
distribution: undefined,
209+
pathsIgnored: ['test', 'vendor'],
210+
rulesExcluded: ['go/rule1'],
211+
};
212+
const config = {
213+
languages_config: [
214+
{
215+
language: 'go',
216+
build_mode: 'autobuild',
217+
},
218+
],
219+
};
220+
221+
const result = applyLanguageConfigFallbacks(inputs, config);
222+
223+
// Other properties should remain unchanged
224+
expect(result.repo).toBe('owner/repo');
225+
expect(result.language).toBe('go');
226+
expect(result.pathsIgnored).toEqual(['test', 'vendor']);
227+
expect(result.rulesExcluded).toEqual(['go/rule1']);
228+
});
229+
});
230+
});

packages/codeql-action/action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ runs:
6767
env:
6868
REPO: ${{inputs.repo}}
6969
LANGUAGE: ${{ inputs.language }}
70+
BUILD_MODE: ${{ inputs.build_mode }}
71+
BUILD_COMMAND: ${{ inputs.build_command }}
72+
VERSION: ${{ inputs.version }}
73+
DISTRIBUTION: ${{ inputs.distribution }}
7074
PATHS_IGNORED: ${{ inputs.paths_ignored}}
7175
RULES_EXCLUDED: ${{ inputs.rules_excluded}}
7276

packages/codeql-action/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"scripts": {
1616
"lint": "prettier '**/*.json' '**/*.md' '**/*.yml' '**/*.js' --check --ignore-path .gitignore --no-error-on-unmatched-pattern",
1717
"lint:fix": "prettier '**/*.json' '**/*.md' '**/*.yml' '**/*.js' --write --ignore-path .gitignore --no-error-on-unmatched-pattern",
18-
"test": "NODE_OPTIONS=--experimental-vm-modules yarn exec jest",
19-
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules yarn exec jest --coverage",
20-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules yarn exec jest --watch"
18+
"test": "NODE_OPTIONS=--experimental-vm-modules yarn test",
19+
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules yarn test:coverage",
20+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules yarn test:watch"
2121
},
2222
"dependencies": {
2323
"ejs": "^3.1.10"

0 commit comments

Comments
 (0)