Skip to content

Commit a5768a7

Browse files
authored
Merge pull request #139 from advanced-security/extractor-update
feat(extractor): Update grammars and CodeQL
2 parents ca558b5 + 6b93464 commit a5768a7

File tree

16 files changed

+755
-408
lines changed

16 files changed

+755
-408
lines changed

.github/action/dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13530,7 +13530,7 @@ const toolcache = __importStar(__nccwpck_require__(7784));
1353013530
const github = __importStar(__nccwpck_require__(5438));
1353113531
const toolrunner = __importStar(__nccwpck_require__(8159));
1353213532
exports.EXTRACTOR_REPOSITORY = "advanced-security/codeql-extractor-iac";
13533-
exports.EXTRACTOR_VERSION = "v0.0.4"; // stable version
13533+
exports.EXTRACTOR_VERSION = "v0.4.0"; // stable version
1353413534
async function newCodeQL() {
1353513535
var version = core.getInput("extractor-version");
1353613536
if (version === "") {

.github/action/src/codeql.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as github from "@actions/github";
77
import * as toolrunner from "@actions/exec/lib/toolrunner";
88

99
export const EXTRACTOR_REPOSITORY = "advanced-security/codeql-extractor-iac";
10-
export const EXTRACTOR_VERSION = "v0.0.4"; // stable version
10+
export const EXTRACTOR_VERSION = "v0.4.0"; // stable version
1111

1212
export interface CodeQLConfig {
1313
// The path to the codeql bundle.
@@ -48,7 +48,7 @@ export async function newCodeQL(): Promise<CodeQLConfig> {
4848

4949
export async function runCommand(
5050
config: CodeQLConfig,
51-
args: string[]
51+
args: string[],
5252
): Promise<any> {
5353
var bin = path.join(config.path, "codeql");
5454
let output = "";
@@ -68,7 +68,7 @@ export async function runCommand(
6868

6969
export async function runCommandJson(
7070
config: CodeQLConfig,
71-
args: string[]
71+
args: string[],
7272
): Promise<object> {
7373
return JSON.parse(await runCommand(config, args));
7474
}
@@ -130,12 +130,12 @@ export async function downloadExtractor(config: CodeQLConfig): Promise<string> {
130130
}
131131
// we assume there is only one tar.gz asset
132132
const assets = release.data.assets.filter((asset) =>
133-
asset.browser_download_url.endsWith(".tar.gz")
133+
asset.browser_download_url.endsWith(".tar.gz"),
134134
);
135135

136136
if (assets.length !== 1) {
137137
throw new Error(
138-
`Expected 1 asset to be found, but found ${assets.length} instead.`
138+
`Expected 1 asset to be found, but found ${assets.length} instead.`,
139139
);
140140
}
141141
var asset = assets[0];
@@ -148,7 +148,7 @@ export async function downloadExtractor(config: CodeQLConfig): Promise<string> {
148148
`token ${core.getInput("token")}`,
149149
{
150150
accept: "application/octet-stream",
151-
}
151+
},
152152
);
153153
core.debug(`Extractor downloaded to ${extractorPath}`);
154154

@@ -170,7 +170,7 @@ export async function downloadPack(codeql: CodeQLConfig): Promise<boolean> {
170170
}
171171

172172
export async function codeqlDatabaseCreate(
173-
codeql: CodeQLConfig
173+
codeql: CodeQLConfig,
174174
): Promise<string> {
175175
// get runner temp directory for database
176176
var temp = process.env["RUNNER_TEMP"];
@@ -196,7 +196,7 @@ export async function codeqlDatabaseCreate(
196196

197197
export async function codeqlDatabaseAnalyze(
198198
codeql: CodeQLConfig,
199-
database_path: string
199+
database_path: string,
200200
): Promise<string> {
201201
var codeql_output = codeql.output || "codeql-iac.sarif";
202202

.github/labeler.yml

+33-30
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
1-
21
docs:
3-
- changed-files:
4-
- any-glob-to-any-file: 'docs/*'
2+
- changed-files:
3+
- any-glob-to-any-file: "docs/*"
54

65
action:
7-
- changed-files:
8-
- any-glob-to-any-file: '.github/action/*'
6+
- changed-files:
7+
- any-glob-to-any-file: ".github/action/*"
98

109
extractor:
11-
- changed-files:
12-
- any-glob-to-any-file:
13-
- 'extractor/*'
14-
- 'tools/*'
10+
- changed-files:
11+
- any-glob-to-any-file:
12+
- "extractor/*"
13+
- "tools/*"
14+
15+
version:
16+
- changed-files:
17+
- any-glob-to-any-file: ".release.yml"
1518

1619
ql-library:
17-
- changed-files:
18-
- any-glob-to-any-file:
19-
- 'ql/lib/*'
20+
- changed-files:
21+
- any-glob-to-any-file:
22+
- "ql/lib/*"
2023

2124
ql-queries:
22-
- changed-files:
23-
- any-glob-to-any-file:
24-
- 'ql/src/*'
25+
- changed-files:
26+
- any-glob-to-any-file:
27+
- "ql/src/*"
2528

2629
ql-tests:
27-
- changed-files:
28-
- any-glob-to-any-file:
29-
- 'ql/test/*'
30+
- changed-files:
31+
- any-glob-to-any-file:
32+
- "ql/test/*"
3033

3134
# Languages
3235

3336
bicep:
34-
- changed-files:
35-
- any-glob-to-any-file:
36-
- ql/lib/codeql/bicep
37-
- ql/src/security/Bicep
38-
- test/library-tests/bicep
39-
- test/queries-tests/Bicep
37+
- changed-files:
38+
- any-glob-to-any-file:
39+
- ql/lib/codeql/bicep
40+
- ql/src/security/Bicep
41+
- test/library-tests/bicep
42+
- test/queries-tests/Bicep
4043

4144
terraform:
42-
- changed-files:
43-
- any-glob-to-any-file:
44-
- ql/lib/codeql/hcl
45-
- ql/src/security/Terraform
46-
- test/library-tests/hcl
47-
- test/queries-tests/Terraform
45+
- changed-files:
46+
- any-glob-to-any-file:
47+
- ql/lib/codeql/hcl
48+
- ql/src/security/Terraform
49+
- test/library-tests/hcl
50+
- test/queries-tests/Terraform

.github/workflows/build.yml

+21-48
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,27 @@ permissions:
1111
pull-requests: read
1212

1313
jobs:
14-
extractor:
14+
tests:
1515
runs-on: ubuntu-latest
16-
16+
strategy:
17+
matrix:
18+
test-folders: ["library-tests", "queries-tests"]
1719
steps:
18-
- uses: actions/checkout@v4
20+
- name: "Checkout"
21+
uses: actions/checkout@v4
1922

20-
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
21-
id: changes
23+
- name: "Check for changes"
24+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
25+
id: extractor-changes
2226
with:
2327
filters: |
2428
src:
2529
- 'extractor/**'
2630
- 'rust-toolchain.toml'
2731
- 'Cargo.*'
2832
29-
- uses: dtolnay/rust-toolchain@nightly
30-
if: steps.changes.outputs.src == 'true'
31-
32-
- name: "Build Extractor"
33-
if: steps.changes.outputs.src == 'true'
34-
env:
35-
GH_TOKEN: ${{ github.token }}
36-
run: |
37-
gh extensions install github/gh-codeql
38-
gh codeql set-version latest
39-
40-
./scripts/create-extractor-pack.sh
41-
42-
gh codeql resolve languages --format=json --search-path ./extractor-pack
43-
4433
- name: "Download Extracter"
45-
if: steps.changes.outputs.src == 'false'
34+
if: steps.extractor-changes.outputs.src == 'false'
4635
env:
4736
GH_TOKEN: ${{ github.token }}
4837
run: |
@@ -55,38 +44,22 @@ jobs:
5544
5645
tar -zxf extractor-iac.tar.gz
5746
58-
# cache the extractor pack
59-
- name: Cache Extractor Pack
60-
uses: actions/cache@v4
61-
with:
62-
path: extractor-pack
63-
key: extractor-pack
47+
- uses: dtolnay/rust-toolchain@nightly
48+
if: steps.extractor-changes.outputs.src == 'true'
6449

65-
tests:
66-
runs-on: ubuntu-latest
67-
needs: [extractor]
68-
strategy:
69-
matrix:
70-
test-folders: ["library-tests", "queries-tests"]
71-
steps:
72-
- uses: actions/checkout@v4
50+
- name: "Build Extractor"
51+
if: steps.extractor-changes.outputs.src == 'true'
52+
env:
53+
GH_TOKEN: ${{ github.token }}
54+
run: |
55+
gh extensions install github/gh-codeql
56+
gh codeql set-version latest
7357
74-
# download from cache
75-
- name: "Download from cache"
76-
uses: actions/cache@v4
77-
with:
78-
path: extractor-pack
79-
key: extractor-pack
58+
./scripts/create-extractor-pack.sh
8059
81-
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
82-
id: changes
83-
with:
84-
filters: |
85-
src:
86-
- 'ql/**'
60+
gh codeql resolve languages --format=json --search-path ./extractor-pack
8761
8862
- name: "Run Tests"
89-
if: steps.changes.outputs.src == 'true'
9063
env:
9164
GH_TOKEN: ${{ github.token }}
9265
run: |

.github/workflows/publish.yml

+36-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,40 @@ permissions:
1010
packages: write
1111

1212
jobs:
13+
release-check:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
release: ${{ steps.get_version.outputs.release }}
17+
version: ${{ steps.get_version.outputs.version }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: "Check release version"
22+
id: get_version
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
run: |
26+
set -e
27+
28+
pip install yq
29+
current_version=$(cat .release.yml | yq -r ".version")
30+
31+
released_version=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/:owner/:repo/releases/latest | jq -r ".tag_name")
32+
33+
if [[ "$current_version" == "NA" || "$current_version" == "$released_version" ]]; then
34+
echo "No new release found"
35+
echo "release=false" >> "$GITHUB_OUTPUT"
36+
else
37+
echo "New release found"
38+
echo "version=$current_version" >> "$GITHUB_OUTPUT"
39+
echo "release=true" >> "$GITHUB_OUTPUT"
40+
fi
41+
42+
1343
queries:
1444
runs-on: ubuntu-latest
45+
needs: [release-check]
46+
if: ${{ needs.release-check.outputs.release == 'true' }}
1547

1648
permissions:
1749
contents: read
@@ -23,7 +55,8 @@ jobs:
2355
packs: ["lib", "src"]
2456

2557
steps:
26-
- uses: actions/checkout@v4
58+
- name: "Checkout"
59+
uses: actions/checkout@v4
2760

2861
- name: "Check and Publish CodeQL Packs"
2962
env:
@@ -45,6 +78,8 @@ jobs:
4578
4679
compile:
4780
runs-on: ubuntu-latest
81+
needs: [release-check]
82+
if: ${{ needs.release-check.outputs.release == 'true' }}
4883

4984
steps:
5085
- uses: actions/checkout@v4

.github/workflows/release.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# GitHub Releasing Workflow
2+
name: GitHub - Release
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
bump:
8+
type: choice
9+
description: "The type of version bump to perform"
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
release-next:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: "Checkout"
24+
uses: actions/checkout@v4
25+
26+
- name: "Patch Release Me"
27+
uses: 42ByteLabs/[email protected]
28+
with:
29+
mode: ${{ github.event.inputs.bump }}
30+
31+
- name: "Bundle"
32+
run: |
33+
set -e
34+
cd .github/action
35+
npm i && npm run bundle
36+
37+
- name: "Get Version"
38+
id: get_version
39+
run: |
40+
set -e
41+
pip install yq
42+
echo "version=$(cat .release.yml | yq -r ".version")" >> "$GITHUB_ENV"
43+
echo "release=true" >> "$GITHUB_ENV"
44+
45+
- name: "Create Release"
46+
uses: peter-evans/create-pull-request@v6
47+
with:
48+
token: ${{ github.token }}
49+
commit-message: "[chore]: Create release for ${{ steps.get_version.outcome.version }}"
50+
title: "[chore]: Create release for ${{ steps.get_version.outcome.version }}"
51+
branch: chore-release-${{ steps.get_version.outcome.version }}
52+
labels: version
53+
body: |
54+
This is an automated PR to create a new release. The release will be created once this PR is merged.

0 commit comments

Comments
 (0)