Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Pages

# Publishes site/, the project's landing page, to GitHub Pages when it changes on main.
on:
push:
branches: [main]
paths: [site/**, .github/workflows/pages.yml]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: pages
cancel-in-progress: false

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Upload site
uses: actions/upload-pages-artifact@v3
with:
path: site
- name: Deploy
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Read `CONSTRAINTS.md` before writing code. Do not weaken it to make a change pas
`README.md` is the user documentation and DocC comments are the API reference (Swift Package Index builds docs for `JSONPath`, see `.spi.yml`). In the same change as any API or behaviour change:
- Update the doc comment on every public declaration you touch.
- Update every README section, example and table the change affects (`grep -n "<Symbol>" README.md`), including the Dialect feature table.
- `site/index.html` is the landing page (GitHub Pages, `.github/workflows/pages.yml`). Its code tour and install snippet quote the README (`data-readme` blocks, checked by `ReadmeTests.sitePageQuotesTheReadme`); its feature claims, dialect table and numbers repeat the README: update them in the same change.
- Keep README snippets compiling: `Tests/JSONPathTests/ReadmeTests.swift` mirrors them, so a changed snippet changes its test.

## Build and test
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmackoj%2Fswift-jsonpath%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/mackoj/swift-jsonpath)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmackoj%2Fswift-jsonpath%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/mackoj/swift-jsonpath)

**[Website](https://mackoj.github.io/swift-jsonpath/)** ·
**[API reference](https://swiftpackageindex.com/mackoj/swift-jsonpath/documentation/jsonpath)**

A complete JSONPath implementation in pure Swift — no Foundation, no dependencies — supporting both
the IETF standard and the widely deployed Jayway dialect, with JSON Pointer (RFC 6901) alongside it.

Expand Down Expand Up @@ -31,7 +34,7 @@ the IETF standard and the widely deployed Jayway dialect, with JSON Pointer (RFC

```swift
dependencies: [
.package(url: "https://github.com/mackoj/swift-jsonpath.git", from: "0.0.1"),
.package(url: "https://github.com/mackoj/swift-jsonpath.git", from: "0.0.4"),
],
targets: [
.target(name: "MyTool", dependencies: [.product(name: "JSONPath", package: "swift-jsonpath")]),
Expand Down
26 changes: 26 additions & 0 deletions Tests/JSONPathTests/ReadmeTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import JSONPath
import Testing

Expand All @@ -13,6 +14,31 @@ struct ReadmeTests {
], "bicycle": {"color": "red", "price": 19.95}}}
""")

/// The landing page repeats README snippets in its code tour and install section (`data-readme` blocks); every
/// line of them must be a README line, so this suite's checks of the README cover the page too.
@Test func sitePageQuotesTheReadme() throws {
// Given the README and the landing page
let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent()
.deletingLastPathComponent()
let readme = try String(contentsOf: root.appendingPathComponent("README.md"), encoding: .utf8)
let page = try String(contentsOf: root.appendingPathComponent("site/index.html"), encoding: .utf8)

// When the page's README blocks are read back as text
let blocks = page.components(separatedBy: " data-readme>").dropFirst().map { block in
String(block.prefix { $0 != "<" })
.replacingOccurrences(of: "&lt;", with: "<").replacingOccurrences(of: "&gt;", with: ">")
.replacingOccurrences(of: "&quot;", with: "\"").replacingOccurrences(of: "&amp;", with: "&")
}
let readmeLines = Set(readme.split(separator: "\n", omittingEmptySubsequences: false).map(String.init))
let strayLines = blocks.flatMap { $0.split(separator: "\n").map(String.init) }.filter {
!readmeLines.contains($0)
}

// Then there are blocks, and each of their lines is in the README
#expect(blocks.count == 9)
#expect(strayLines == [])
}

@Test func usage() throws {
let document = Self.document
let cheap = try JSONPath("$.store.book[?@.price < 10].title")
Expand Down
Loading
Loading