Skip to content

Commit 460abda

Browse files
authored
Merge pull request #4 from advanced-security/address-breaking-change-pack-ls
Address breaking change pack ls
2 parents f29c6fd + 046b394 commit 460abda

File tree

7 files changed

+44
-34
lines changed

7 files changed

+44
-34
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Test action
22
on:
33
workflow_dispatch:
4+
inputs:
5+
bundle-version:
6+
description: "Tag of the bundle to use for testing"
7+
required: true
8+
default: "latest"
9+
type: string
410

511
jobs:
612
create-test-bundle:

lib/bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bundle.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,9 @@ import * as fs from "fs"
77
import * as tar from "tar"
88
import * as yaml from "js-yaml"
99
import * as async from "async"
10-
import { CodeQL, CodeQLPack, CodeQLPackDependency } from "./codeql"
10+
import { CodeQL, CodeQLPack, CodeQLPackYmlSpec } from "./codeql"
1111
import internal = require("stream")
1212

13-
interface QLPackDependencies {
14-
[key: string]: string
15-
}
16-
17-
interface QLPack {
18-
name: string;
19-
version: string;
20-
library: boolean;
21-
dependencies?: QLPackDependencies
22-
}
23-
2413
export class Bundle {
2514
private octokit: any
2615
private tag: string
@@ -84,6 +73,7 @@ export class Bundle {
8473
customization: []
8574
} as { query: CodeQLPack[]; library: CodeQLPack[], customization: CodeQLPack[] })
8675

76+
core.debug(`Found ${groupedPacks.query.length} query pack(s), ${groupedPacks.library.length} library pack(s), ${groupedPacks.customization.length} customization pack(s)`)
8777
const codeqlCli = this.getCodeQL()
8878
const qlpacksPath = path.join(this.bundlePath, 'qlpacks')
8979
await Promise.all(groupedPacks.library.map(async pack => await codeqlCli.bundlePack(pack.path, qlpacksPath, [workspace])))
@@ -106,7 +96,7 @@ export class Bundle {
10696

10797
const standardPack = compatibleStandardPacks[0]
10898
core.debug(`Found compatible standard pack ${standardPack.name} as a target for customization.`)
109-
const packDefinition = (yaml.load(fs.readFileSync(pack.path, 'utf-8'))) as QLPack
99+
const packDefinition = (yaml.load(fs.readFileSync(pack.path, 'utf-8'))) as CodeQLPackYmlSpec
110100
if (packDefinition.dependencies) {
111101
core.debug(`Removing dependency on ${standardPack.name} to prevent circular dependency.`)
112102
delete packDefinition.dependencies[standardPack.name]
@@ -127,7 +117,7 @@ export class Bundle {
127117
core.debug(`Copying ${standardPackVersionDir} to ${tempStandardPackVersionDir}.`)
128118
await io.cp(standardPackVersionDir, tempStandardPackVersionDir, { recursive: true })
129119

130-
const standardPackDefinition = (yaml.load(fs.readFileSync(standardPack.path, 'utf-8'))) as QLPack
120+
const standardPackDefinition = (yaml.load(fs.readFileSync(standardPack.path, 'utf-8'))) as CodeQLPackYmlSpec
131121
standardPackDefinition.dependencies = standardPackDefinition.dependencies || {}
132122
standardPackDefinition.dependencies[pack.name] = pack.version
133123

@@ -205,7 +195,7 @@ export class Bundle {
205195
*/
206196
patchDependencyOnSuiteHelpers(pack: CodeQLPack) {
207197
const suiteHelpersPackName = 'codeql/suite-helpers'
208-
const packDefinition = (yaml.load(fs.readFileSync(pack.path, 'utf-8'))) as QLPack
198+
const packDefinition = (yaml.load(fs.readFileSync(pack.path, 'utf-8'))) as CodeQLPackYmlSpec
209199
if (packDefinition.dependencies) {
210200
core.debug(`Patching dependency on 'codeql/suite-helpers' to prevent resolution error.`)
211201
packDefinition.dependencies[suiteHelpersPackName] = "*"

src/codeql.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as exec from "@actions/exec"
33
import * as io from "@actions/io"
44
import * as path from "path"
55
import * as crypto from "crypto"
6+
import * as yaml from "js-yaml"
7+
import * as fs from "fs"
68

79
export interface CodeQLVersion {
810
productName: string;
@@ -19,7 +21,6 @@ export interface CodeQLVersion {
1921
export interface CodeQLPackDependency {
2022
name: string;
2123
version: string;
22-
inclusive: boolean
2324
}
2425
export interface CodeQLPack {
2526
path: string;
@@ -44,6 +45,18 @@ interface RunResult {
4445
stderr: string;
4546
}
4647

48+
export interface QLPackDependencyYmlSpec {
49+
[key: string]: string
50+
}
51+
52+
export interface CodeQLPackYmlSpec {
53+
name: string;
54+
version?: string;
55+
library: boolean;
56+
dependencies?: QLPackDependencyYmlSpec
57+
extractor?: string;
58+
}
59+
4760
export class CodeQL {
4861
private codeqlHome: string;
4962

@@ -88,21 +101,20 @@ export class CodeQL {
88101
const packs = JSON.parse(result.stdout).packs
89102
return Object.keys(packs).map(path => {
90103
console.debug(`Listing pack at ${path}`)
91-
const extractor = packs[path].extractor || undefined
92-
const dependencies = packs[path].dependencies ? Object.keys(packs[path].dependencies).map(pack => {
104+
const packDefinition = (yaml.load(fs.readFileSync(path, 'utf-8'))) as CodeQLPackYmlSpec
105+
const dependencies = packDefinition.dependencies ? Object.keys(packDefinition.dependencies).map(pack => {
93106
return {
94107
name: pack,
95-
version: packs[path].dependencies[pack].text,
96-
inclusive: packs[path].dependencies[pack].inclusive
108+
version: (packDefinition.dependencies as QLPackDependencyYmlSpec)[pack]
97109
}
98110
}) : []
99111
return {
100-
name: packs[path].name,
112+
name: packDefinition.name,
101113
path: path,
102-
library: packs[path].library,
103-
version: packs[path].version || "0.0.0",
114+
library: packDefinition.library,
115+
version: packDefinition.version || "0.0.0",
104116
dependencies: dependencies,
105-
extractor: extractor
117+
extractor: packDefinition.extractor
106118
}
107119
})
108120
}

0 commit comments

Comments
 (0)