Skip to content

Commit f29813b

Browse files
authored
QL: Merge pull request #131 from github/esbena/workflow-improvements
Misc. workflow improvements
2 parents efff86e + dc715af commit f29813b

File tree

3 files changed

+178
-152
lines changed

3 files changed

+178
-152
lines changed

.github/workflows/bleeding-codeql-analysis.yml

Lines changed: 15 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -12,146 +12,43 @@ on:
1212

1313
jobs:
1414

15-
build_query_pack:
16-
runs-on: ubuntu-latest-xl
17-
steps:
18-
- uses: actions/checkout@v2
19-
- name: Find codeql
20-
id: find-codeql
21-
uses: github/codeql-action/init@esbena/ql
22-
with:
23-
languages: javascript # does not matter
24-
- name: Build query pack
25-
run: |
26-
cd ql/src
27-
"${CODEQL}" pack create
28-
cd .codeql/pack/codeql/ql-all/0.0.0
29-
zip "${PACKZIP}" -r .
30-
env:
31-
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
32-
PACKZIP: ${{ runner.temp }}/query-pack.zip
33-
- name: Upload query pack
34-
uses: actions/upload-artifact@v2
35-
with:
36-
name: query-pack
37-
path: ${{ runner.temp }}/query-pack.zip
38-
39-
# XXX this is mostly an inlined copy of the 'build' job in build.yml
40-
build_extractor_pack:
41-
strategy:
42-
matrix:
43-
os: [ubuntu-latest]
44-
45-
runs-on: ${{ matrix.os }}
46-
47-
steps:
48-
- uses: actions/checkout@v2
49-
- uses: actions/cache@v2
50-
with:
51-
path: |
52-
~/.cargo/registry
53-
~/.cargo/git
54-
target
55-
key: ${{ runner.os }}-rust-cargo-${{ hashFiles('**/Cargo.lock') }}
56-
- name: Check formatting
57-
run: cargo fmt --all -- --check
58-
- name: Build
59-
run: cargo build --verbose
60-
- name: Run tests
61-
run: cargo test --verbose
62-
- name: Release build
63-
run: cargo build --release
64-
- name: Generate dbscheme
65-
run: target/release/ql-generator --dbscheme ql/src/ql.dbscheme --library ql/src/codeql_ql/ast/internal/TreeSitter.qll
66-
- uses: actions/upload-artifact@v2
67-
with:
68-
name: ql.dbscheme
69-
path: ql/src/ql.dbscheme
70-
- uses: actions/upload-artifact@v2
71-
with:
72-
name: TreeSitter.qll
73-
path: ql/src/codeql_ql/ast/internal/TreeSitter.qll
74-
- uses: actions/upload-artifact@v2
75-
with:
76-
name: extractor-${{ matrix.os }}
77-
path: |
78-
target/release/ql-extractor
79-
retention-days: 1
80-
# XXX this is mostly an inlined copy of the 'package' job in build.yml
81-
- run: |
82-
mkdir -p ${PACK_DIR}
83-
env:
84-
PACK_DIR: ${{ runner.temp }}/pack
85-
86-
- name: Pack
87-
working-directory: ${{ runner.temp }}/pack
88-
run: |
89-
mkdir -p ql
90-
cp -r "${CHECKOUT}/codeql-extractor.yml" "${CHECKOUT}/tools" "${CHECKOUT}/ql/src/ql.dbscheme" "${CHECKOUT}/ql/src/ql.dbscheme.stats" ql/
91-
mkdir -p ql/tools/linux64
92-
cp "${CHECKOUT}/target/release/ql-extractor" ql/tools/linux64/extractor
93-
chmod +x ql/tools/linux64/extractor
94-
zip -rq codeql-ql.zip ql
95-
env:
96-
CHECKOUT: ${{ github.workspace }}
97-
98-
- uses: actions/upload-artifact@v2
99-
with:
100-
name: extractor-pack
101-
path: ${{ runner.temp }}/pack/codeql-ql.zip
102-
retention-days: 1
15+
build:
16+
uses: github/codeql-ql/.github/workflows/build.yml@esbena/workflow-improvements
17+
with:
18+
os: '[ "ubuntu-latest" ]'
10319

10420
analyze:
10521
name: Analyze
10622
needs:
107-
- build_query_pack
108-
- build_extractor_pack
23+
- build
10924

110-
runs-on: ubuntu-latest-xl
25+
runs-on: ubuntu-latest
11126

11227
permissions:
11328
actions: read
11429
contents: read
11530
security-events: write
11631

11732
steps:
118-
- name: Download query pack
33+
- name: Download pack
11934
uses: actions/download-artifact@v2
12035
with:
121-
name: query-pack
122-
path: ${{ runner.temp }}/query-pack-artifact
36+
name: codeql-ql-pack
37+
path: ${{ runner.temp }}/codeql-ql-pack-artifact
12338

124-
- name: Download extractor pack
125-
uses: actions/download-artifact@v2
126-
with:
127-
name: extractor-pack
128-
path: ${{ runner.temp }}/extractor-pack-artifact
129-
130-
- name: Prepare packs
131-
id: prepare-packs
39+
- name: Prepare pack
13240
run: |
133-
set -x
134-
mkdir -p "${COMPLETE_PACK}" "${PACKS_TMP}"
135-
cd "${PACKS_TMP}"
136-
unzip "${QUERY_PACK_ARTIFACT}/*.zip" -d query-pack-artifact-unzipped
137-
cp -r query-pack-artifact-unzipped/. "${COMPLETE_PACK}"
138-
unzip "${EXTRACTOR_PACK_ARTIFACT}/*.zip" -d extractor-pack-artifact-unzipped
139-
cp -r extractor-pack-artifact-unzipped/ql/. "${COMPLETE_PACK}"
140-
cd "${COMPLETE_PACK}"
141-
zip "${COMPLETE_PACK_ZIP}" -r .
41+
unzip "${PACK_ARTIFACT}/*.zip" -d "${PACK}"
14242
env:
143-
PACKS_TMP: ${{ runner.temp }}/pack-artifacts.tmp
144-
QUERY_PACK_ARTIFACT: ${{ runner.temp }}/query-pack-artifact
145-
EXTRACTOR_PACK_ARTIFACT: ${{ runner.temp }}/extractor-pack-artifact
146-
COMPLETE_PACK: ${{ runner.temp }}/pack
147-
COMPLETE_PACK_ZIP: ${{ runner.temp }}/pack.zip
43+
PACK_ARTIFACT: ${{ runner.temp }}/codeql-ql-pack-artifact
44+
PACK: ${{ runner.temp }}/pack
14845

14946
- name: Hack codeql-action options
15047
run: |
151-
JSON=$(jq -nc --arg pack "${COMPLETE_PACK}" '.resolve.queries=["--search-path", $pack] | .resolve.extractor=["--search-path", $pack] | .database.init=["--search-path", $pack]')
48+
JSON=$(jq -nc --arg pack "${PACK}" '.resolve.queries=["--search-path", $pack] | .resolve.extractor=["--search-path", $pack] | .database.init=["--search-path", $pack]')
15249
echo "CODEQL_ACTION_EXTRA_OPTIONS=${JSON}" >> ${GITHUB_ENV}
15350
env:
154-
COMPLETE_PACK: ${{ runner.temp }}/pack
51+
PACK: ${{ runner.temp }}/pack
15552

15653
- name: Checkout repository
15754
uses: actions/checkout@v2
@@ -172,9 +69,3 @@ jobs:
17269
path: ${{ runner.temp }}/db
17370
retention-days: 1
17471

175-
- name: Upload complete pack
176-
uses: actions/upload-artifact@v2
177-
with:
178-
name: complete-pack
179-
path: ${{ runner.temp }}/pack.zip
180-
retention-days: 1

.github/workflows/build.yml

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
name: Rust
1+
name: Build codeql-ql-pack
22

33
on:
44
push:
55
branches: [main]
66
pull_request:
77
branches: [main]
8+
workflow_call:
9+
inputs:
10+
os:
11+
description: A JSON array string of (fixed) operating systems to build for, e.g. '["ubuntu-latest", "macos-latest", "windows-latest"]'
12+
required: false
13+
type: string
814

915
env:
1016
CARGO_TERM_COLOR: always
1117

1218
jobs:
13-
build:
19+
queries:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Find codeql
24+
id: find-codeql
25+
uses: github/codeql-action/init@esbena/ql
26+
with:
27+
languages: javascript # does not matter
28+
- name: Build query pack
29+
run: |
30+
cd ql/src
31+
"${CODEQL}" pack create
32+
cd .codeql/pack/codeql/ql-all/0.0.0
33+
zip "${PACKZIP}" -r .
34+
env:
35+
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
36+
PACKZIP: ${{ runner.temp }}/query-pack.zip
37+
- name: Upload query pack
38+
uses: actions/upload-artifact@v2
39+
with:
40+
name: query-pack-zip
41+
path: ${{ runner.temp }}/query-pack.zip
42+
43+
extractors:
1444
strategy:
1545
fail-fast: false
1646
matrix:
17-
os: [ubuntu-latest, macos-latest]
18-
#os: [ubuntu-latest, macos-latest, windows-latest]
47+
os: ${{ fromJson(inputs.os || '["ubuntu-latest", "macos-latest", "windows-latest"]') }}
1948

2049
runs-on: ${{ matrix.os }}
2150

@@ -44,16 +73,6 @@ jobs:
4473
- name: Generate dbscheme
4574
if: ${{ matrix.os == 'ubuntu-latest' }}
4675
run: target/release/ql-generator --dbscheme ql/src/ql.dbscheme --library ql/src/codeql_ql/ast/internal/TreeSitter.qll
47-
- uses: actions/upload-artifact@v2
48-
if: ${{ matrix.os == 'ubuntu-latest' }}
49-
with:
50-
name: ql.dbscheme
51-
path: ql/src/ql.dbscheme
52-
- uses: actions/upload-artifact@v2
53-
if: ${{ matrix.os == 'ubuntu-latest' }}
54-
with:
55-
name: TreeSitter.qll
56-
path: ql/src/codeql_ql/ast/internal/TreeSitter.qll
5776
- uses: actions/upload-artifact@v2
5877
with:
5978
name: extractor-${{ matrix.os }}
@@ -63,33 +82,49 @@ jobs:
6382
retention-days: 1
6483
package:
6584
runs-on: ubuntu-latest
66-
needs: build
85+
86+
needs:
87+
- extractors
88+
- queries
89+
6790
steps:
6891
- uses: actions/checkout@v2
6992
- uses: actions/download-artifact@v2
7093
with:
71-
name: ql.dbscheme
72-
path: ql
94+
name: query-pack-zip
95+
path: query-pack-zip
7396
- uses: actions/download-artifact@v2
97+
if: ${{ contains(fromJson(inputs.os || '["ubuntu-latest", "macos-latest", "windows-latest"]'), 'ubuntu-latest') }}
7498
with:
7599
name: extractor-ubuntu-latest
76100
path: linux64
77-
# - uses: actions/download-artifact@v2
78-
# with:
79-
# name: extractor-windows-latest
80-
# path: win64
81101
- uses: actions/download-artifact@v2
102+
if: ${{ contains(fromJson(inputs.os || '["ubuntu-latest", "macos-latest", "windows-latest"]'), 'windows-latest') }}
103+
with:
104+
name: extractor-windows-latest
105+
path: win64
106+
- uses: actions/download-artifact@v2
107+
if: ${{ contains(fromJson(inputs.os || '["ubuntu-latest", "macos-latest", "windows-latest"]'), 'macos-latest') }}
82108
with:
83109
name: extractor-macos-latest
84110
path: osx64
85111
- run: |
86-
mkdir -p ql
87-
cp -r codeql-extractor.yml tools ql/src/ql.dbscheme.stats ql/
88-
mkdir -p ql/tools/{linux64,osx64}
89-
cp linux64/ql-extractor ql/tools/linux64/extractor
90-
cp osx64/ql-extractor ql/tools/osx64/extractor
91-
chmod +x ql/tools/{linux64,osx64}/extractor
92-
zip -rq codeql-ql.zip ql
112+
unzip query-pack-zip/*.zip -d pack
113+
cp -r codeql-extractor.yml tools ql/src/ql.dbscheme.stats pack/
114+
mkdir -p pack/tools/{linux64,osx64,win64}
115+
if [[ -f linux64/ql-extractor ]]; then
116+
cp linux64/ql-extractor pack/tools/linux64/extractor
117+
chmod +x pack/tools/linux64/extractor
118+
fi
119+
if [[ -f osx64/ql-extractor ]]; then
120+
cp osx64/ql-extractor pack/tools/osx64/extractor
121+
chmod +x pack/tools/osx64/extractor
122+
fi
123+
if [[ -f win64/ql-extractor.exe ]]; then
124+
cp win64/ql-extractor.exe pack/tools/win64/extractor
125+
fi
126+
cd pack
127+
zip -rq ../codeql-ql.zip .
93128
- uses: actions/upload-artifact@v2
94129
with:
95130
name: codeql-ql-pack

0 commit comments

Comments
 (0)