diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 6454e914..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: CI - -on: - pull_request: - push: - branches: - - main - workflow_dispatch: - -jobs: - test: - name: Swift ${{ matrix.swift }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-15] - swift: ["6.1"] - env: - RUNALL: "true" - steps: - - uses: swift-actions/setup-swift@v2 - with: - swift-version: ${{ matrix.swift }} - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - name: Run tests - run: swift test - - generator-tests: - runs-on: macos-15 - env: - RUNALL: "true" - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - - name: Run tests - run: swift test --package-path ./generator - generator-template-tests: - runs-on: macos-15 - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - - name: Run tests - run: ./bin/test_generator.sh diff --git a/.github/workflows/ci_exercises.yml b/.github/workflows/ci_exercises.yml new file mode 100644 index 00000000..1f074d08 --- /dev/null +++ b/.github/workflows/ci_exercises.yml @@ -0,0 +1,42 @@ +name: CI Exercises + +on: + pull_request: + push: + branches: + - main + workflow_dispatch: + +jobs: + run-exercises-tests-ubuntu: + name: Run exercise tests for swift ${{ matrix.swift }} on Ubuntu + runs-on: ubuntu-24.04 + strategy: + matrix: + swift: ["6.0", "6.1", "6.2"] + container: + image: swift:${{ matrix.swift }} + env: + RUNALL: "true" + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Run tests + run: swift test + + run-exercises-tests-macos: + name: Run exercise tests on macOS ${{ matrix.macOS }} with Xcode ${{ matrix.xcode }} + runs-on: macos-${{ matrix.macOS }} + strategy: + matrix: + include: + - macOS: '26' + xcode: '26.0' + env: + RUNALL: "true" + DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Run tests + run: swift test diff --git a/.github/workflows/ci_generator.yml b/.github/workflows/ci_generator.yml new file mode 100644 index 00000000..2998f33f --- /dev/null +++ b/.github/workflows/ci_generator.yml @@ -0,0 +1,52 @@ +name: CI Generator + +on: + pull_request: + paths: + - '.github/workflows/ci_generator.yml' + - 'generator/**' + - 'bin/test_generator.sh' + push: + branches: + - main + workflow_dispatch: + +jobs: + run-generator-unit-tests: + name: Run generator unit tests + runs-on: ubuntu-24.04 + container: + image: swift:6.2 + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Run tests + run: swift test --package-path ./generator + + run-generator-usage-tests: + name: Test generator usage on Ubuntu + runs-on: ubuntu-24.04 + container: + image: swift:6.2 + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run generator tests + run: ./bin/test_generator.sh + + run-generator-usage-tests-macos: + name: Test generator usage on macOS ${{ matrix.macOS }} with Xcode ${{ matrix.xcode }} + runs-on: macos-${{ matrix.macOS }} + strategy: + matrix: + include: + - macOS: '26' + xcode: '26.0' + env: + RUNALL: "true" + DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Run generator tests + run: ./bin/test_generator.sh \ No newline at end of file diff --git a/bin/test_generator.sh b/bin/test_generator.sh index 36b31071..edd2aedc 100755 --- a/bin/test_generator.sh +++ b/bin/test_generator.sh @@ -1,23 +1,42 @@ #!/usr/bin/env bash -set -eo pipefail +set -euo pipefail -temp=$(mktemp -d) +declare TEMP_DIR +TEMP_DIR=$(mktemp -d) + +readonly TEMP_DIR +readonly GENERATOR_DIR="./generator" +readonly PRACTICE_DIR="./exercises/practice" +readonly TEMPLATE_PATH=".meta/template.swift" swift build --package-path ./generator -for exercise in ./exercises/practice/*; do - if [[ -r "${exercise}/.meta/template.swift" ]]; then - cp -r "$exercise" "$temp" - test_file="${exercise}/$(jq -r '.files.test[0]' ${exercise}/.meta/config.json)" - temp_test_file="${temp}/$(basename "$exercise")/$(jq -r '.files.test[0]' ${exercise}/.meta/config.json)" - swift run --package-path ./generator Generator $(basename "$exercise") "$temp/$(basename "$exercise")" - echo "Comparing $test_file with $temp_test_file" - diff "$temp_test_file" "$test_file" - if [ $? -ne 0 ]; then - exit_code=1 - fi +exit_code=0 +for exercise_path in "${PRACTICE_DIR}"/*; do + [[ -e "${exercise_path}/${TEMPLATE_PATH}" ]] || continue + + cp -r "${exercise_path}"/. "${TEMP_DIR}" + + # Minify json and extract test file name + test_file=$(tr -d '\n\r ' < "${exercise_path}"/.meta/config.json | grep -o '"test":\["[^"]*' | sed 's/.*\["//') + original_test="${exercise_path}/${test_file}" + temp_test="${TEMP_DIR}/${test_file}" + + exercise_name="${exercise_path##*/}" + + if ! swift run --package-path "${GENERATOR_DIR}" Generator "${exercise_name}" "${TEMP_DIR}"; then + printf 'Generation failed for %s\n' "${exercise_name}" + exit_code=1 + continue + fi + + if ! diff -u -- "${original_test}" "${temp_test}"; then + printf 'Mismatch detected in %s\n' "${exercise_name}" + exit_code=1 + else + printf '%s OK\n' "${exercise_name}" fi done -exit ${exit_code} +exit "${exit_code}" \ No newline at end of file