Skip to content

Commit e0aa0f7

Browse files
authored
Add Swift to CodeQL again (#4722)
1 parent 2f55a14 commit e0aa0f7

File tree

4 files changed

+14
-36
lines changed

4 files changed

+14
-36
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ To run the tests locally, **you will need the following dependencies**:
306306
- **Python 3.9+**: our build system is constructed with Python given that
307307
testing is built with glotter, a Python testing library that leverages docker.
308308
- **Poetry**: our build system is managed and versioned using Poetry. Make sure
309-
to use version **2.1.1** or later. If you are using an older version, please
309+
to use version **2.1.3** or later. If you are using an older version, please
310310
update to the latest.
311311

312312
With all three installed, the remaining dependencies can be installed using

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ on:
1616
branches: [ main ]
1717
paths:
1818
- '.github/workflows/codeql-analysis.yml'
19-
- 'repo-config.yml'
2019
- 'scripts/*.py'
21-
- 'pyproject.toml'
22-
- 'poetry.lock'
2320
- 'archive/c/c/*.c'
2421
- 'archive/c/c/testinfo.yml'
2522
- 'archive/c/c-plus-plus/*.cpp'
@@ -45,10 +42,7 @@ on:
4542
- 'main'
4643
paths:
4744
- '.github/workflows/codeql-analysis.yml'
48-
- 'repo-config.yml'
4945
- 'scripts/*.py'
50-
- 'pyproject.toml'
51-
- 'poetry.lock'
5246
- 'archive/c/c/*.c'
5347
- 'archive/c/c/testinfo.yml'
5448
- 'archive/c/c-plus-plus/*.cpp'
@@ -129,25 +123,6 @@ jobs:
129123
with:
130124
fetch-depth: 2
131125

132-
- name: Read repo config
133-
uses: pietrobolcato/[email protected]
134-
id: repo-config
135-
with:
136-
config: repo-config.yml
137-
138-
- name: Set up Python
139-
uses: actions/setup-python@v5
140-
with:
141-
python-version: "${{ steps.repo-config.outputs['python-version'] }}"
142-
143-
- name: Run Poetry Image
144-
uses: abatilo/actions-poetry@v3
145-
with:
146-
poetry-version: "${{ steps.repo-config.outputs['poetry-version'] }}"
147-
148-
- name: Install Dependencies
149-
run: poetry install
150-
151126
# Initializes the CodeQL tools for scanning.
152127
- name: Initialize CodeQL
153128
uses: github/codeql-action/init@v3
@@ -170,7 +145,7 @@ jobs:
170145

171146
- name: Manual build
172147
if: ${{ matrix.build-mode == 'manual' }}
173-
run: poetry run python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }}
148+
run: python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }}
174149

175150
- name: Perform CodeQL Analysis
176151
uses: github/codeql-action/analyze@v3

scripts/build_codeql_language.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import argparse
2+
import re
23
import shlex
34
import subprocess
45
from dataclasses import dataclass
56
from pathlib import Path
67
from typing import Dict, List
78

8-
from glotter.source import Source
9-
109
TEST_INFO_DIR: Dict[str, str] = {
1110
"c": "c",
1211
"cpp": "c-plus-plus",
1312
"java": "java",
1413
"kotlin": "kotlin",
14+
"swift": "swift",
1515
}
1616

17+
BUILD_PATTERN = re.compile(r"""^\s+build:\s*['"]([^'"]+)""", re.M)
18+
SOURCE_NAME_PATTERN = re.compile(r"\{\{\s*source\.name\s*\}\}")
19+
SOURCE_EXTENSION_PATTERN = re.compile(r"\{\{\s*source\.extension\s*\}\}")
20+
1721

1822
@dataclass
1923
class TestInfoStruct:
@@ -42,13 +46,11 @@ def get_test_info_struct(language: str) -> TestInfoStruct:
4246

4347

4448
def get_build_command(testinfo_struct: TestInfoStruct, path: Path) -> List[str]:
45-
source = Source(
46-
name=path.name,
47-
language=testinfo_struct.language,
48-
path=str(path),
49-
test_info_string=testinfo_struct.test_info_str,
50-
)
51-
build: str = source.test_info.container_info.build
49+
match_str = BUILD_PATTERN.search(testinfo_struct.test_info_str)
50+
assert match_str
51+
52+
build = SOURCE_NAME_PATTERN.sub(path.stem, match_str.group(1))
53+
build = SOURCE_EXTENSION_PATTERN.sub(path.suffix, build)
5254
return shlex.split(build)
5355

5456

scripts/get_codeql_languages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LanguageInfo:
3030
"archive/p/python/*.py": LanguageInfo(language="python"),
3131
"archive/r/ruby/*.rb": LanguageInfo(language="ruby"),
3232
"archive/t/typescript/*.ts": LanguageInfo(language="typescript"),
33+
"archive/s/swift/*.swift": LanguageInfo(language="swift", build_mode="manual", os=MACOS),
3334
}
3435
ALL_CODEQL_LANGUAGES_FILES = {
3536
".github/workflows/codeql-analysis.yml",

0 commit comments

Comments
 (0)