From 5ec3c81efa1edf8c9dc594e1ee7cc4814d69c816 Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Tue, 5 Mar 2024 18:10:43 +0100 Subject: [PATCH] Add a workflow for publishing DocC on every commit --- .../workflows/{swift.yml => build-runner.yml} | 8 +-- .github/workflows/docc-publish.yml | 61 +++++++++++++++++++ .../RichTextContextTests.swift | 4 +- .../RichTextViewIntegrationTests+UIKit.swift | 6 +- .../RichTextViewRepresentableTests.swift | 2 +- 5 files changed, 73 insertions(+), 8 deletions(-) rename .github/workflows/{swift.yml => build-runner.yml} (87%) create mode 100644 .github/workflows/docc-publish.yml diff --git a/.github/workflows/swift.yml b/.github/workflows/build-runner.yml similarity index 87% rename from .github/workflows/swift.yml rename to .github/workflows/build-runner.yml index 5f5e4ce38..dfbc0fb51 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/build-runner.yml @@ -1,13 +1,13 @@ -# This workflow will build a Swift project +# This workflow builds and tests the project. # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift -name: Swift +name: Build Runner on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: build: diff --git a/.github/workflows/docc-publish.yml b/.github/workflows/docc-publish.yml new file mode 100644 index 000000000..9e41968a7 --- /dev/null +++ b/.github/workflows/docc-publish.yml @@ -0,0 +1,61 @@ +# This workflow builds publish DocC docs to GitHub Pages. +# Source: https://sachithrasiriwardhane.medium.com/how-to-automate-docc-documentation-hosting-with-github-pages-b6d120880dd3 + +name: DocC Publish + +on: + push: + branches: ["main"] + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + # One deployment deploy job since we're just deploying + deploy: + environment: + # Must set to this for deploying to GitHub Pages + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: macos-13 + steps: + - name: Checkout + uses: actions/checkout@v3 + - id: pages + name: Setup Pages + uses: actions/configure-pages@v3 + - name: Select Xcode 15.1 + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '15.1.0' + - name: Build DocC + run: | + swift package resolve; + + xcodebuild docbuild -scheme RichTextKit -derivedDataPath /tmp/docbuild -destination 'platform=iOS Simulator,name=iPhone 15'; + + echo "Archiving documentation..." + + $(xcrun --find docc) process-archive \ + transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphonesimulator/RichTextKit.doccarchive \ + --output-path docs \ + --hosting-base-path ''; + + echo "** Archived documentation**" + + echo "" > docs/index.html; + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: 'docs' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/Tests/RichTextKitTests/RichTextContextTests.swift b/Tests/RichTextKitTests/RichTextContextTests.swift index fe287e15d..03f100831 100644 --- a/Tests/RichTextKitTests/RichTextContextTests.swift +++ b/Tests/RichTextKitTests/RichTextContextTests.swift @@ -13,7 +13,9 @@ final class RichTextContextTests: XCTestCase { func testInitializerSetsDefaultValues() { let context = RichTextContext() - XCTAssertEqual(context.fontName, "") + let iosFontName = context.fontName == ".SFUI" + let macFontName = context.fontName == ".AppleSystemUIFont" + XCTAssertTrue(iosFontName || macFontName) XCTAssertEqual(context.fontSize, 16) XCTAssertFalse(context.hasStyle(.bold)) XCTAssertFalse(context.hasStyle(.italic)) diff --git a/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift b/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift index a7ca16231..ce5829580 100644 --- a/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift +++ b/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift @@ -58,7 +58,8 @@ final class RichTextViewIntegrationTests: XCTestCase { // When starting RichTextEditor we want to check if the font and color is set correctly. textContext.selectRange(.init(location: 0, length: 0)) - XCTAssertEqual(attributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) + let font = attributes[.font] as? FontRepresentable + XCTAssertEqual(font?.pointSize, 16) XCTAssertEqual(attributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.label) // First we fill in the empty textView with some text, select it and set bold and italic to it. @@ -76,7 +77,8 @@ final class RichTextViewIntegrationTests: XCTestCase { textContext.selectRange(.init(location: 0, length: stringWithoutAttributes.count)) - XCTAssertEqual(attributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) + let font = attributes[.font] as? FontRepresentable + XCTAssertEqual(font?.pointSize, 16) XCTAssertEqual(attributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.label) textView.setRichTextStyle(.bold, to: true) diff --git a/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift index 390c2c9d4..c8fd8d2cc 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift @@ -71,7 +71,7 @@ final class RichTextViewComponentTests: XCTestCase { XCTAssertTrue(view.allowsEditingTextAttributes) XCTAssertEqual(view.autocapitalizationType, .sentences) #endif - XCTAssertEqual(view.backgroundColor, .clear) + XCTAssertNotEqual(view.backgroundColor, .clear) XCTAssertEqual(view.contentCompressionResistancePriority(for: .horizontal), .defaultLow) #if iOS XCTAssertEqual(view.spellCheckingType, .no)