Skip to content

Commit 76f94f6

Browse files
authored
Merge pull request #220 from advanced-security/ci-updates
feat: Enhance extractor pack workflow with compile and bundle jobs
2 parents 48bbd09 + ce9b013 commit 76f94f6

File tree

7 files changed

+111
-39
lines changed

7 files changed

+111
-39
lines changed

.github/workflows/publish.yml

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,65 @@ jobs:
3939
echo "release=true" >> "$GITHUB_OUTPUT"
4040
fi
4141
42+
compile:
43+
name: "Compile Extractor Pack for ${{ matrix.os }}"
44+
needs: [release-check]
45+
46+
runs-on: ${{ matrix.os }}
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
# TODO: Add windows-latest
51+
os: [ubuntu-latest, macos-latest]
52+
53+
if: ${{ needs.release-check.outputs.release == 'true' }}
54+
steps:
55+
- name: "Checkout"
56+
uses: actions/checkout@v5
57+
with:
58+
submodules: true
59+
60+
- name: "Set up Rust"
61+
uses: dtolnay/rust-toolchain@nightly
62+
if: ${{ matrix.os != 'windows-latest' }}
63+
64+
- name: "Build Extractor"
65+
if: ${{ matrix.os != 'windows-latest' }}
66+
env:
67+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
run: ./scripts/create-extractor-pack.sh
69+
70+
- name: "Upload bundle artifact"
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: "extractor-bundle-${{ matrix.os }}"
74+
path: "./extractor-pack"
75+
76+
bundle:
77+
name: "Bundle Extractor Pack"
78+
runs-on: ubuntu-latest
79+
needs: [compile]
80+
if: ${{ needs.release-check.outputs.release == 'true' }}
81+
82+
steps:
83+
- name: "Checkout"
84+
uses: actions/checkout@v5
85+
with:
86+
submodules: true
87+
88+
- name: "Downloadd all artifacts"
89+
uses: actions/download-artifact@v4
90+
with:
91+
path: "./extractor-pack"
92+
merge-multiple: true
93+
94+
- name: "Publish Extractor Pack"
95+
if: github.ref == 'refs/heads/main'
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
EXTRACTOR_NAME: "iac"
99+
run: |
100+
./scripts/publish-extractor-pack.sh
42101
43102
queries:
44103
runs-on: ubuntu-latest
@@ -61,32 +120,24 @@ jobs:
61120
- name: "Check and Publish CodeQL Packs"
62121
env:
63122
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
PACKS: ${{ matrix.packs }}
124+
ORG: ${{ github.repository_owner }}
64125
run: |
65-
PACK_PATH=ql/${{ matrix.packs }}/qlpack.yml
126+
set -e
127+
128+
PACK_PATH="ql/${PACKS}/qlpack.yml"
129+
echo "[+] Pack Path :: $PACK_PATH"
130+
66131
CURRENT_VERSION=$(grep version $PACK_PATH | awk '{print $2}')
67132
PACK_FULLNAME=$(cat $PACK_PATH | grep "name:" | awk '{print $2}')
68133
PACK_NAME=$(echo $PACK_FULLNAME | awk -F '/' '{print $2}')
134+
echo "[+] Pack Name :: $PACK_NAME ($PACK_FULLNAME)"
69135
70-
PUBLISHED_VERSION=$(gh api /orgs/advanced-security/packages/container/$PACK_NAME/versions --jq '.[0].metadata.container.tags[0]')
136+
PUBLISHED_VERSION=$(gh api /orgs/${ORG}/packages/container/$PACK_NAME/versions --jq '.[0].metadata.container.tags[0]')
71137
echo "Packs :: ${CURRENT_VERSION} -> ${PUBLISHED_VERSION}"
72138
73139
if [ "$PUBLISHED_VERSION" != "$CURRENT_VERSION" ]; then
74140
gh extension install github/gh-codeql
75-
gh codeql pack install "ql/${{ matrix.packs }}"
76-
gh codeql pack publish "ql/${{ matrix.packs }}"
141+
gh codeql pack install "ql/${PACKS}"
142+
gh codeql pack publish "ql/${PACKS}"
77143
fi
78-
79-
compile:
80-
runs-on: ubuntu-latest
81-
needs: [release-check]
82-
if: ${{ needs.release-check.outputs.release == 'true' }}
83-
84-
steps:
85-
- uses: actions/checkout@v5
86-
87-
- name: "Publish Extractor Pack"
88-
if: github.ref == 'refs/heads/main'
89-
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91-
run: |
92-
./scripts/publish-extractor-pack.sh

codeql-extractor.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ legacy_qltest_extraction: true
66
github_api_languages:
77
- HCL
88
- Docker
9-
- Bicep
109
scc_languages:
1110
- HCL
1211
- Docker
13-
- Bicep
1412

1513
# File types
1614
file_types:
@@ -26,8 +24,3 @@ file_types:
2624
extensions:
2725
- .Dockerfile
2826
- .Containerfile
29-
30-
- name: bicep
31-
display_name: Bicep
32-
extensions:
33-
- .bicep

ql/lib/codeql/hcl/Providers.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import providers.Alicloud
2+
import providers.AWS
3+
import providers.Azure
4+
import providers.GCP
5+
import providers.GitHub
6+
import providers.Helm
7+
import providers.Kubernetes
8+
import providers.OCI

ql/lib/codeql/hcl/Security.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import security.HardcodedPasswords

ql/lib/hcl.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import codeql.hcl.Constants
66
import codeql.hcl.Locals
77
import codeql.hcl.Terraform
88
// providers
9-
import codeql.hcl.providers.AWS
10-
import codeql.hcl.providers.Azure
11-
import codeql.hcl.providers.GCP
12-
import codeql.hcl.providers.Helm
9+
import codeql.hcl.Providers
1310
// security
14-
import codeql.hcl.security.HardcodedPasswords
11+
import codeql.hcl.Security

scripts/create-extractor-pack.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,3 @@ mkdir -p extractor-pack
3434
cp -r codeql-extractor.yml downgrades tools ql/lib/iac.dbscheme ql/lib/iac.dbscheme.stats extractor-pack/
3535
mkdir -p extractor-pack/tools/${platform}
3636
cp target/release/codeql-extractor-iac extractor-pack/tools/${platform}/extractor
37-
38-
# pushd ql/lib
39-
# $CODEQL_BINARY pack installl .
40-
# $CODEQL_BINARY pack create --output=$HOME/.codeql/packages .
41-
# popd

scripts/publish-extractor-pack.sh

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
#!/bin/bash
2+
set -eux
3+
4+
DRY_RUN=${DRY_RUN:-false}
25

36
# Extractor info
47
EXTRACTOR_INFO="./codeql-extractor.yml"
5-
EXTRACTOR_NAME="iac"
8+
EXTRACTOR_NAME="${EXTRACTOR_NAME:-$(basename $(dirname $EXTRACTOR_INFO))}"
69
EXTRACTOR_VERSION=$(grep version $EXTRACTOR_INFO | awk '{print $2}')
710

811
LATEST_RELEASE=$(gh release list | head -n 1 | awk '{print $1}' | sed 's/v//')
912

13+
if which codeql >/dev/null 2>&1; then
14+
CODEQL_BINARY="codeql"
15+
elif gh codeql version >/dev/null 2>&1; then
16+
CODEQL_BINARY="gh codeql"
17+
else
18+
gh extension install github/gh-codeql
19+
CODEQL_BINARY="gh codeql"
20+
fi
21+
1022
echo "[+] ${EXTRACTOR_NAME} (${EXTRACTOR_VERSION})"
1123
echo "[+] Last release: ${LATEST_RELEASE}"
1224

1325
if [ "$LATEST_RELEASE" != "$EXTRACTOR_VERSION" ]; then
1426
echo "[+] New Extractor version being released"
1527

16-
# create extractor pack
17-
./scripts/create-extractor-pack.sh
28+
# Check extracrtor-pack
29+
if [ ! -d "extractor-pack" ]; then
30+
echo "[+] No extractor-pack found"
31+
exit 1
32+
fi
33+
34+
echo "[+] Install pack dependencies"
35+
$CODEQL_BINARY pack install "./ql/lib"
36+
37+
echo "[+] Add queries to extractor-pack"
38+
$CODEQL_BINARY pack create --output="./extractor-pack/qlpacks" "./ql/lib"
39+
$CODEQL_BINARY pack create --output="./extractor-pack/qlpacks" "./ql/src"
1840

1941
# bundle extractor
2042
tar czf extractor-$EXTRACTOR_NAME.tar.gz extractor-pack
2143

44+
if [ "$DRY_RUN" = "true" ]; then
45+
echo "[+] Dry run - skipping release"
46+
exit 0
47+
fi
48+
2249
export GH_TOKEN=$GITHUB_TOKEN
2350

2451
# create release

0 commit comments

Comments
 (0)