From 9c46e6ea1243f8ffbc349af8e896388d3bbd1c4d Mon Sep 17 00:00:00 2001 From: Varun Santhanam Date: Sat, 20 Dec 2025 09:08:54 -0800 Subject: [PATCH] Setup CI --- .github/workflows/ci.yml | 118 ++++++++++++++++++++++++++++++++++++++ .scripts/lint-docc | 31 ++++++++++ .scripts/lint-swiftformat | 3 + .scripts/xcode-select | 2 +- 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100755 .scripts/lint-docc create mode 100755 .scripts/lint-swiftformat diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a588888 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,118 @@ +name: ViewScope CI +permissions: + contents: read + pull-requests: write + +on: + push: + branches: + - "main" + - "*release*" + pull_request: + branches: + - "main" + - "*release*" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + swiftformat: + name: Run SwiftFormat + runs-on: macos-26 + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Select Xcode Version + run: ./.scripts/xcode-select + - name: Lint with SwiftFormat + run: ./.scripts/lint-swiftformat + + lint-docc: + name: Validate Documentation + runs-on: macos-26 + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Select Xcode Version + run: ./.scripts/xcode-select + - name: Validate Documentation + run: ./.scripts/lint-docc + + build-macos-spm: + name: Build ViewScope (macOS) + strategy: + fail-fast: false + matrix: + swift: ["6.2"] + include: + - swift: "6.2" + runner: "macos-26" + xcode: "26.1" + runs-on: ${{ matrix.runner }} + outputs: + artifact-name: macos-build + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Select Xcode Version + run: ./.scripts/xcode-select ${{ matrix.xcode }} + - name: Build ViewScope + run: swift build -v --build-tests --build-path .build + - name: Compress Build + run: zip -r build.zip .build + - name: Upload Build + uses: actions/upload-artifact@v6 + with: + name: macos-build-${{ matrix.swift }} + path: build.zip + + test-macos-spm: + name: Test ViewScope (macOS) + strategy: + fail-fast: false + matrix: + swift: ["6.2"] + include: + - swift: "6.2" + runner: "macos-26" + xcode: "26.1" + needs: build-macos-spm + runs-on: ${{ matrix.runner }} + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Xcode Version + run: ./.scripts/xcode-select ${{ matrix.xcode }} + - name: Download Build + uses: actions/download-artifact@v7 + with: + name: macos-build-${{ matrix.swift }} + path: . + - name: Decompress Build + run: unzip build.zip + - name: Test ViewScope + run: swift test --skip-build + + validate-pr: + name: Validate Pull Request + if: ${{ always() && github.event_name == 'pull_request' }} + needs: + - build-macos-spm + - test-macos-spm + - swiftformat + - lint-docc + runs-on: ubuntu-latest + steps: + - name: Check upstream jobs + run: | + if [[ "${{ needs.build-macos-spm.result }}" == "failure" ]] || \ + [[ "${{ needs.test-macos-spm.result }}" == "failure" ]] || \ + [[ "${{ needs.swiftformat.result }}" == "failure" ]] || \ + [[ "${{ needs.lint-docc.result }}" == "failure" ]]; then + echo "❌ Required job failed." + exit 1 + else + echo "✅ All required jobs completed successfully." + fi \ No newline at end of file diff --git a/.scripts/lint-docc b/.scripts/lint-docc new file mode 100755 index 0000000..2c760d4 --- /dev/null +++ b/.scripts/lint-docc @@ -0,0 +1,31 @@ +#!/bin/bash + +set -euo pipefail + +temp_dir=$(mktemp -d) +trap 'rm -rf "$temp_dir"' EXIT + +set +e +output=$(swift package \ + --allow-writing-to-directory "$temp_dir" \ + generate-documentation \ + --product ViewScope \ + --output-path "$temp_dir" \ + --transform-for-static-hosting \ + --hosting-base-path temp-docs 2>&1) +exit_code=$? +set -e + +echo "$output" + +if [ $exit_code -ne 0 ]; then + echo "❌ Documentation generation failed with errors." + exit $exit_code +fi + +if echo "$output" | grep -q '\bwarning:'; then + echo "❌ Documentation generation succeeded, but warnings were emitted." + exit 1 +fi + +echo "✅ Documentation generated without warnings." \ No newline at end of file diff --git a/.scripts/lint-swiftformat b/.scripts/lint-swiftformat new file mode 100755 index 0000000..417e72a --- /dev/null +++ b/.scripts/lint-swiftformat @@ -0,0 +1,3 @@ +#!/bin/bash + +swift package plugin --allow-writing-to-package-directory swiftformat --lint \ No newline at end of file diff --git a/.scripts/xcode-select b/.scripts/xcode-select index 539ca43..3e65eb9 100755 --- a/.scripts/xcode-select +++ b/.scripts/xcode-select @@ -1,5 +1,5 @@ #!/bin/bash -VERSION="${1:-26.2}" +VERSION="${1:-26.1}" sudo xcode-select --switch "/Applications/Xcode_${VERSION}.app" \ No newline at end of file