Skip to content

Commit deec053

Browse files
authored
Update workflow to run swift 6.2 on different machines (#882)
* Update workflow to run on ubuntu * return to 22.04, jq now installed? * setup jq * Don't use jq, fix workflow, add macOS test for generator CLI * Add proper names and remove mac os legacy xcodes. * Adjust workflow * Split the ci into two workflows * Fix names
1 parent aeac671 commit deec053

File tree

4 files changed

+127
-60
lines changed

4 files changed

+127
-60
lines changed

.github/workflows/ci.yml

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

.github/workflows/ci_exercises.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI Exercises
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
10+
jobs:
11+
run-exercises-tests-ubuntu:
12+
name: Run exercise tests for swift ${{ matrix.swift }} on Ubuntu
13+
runs-on: ubuntu-24.04
14+
strategy:
15+
matrix:
16+
swift: ["6.0", "6.1", "6.2"]
17+
container:
18+
image: swift:${{ matrix.swift }}
19+
env:
20+
RUNALL: "true"
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
24+
- name: Run tests
25+
run: swift test
26+
27+
run-exercises-tests-macos:
28+
name: Run exercise tests on macOS ${{ matrix.macOS }} with Xcode ${{ matrix.xcode }}
29+
runs-on: macos-${{ matrix.macOS }}
30+
strategy:
31+
matrix:
32+
include:
33+
- macOS: '26'
34+
xcode: '26.0'
35+
env:
36+
RUNALL: "true"
37+
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
41+
- name: Run tests
42+
run: swift test

.github/workflows/ci_generator.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI Generator
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/ci_generator.yml'
7+
- 'generator/**'
8+
- 'bin/test_generator.sh'
9+
push:
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
jobs:
15+
run-generator-unit-tests:
16+
name: Run generator unit tests
17+
runs-on: ubuntu-24.04
18+
container:
19+
image: swift:6.2
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
23+
- name: Run tests
24+
run: swift test --package-path ./generator
25+
26+
run-generator-usage-tests:
27+
name: Test generator usage on Ubuntu
28+
runs-on: ubuntu-24.04
29+
container:
30+
image: swift:6.2
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
- name: Run generator tests
35+
run: ./bin/test_generator.sh
36+
37+
run-generator-usage-tests-macos:
38+
name: Test generator usage on macOS ${{ matrix.macOS }} with Xcode ${{ matrix.xcode }}
39+
runs-on: macos-${{ matrix.macOS }}
40+
strategy:
41+
matrix:
42+
include:
43+
- macOS: '26'
44+
xcode: '26.0'
45+
env:
46+
RUNALL: "true"
47+
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
51+
- name: Run generator tests
52+
run: ./bin/test_generator.sh

bin/test_generator.sh

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
#!/usr/bin/env bash
22

3-
set -eo pipefail
3+
set -euo pipefail
44

5-
temp=$(mktemp -d)
5+
declare TEMP_DIR
6+
TEMP_DIR=$(mktemp -d)
7+
8+
readonly TEMP_DIR
9+
readonly GENERATOR_DIR="./generator"
10+
readonly PRACTICE_DIR="./exercises/practice"
11+
readonly TEMPLATE_PATH=".meta/template.swift"
612

713
swift build --package-path ./generator
814

9-
for exercise in ./exercises/practice/*; do
10-
if [[ -r "${exercise}/.meta/template.swift" ]]; then
11-
cp -r "$exercise" "$temp"
12-
test_file="${exercise}/$(jq -r '.files.test[0]' ${exercise}/.meta/config.json)"
13-
temp_test_file="${temp}/$(basename "$exercise")/$(jq -r '.files.test[0]' ${exercise}/.meta/config.json)"
14-
swift run --package-path ./generator Generator $(basename "$exercise") "$temp/$(basename "$exercise")"
15-
echo "Comparing $test_file with $temp_test_file"
16-
diff "$temp_test_file" "$test_file"
17-
if [ $? -ne 0 ]; then
18-
exit_code=1
19-
fi
15+
exit_code=0
16+
for exercise_path in "${PRACTICE_DIR}"/*; do
17+
[[ -e "${exercise_path}/${TEMPLATE_PATH}" ]] || continue
18+
19+
cp -r "${exercise_path}"/. "${TEMP_DIR}"
20+
21+
# Minify json and extract test file name
22+
test_file=$(tr -d '\n\r ' < "${exercise_path}"/.meta/config.json | grep -o '"test":\["[^"]*' | sed 's/.*\["//')
23+
original_test="${exercise_path}/${test_file}"
24+
temp_test="${TEMP_DIR}/${test_file}"
25+
26+
exercise_name="${exercise_path##*/}"
27+
28+
if ! swift run --package-path "${GENERATOR_DIR}" Generator "${exercise_name}" "${TEMP_DIR}"; then
29+
printf 'Generation failed for %s\n' "${exercise_name}"
30+
exit_code=1
31+
continue
32+
fi
33+
34+
if ! diff -u -- "${original_test}" "${temp_test}"; then
35+
printf 'Mismatch detected in %s\n' "${exercise_name}"
36+
exit_code=1
37+
else
38+
printf '%s OK\n' "${exercise_name}"
2039
fi
2140
done
2241

23-
exit ${exit_code}
42+
exit "${exit_code}"

0 commit comments

Comments
 (0)