Use SwiftSyntax prebuilt action in CI #2709
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run unit tests | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| concurrency: | |
| group: ${{ github.workflow }} / ${{ startsWith(github.event_name, 'pull') && github.ref_name || github.sha }} | |
| cancel-in-progress: ${{ startsWith(github.event_name, 'pull') }} | |
| jobs: | |
| test: | |
| name: Build and Test | |
| strategy: | |
| matrix: | |
| entry: | |
| - os: ubuntu-24.04 | |
| toolchain: | |
| download-url: https://download.swift.org/development/ubuntu2404/swift-DEVELOPMENT-SNAPSHOT-2025-12-01-a/swift-DEVELOPMENT-SNAPSHOT-2025-12-01-a-ubuntu24.04.tar.gz | |
| swift-syntax-version: "603.0.0" | |
| spm-cache-key: ubuntu-24.04-swift-DEVELOPMENT-SNAPSHOT-2025-12-01-a-603.0.0 | |
| wasi-backend: Node | |
| target: "wasm32-unknown-wasip1" | |
| env: | | |
| JAVASCRIPTKIT_DISABLE_TRACING_TRAIT=1 | |
| - os: ubuntu-24.04 | |
| toolchain: | |
| download-url: https://download.swift.org/swift-6.3-branch/ubuntu2404/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-03-05-a/swift-6.3-DEVELOPMENT-SNAPSHOT-2026-03-05-a-ubuntu24.04.tar.gz | |
| swift-syntax-version: "603.0.0" | |
| spm-cache-key: ubuntu-24.04-swift-6.3-DEVELOPMENT-SNAPSHOT-2026-03-05-a-603.0.0 | |
| wasi-backend: Node | |
| target: "wasm32-unknown-wasip1" | |
| - os: ubuntu-22.04 | |
| toolchain: | |
| download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-12-01-a/swift-DEVELOPMENT-SNAPSHOT-2025-12-01-a-ubuntu22.04.tar.gz | |
| swift-syntax-version: "603.0.0" | |
| spm-cache-key: ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2025-12-01-a-603.0.0 | |
| wasi-backend: Node | |
| target: "wasm32-unknown-wasip1-threads" | |
| runs-on: ${{ matrix.entry.os }} | |
| env: | |
| JAVASCRIPTKIT_WASI_BACKEND: ${{ matrix.entry.wasi-backend }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Export matrix env | |
| if: ${{ matrix.entry.env != '' && matrix.entry.env != null }} | |
| run: | | |
| cat <<'EOF' >> "$GITHUB_ENV" | |
| ${{ matrix.entry.env }} | |
| EOF | |
| - uses: ./.github/actions/install-swift | |
| with: | |
| download-url: ${{ matrix.entry.toolchain.download-url }} | |
| - uses: swiftwasm/setup-swiftwasm@v2 | |
| id: setup-swiftwasm | |
| with: | |
| target: ${{ matrix.entry.target }} | |
| - name: Configure environment variables | |
| run: | | |
| echo "SWIFT_SDK_ID=${{ steps.setup-swiftwasm.outputs.swift-sdk-id }}" >> $GITHUB_ENV | |
| echo "SWIFT_BIN_PATH=$(dirname $(which swiftc))" >> $GITHUB_ENV | |
| - name: Restore SwiftPM build cache | |
| id: swiftpm-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| .build | |
| Plugins/PackageToJS/.build | |
| Plugins/BridgeJS/.build | |
| key: swiftpm-${{ matrix.entry.spm-cache-key }}-${{ hashFiles('Package.swift', 'Package.resolved', 'Plugins/PackageToJS/Package.swift', 'Plugins/BridgeJS/Package.swift') }} | |
| restore-keys: | | |
| swiftpm-${{ matrix.entry.spm-cache-key }}- | |
| - uses: swiftwasm/setup-swift-syntax-prebuilts@v1 | |
| id: swiftsyntax-prebuilts | |
| with: | |
| swift-syntax-version: ${{ matrix.entry.swift-syntax-version }} | |
| - run: make bootstrap | |
| - run: make unittest | |
| # Skip unit tests with uwasi because its proc_exit throws | |
| # unhandled promise rejection. | |
| if: ${{ matrix.entry.wasi-backend != 'MicroWASI' }} | |
| env: | |
| SWIFT_PACKAGE_FLAGS: ${{ steps.swiftsyntax-prebuilts.outputs.swift-flags }} | |
| - name: Check if SwiftPM resources are stale | |
| run: | | |
| make regenerate_swiftpm_resources | |
| git diff --exit-code Sources/JavaScriptKit/Runtime | |
| - run: swift test ${{ steps.swiftsyntax-prebuilts.outputs.swift-flags }} --package-path ./Plugins/PackageToJS | |
| - run: swift test ${{ steps.swiftsyntax-prebuilts.outputs.swift-flags }} --package-path ./Plugins/BridgeJS | |
| env: | |
| BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION: ${{ matrix.entry.swift-syntax-version }} | |
| - name: Validate BridgeJS TypeScript declarations | |
| run: npm run check:bridgejs-dts | |
| - name: Save SwiftPM build cache | |
| if: success() && steps.swiftpm-cache.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: | | |
| .build | |
| Plugins/PackageToJS/.build | |
| Plugins/BridgeJS/.build | |
| key: swiftpm-${{ matrix.entry.spm-cache-key }}-${{ hashFiles('Package.swift', 'Package.resolved', 'Plugins/PackageToJS/Package.swift', 'Plugins/BridgeJS/Package.swift') }} | |
| test-bridgejs-against-swift-versions: | |
| name: Test BridgeJS against Swift versions | |
| strategy: | |
| matrix: | |
| entry: | |
| - image: "swift:6.3" | |
| swift-syntax-version: "603.0.0" | |
| spm-cache-key: swift-6.3-603.0.0 | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ${{ matrix.entry.image }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| - name: Install TypeScript | |
| run: npm install | |
| - uses: swiftwasm/setup-swift-syntax-prebuilts@v1 | |
| id: swiftsyntax-prebuilts | |
| with: | |
| swift-syntax-version: ${{ matrix.entry.swift-syntax-version }} | |
| - name: Restore SwiftPM build cache | |
| id: swiftpm-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: Plugins/BridgeJS/.build | |
| key: swiftpm-bridgejs-${{ matrix.entry.spm-cache-key }}-${{ hashFiles('Plugins/BridgeJS/Package.swift') }} | |
| restore-keys: | | |
| swiftpm-bridgejs-${{ matrix.entry.spm-cache-key }}- | |
| - name: Validate BridgeJS TypeScript declarations | |
| run: npm run check:bridgejs-dts | |
| - name: Run BridgeJS tests | |
| run: swift test ${{ steps.swiftsyntax-prebuilts.outputs.swift-flags }} --package-path ./Plugins/BridgeJS | |
| env: | |
| BRIDGEJS_OVERRIDE_SWIFT_SYNTAX_VERSION: ${{ matrix.entry.swift-syntax-version }} | |
| - name: Save SwiftPM build cache | |
| if: success() && steps.swiftpm-cache.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: Plugins/BridgeJS/.build | |
| key: swiftpm-bridgejs-${{ matrix.entry.spm-cache-key }}-${{ hashFiles('Plugins/BridgeJS/Package.swift') }} | |
| native-build: | |
| # Check native build to make it easy to develop applications by Xcode | |
| name: Build for native target | |
| strategy: | |
| matrix: | |
| include: | |
| - os: macos-15 | |
| xcode: Xcode_26.0.1 | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - run: swift build --product BridgeJSTool | |
| env: | |
| DEVELOPER_DIR: /Applications/${{ matrix.xcode }}.app/Contents/Developer/ | |
| - run: swift build --package-path ./Examples/Basic | |
| env: | |
| DEVELOPER_DIR: /Applications/${{ matrix.xcode }}.app/Contents/Developer/ | |
| prettier: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| - run: npm install | |
| - run: npx prettier --check Runtime/src | |
| format: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: swift:6.3 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - run: ./Utilities/format.swift | |
| - name: Check for formatting changes | |
| run: | | |
| git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
| git diff --exit-code || { | |
| echo "::error::The formatting changed some files. Please run \`./Utilities/format.swift\` and commit the changes." | |
| exit 1 | |
| } | |
| check-bridgejs-generated: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./.github/actions/install-swift | |
| with: | |
| download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a/swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a-ubuntu22.04.tar.gz | |
| - uses: swiftwasm/setup-swift-syntax-prebuilts@v1 | |
| id: swiftsyntax-prebuilts | |
| with: | |
| swift-syntax-version: "600.0.1" | |
| - name: Restore SwiftPM build cache | |
| id: swiftpm-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| .build | |
| Plugins/BridgeJS/.build | |
| key: swiftpm-bridgejs-generate-ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a-600.0.1-${{ hashFiles('Package.swift', 'Package.resolved', 'Plugins/BridgeJS/Package.swift') }} | |
| restore-keys: | | |
| swiftpm-bridgejs-generate-ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a-600.0.1- | |
| - run: make bootstrap | |
| - run: ./Utilities/bridge-js-generate.sh | |
| env: | |
| SWIFT_PACKAGE_FLAGS: ${{ steps.swiftsyntax-prebuilts.outputs.swift-flags }} | |
| - name: Check if BridgeJS generated files are up-to-date | |
| run: | | |
| git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
| git diff --exit-code || { | |
| echo "::error::BridgeJS generated files are out of date. Please run \`./Utilities/bridge-js-generate.sh\` and commit the changes." | |
| exit 1 | |
| } | |
| - name: Save SwiftPM build cache | |
| if: success() && steps.swiftpm-cache.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: | | |
| .build | |
| Plugins/BridgeJS/.build | |
| key: swiftpm-bridgejs-generate-ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a-600.0.1-${{ hashFiles('Package.swift', 'Package.resolved', 'Plugins/BridgeJS/Package.swift') }} | |
| build-examples: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./.github/actions/install-swift | |
| with: | |
| download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-03-09-a/swift-DEVELOPMENT-SNAPSHOT-2026-03-09-a-ubuntu22.04.tar.gz | |
| - uses: swiftwasm/setup-swiftwasm@v2 | |
| id: setup-wasm32-unknown-wasip1 | |
| with: { target: wasm32-unknown-wasip1 } | |
| - uses: swiftwasm/setup-swiftwasm@v2 | |
| id: setup-wasm32-unknown-wasip1-threads | |
| with: { target: wasm32-unknown-wasip1-threads } | |
| - uses: swiftwasm/setup-swift-syntax-prebuilts@v1 | |
| id: swiftsyntax-prebuilts | |
| with: | |
| swift-syntax-version: "603.0.0" | |
| - name: Restore SwiftPM build cache | |
| id: swiftpm-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| .build | |
| Examples/ActorOnWebWorker/.build | |
| Examples/Basic/.build | |
| Examples/Embedded/.build | |
| Examples/ExportSwift/.build | |
| Examples/ImportTS/.build | |
| Examples/MultiModule/.build | |
| Examples/Multithreading/.build | |
| Examples/NodeJS/.build | |
| Examples/OffscrenCanvas/.build | |
| Examples/PlayBridgeJS/.build | |
| Examples/Testing/.build | |
| Plugins/BridgeJS/.build | |
| key: swiftpm-examples-ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2026-03-09-a-603.0.0-${{ hashFiles('Package.swift', 'Package.resolved', 'Examples/*/Package.swift', 'Examples/*/Package.resolved', 'Plugins/BridgeJS/Package.swift') }} | |
| restore-keys: | | |
| swiftpm-examples-ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2026-03-09-a-603.0.0- | |
| - run: | | |
| swift --version | |
| ./Utilities/build-examples.sh | |
| env: | |
| SWIFT_SDK_ID_wasm32_unknown_wasip1_threads: ${{ steps.setup-wasm32-unknown-wasip1-threads.outputs.swift-sdk-id }} | |
| SWIFT_SDK_ID_wasm32_unknown_wasip1: ${{ steps.setup-wasm32-unknown-wasip1.outputs.swift-sdk-id }} | |
| SWIFT_PACKAGE_FLAGS: ${{ steps.swiftsyntax-prebuilts.outputs.swift-flags }} | |
| - run: ./Utilities/prepare-gh-pages.sh | |
| - name: Upload static files as artifact | |
| id: deployment | |
| uses: actions/upload-pages-artifact@v5 | |
| with: | |
| path: ./_site | |
| - name: Save SwiftPM build cache | |
| if: success() && steps.swiftpm-cache.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: | | |
| .build | |
| Examples/ActorOnWebWorker/.build | |
| Examples/Basic/.build | |
| Examples/Embedded/.build | |
| Examples/ExportSwift/.build | |
| Examples/ImportTS/.build | |
| Examples/MultiModule/.build | |
| Examples/Multithreading/.build | |
| Examples/NodeJS/.build | |
| Examples/OffscrenCanvas/.build | |
| Examples/PlayBridgeJS/.build | |
| Examples/Testing/.build | |
| Plugins/BridgeJS/.build | |
| key: swiftpm-examples-ubuntu-22.04-swift-DEVELOPMENT-SNAPSHOT-2026-03-09-a-603.0.0-${{ hashFiles('Package.swift', 'Package.resolved', 'Examples/*/Package.swift', 'Examples/*/Package.resolved', 'Plugins/BridgeJS/Package.swift') }} | |
| deploy-examples: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| needs: build-examples | |
| permissions: | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v5 |