Skip to content

Commit 0038666

Browse files
committed
Swift: rework workflows
* A unique workflow file has been created merging all `swift-*.yml` workflows * Change filtering at job level was added using [dorny/paths-filter][1] * only one build of the extractor is made, and then shared via cache (not as an artifact because of [this longstading issue][2]) * integration tests are now run on on macOS * qltests are not run any more on macOS to cut on feedback time * autobuilder tests were moved to the macOS build step to avoid loading bazel twice [1]: https://github.com/dorny/paths-filter#examples [2]: actions/upload-artifact#38
1 parent 21600c6 commit 0038666

File tree

9 files changed

+205
-175
lines changed

9 files changed

+205
-175
lines changed

.github/workflows/swift-autobuilder.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/swift-codegen.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/swift-integration-tests.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/swift-qltest.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/swift.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: "Swift"
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "swift/**"
7+
- "misc/bazel/**"
8+
- "*.bazel*"
9+
- .github/workflows/swift.yml
10+
- .github/actions/fetch-codeql/action.yml
11+
- codeql-workspace.yml
12+
- .pre-commit-config.yaml
13+
- "!**/*.md"
14+
- "!**/*.qhelp"
15+
branches:
16+
- main
17+
defaults:
18+
run:
19+
working-directory: swift
20+
21+
jobs:
22+
changes:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
codegen: ${{ steps.filter.outputs.codegen }}
26+
ql: ${{ steps.filter.outputs.ql }}
27+
steps:
28+
- uses: dorny/paths-filter@v2
29+
id: filter
30+
with:
31+
filters: |
32+
codegen:
33+
- 'github/workflows/swift.yml'
34+
- "misc/bazel/**"
35+
- "*.bazel*"
36+
- 'swift/actions/env-setup/**'
37+
- '.pre-commit-config.yaml'
38+
- 'swift/codegen/**'
39+
- 'swift/schema.py'
40+
- 'swift/**/*.dbscheme'
41+
- 'swift/ql/lib/codeql/swift/elements.qll'
42+
- 'swift/ql/lib/codeql/swift/elements/**'
43+
- 'swift/ql/lib/codeql/swift/generated/**'
44+
- 'swift/ql/test/extractor-tests/generated/**'
45+
ql:
46+
- 'github/workflows/swift.yml'
47+
- 'swift/**/*.ql'
48+
- 'swift/**/*.qll'
49+
# not using a matrix as you cannot depend on a specific job in a matrix, and we want to start linux checks
50+
# without waiting for the macOS build
51+
build-macos:
52+
runs-on: macos-latest
53+
steps:
54+
- uses: actions/checkout@v3
55+
- uses: ./swift/actions/create-extractor-pack
56+
# loading bazel targets is very long on the basic macOS runner
57+
# therefore it's better to test the X
58+
- name: Test the Xcode autobuilder
59+
run: |
60+
bazel test //swift/xcode-autobuilder/tests
61+
build-linux:
62+
runs-on: ubuntu-20.04
63+
steps:
64+
- uses: actions/checkout@v3
65+
- uses: ./swift/actions/create-extractor-pack
66+
qltests:
67+
needs: build-linux
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v3
71+
- uses: ./swift/actions/env-setup
72+
- uses: ./swift/actions/share-extractor-pack
73+
- name: Test qltest.sh
74+
run: |
75+
bazel test //swift/tools/test/qltest
76+
- uses: ./.github/actions/fetch-codeql
77+
- name: Run QL tests
78+
run: |
79+
codeql test run \
80+
--threads=0 \
81+
--ram 5000 \
82+
--search-path "${{ github.workspace }}/swift/extractor-pack" \
83+
--check-databases \
84+
--check-unused-labels \
85+
--check-repeated-labels \
86+
--check-redefined-labels \
87+
--check-use-before-definition \
88+
ql/test
89+
env:
90+
GITHUB_TOKEN: ${{ github.token }}
91+
integration-tests-linux:
92+
needs: build-linux
93+
runs-on: ubuntu-latest
94+
steps:
95+
- uses: actions/checkout@v3
96+
- uses: ./swift/actions/run-integration-tests
97+
integration-tests-macos:
98+
needs: build-macos
99+
runs-on: macos-latest
100+
steps:
101+
- uses: actions/checkout@v3
102+
- uses: ./swift/actions/run-integration-tests
103+
codegen:
104+
runs-on: ubuntu-latest
105+
needs: changes
106+
if: ${{ needs.changes.outputs.codegen == 'true' }}
107+
steps:
108+
- uses: actions/checkout@v3
109+
- uses: ./swift/actions/env-setup
110+
- uses: pre-commit/[email protected]
111+
name: Check that python code is properly formatted
112+
with:
113+
extra_args: autopep8 --all-files
114+
- name: Run unit tests
115+
run: |
116+
bazel test //swift/codegen/test --test_output=errors
117+
- uses: ./.github/actions/fetch-codeql
118+
- uses: pre-commit/[email protected]
119+
name: Check that QL generated code was checked in
120+
with:
121+
extra_args: swift-codegen --all-files
122+
- name: Generate C++ files
123+
run: |
124+
bazel run //swift/codegen:codegen -- --generate=trap,cpp --cpp-output=$PWD/generated-cpp-files
125+
- uses: actions/upload-artifact@v3
126+
with:
127+
name: swift-generated-cpp-files
128+
path: swift/generated-cpp-files/**
129+
qlformat:
130+
runs-on: ubuntu-latest
131+
needs: changes
132+
if: ${{ needs.changes.outputs.ql == 'true' }}
133+
steps:
134+
- uses: actions/checkout@v3
135+
- uses: ./.github/actions/fetch-codeql
136+
- name: Check QL formatting
137+
run: find ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 codeql query format --check-only
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Build Swift CodeQL pack
2+
description: Builds the Swift CodeQL pack
3+
runs:
4+
using: composite
5+
steps:
6+
- uses: ./swift/actions/env-setup
7+
- uses: ./swift/actions/share-extractor-pack
8+
- name: Build Swift extractor
9+
shell: bash
10+
run: |
11+
bazel run //swift:create-extractor-pack

swift/actions/env-setup/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Setup Swift Package Environment
2+
description: Sets up the environment in which to build the Swift package and run its tests
3+
runs:
4+
using: composite
5+
steps:
6+
- uses: bazelbuild/setup-bazelisk@v2
7+
- uses: actions/setup-python@v4
8+
with:
9+
python-version-file: 'swift/.python-version'
10+
- name: Mount bazel cache
11+
uses: actions/cache@v3
12+
with:
13+
path: "~/.cache/bazel-repository-cache"
14+
key: bazel-cache-${{ runner.os }}-${{ runner.arch }}
15+
- name: Mount bazel disk cache
16+
uses: actions/cache@v3
17+
with:
18+
path: "~/.cache/bazel-disk-cache"
19+
key: bazel-disk-cache-${{ runner.os }}-${{ runner.arch }}
20+
- name: Set up bazel disk cache
21+
shell: bash
22+
run: |
23+
echo build --repository_cache=~/.cache/bazel-repository-cache --disk_cache=~/.cache/bazel-disk-cache > ~/.bazelrc
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build Swift CodeQL pack
2+
description: Builds the Swift CodeQL pack
3+
runs:
4+
using: composite
5+
steps:
6+
- uses: ./swift/actions/share-extractor-pack
7+
- name: Get Swift version
8+
id: get_swift_version
9+
shell: bash
10+
run: |
11+
VERSION=$(swift/extractor-pack/tools/*/extractor --version | awk '/version/ { print $3 }')
12+
echo "version=$VERSION" | tee -a $GITHUB_OUTPUT
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version-file: 'swift/.python-version'
16+
- uses: swift-actions/setup-swift@v1
17+
with:
18+
swift-version: "${{steps.get_swift_version.outputs.version}}"
19+
- uses: ./.github/actions/fetch-codeql
20+
- name: Run integration tests
21+
shell: bash
22+
run: |
23+
python swift/integration-tests/runner.py
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Build Swift CodeQL pack
2+
description: Builds the Swift CodeQL pack
3+
runs:
4+
using: composite
5+
steps:
6+
# not using artifacts because of annoying https://github.com/actions/upload-artifact/issues/38
7+
- name: Mount cache for sharing extractor pack
8+
uses: actions/cache@v3
9+
with:
10+
path: swift/extractor-pack
11+
key: extractor-pack-${{ github.run_id }}-${{ github.run_number }}-${{ runner.os }}

0 commit comments

Comments
 (0)