Skip to content

Commit b1bd598

Browse files
authored
Merge pull request #1 from Wei18/feat/docc
Update CI.yml, Makefile, Package.swift to support docc
2 parents 73f9e82 + 88ad269 commit b1bd598

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

.github/workflows/CI.yml

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: CI
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
47

58
jobs:
69

7-
test:
10+
Test:
811
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
912
strategy:
1013
matrix:
@@ -21,4 +24,38 @@ jobs:
2124
os: ${{ matrix.os }}
2225

2326
- run: swift build
24-
- run: swift test
27+
- run: swift test
28+
29+
# Package.swift uses GITHUB_JOB to add docc dependency
30+
BuildDocC:
31+
strategy:
32+
matrix:
33+
os:
34+
- ubuntu-latest
35+
# - macos-latest
36+
swift: ["5.9"]
37+
runs-on: ${{ matrix.os }}
38+
env:
39+
GITHUB_PAGES: "true"
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: ./.github/workflows/actions/setup
43+
- run: make .build/docs
44+
- uses: actions/upload-pages-artifact@v2
45+
with:
46+
path: .build/docs
47+
48+
DeployDocC:
49+
needs: BuildDocC
50+
permissions:
51+
pages: write
52+
id-token: write
53+
environment:
54+
name: github-pages
55+
url: ${{ steps.deployment.outputs.page_url }}
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Deploy to GitHub Pages
59+
id: deployment
60+
uses: actions/deploy-pages@v4
61+

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,19 @@ Sources/%/openapi.yml: Submodule
2020
git commit -m "Relink $@" || true
2121

2222
.PHONY: install
23-
install: $(OPENAPI_FILES)
23+
install: $(OPENAPI_FILES)
24+
25+
.build/docs: ## Need env GITHUB_PAGES is created as 'true'
26+
swift package --allow-writing-to-directory $@ generate-documentation \
27+
--target GitHubRestAPISwiftOpenAPI \
28+
--disable-indexing \
29+
--output-path $@ \
30+
--transform-for-static-hosting \
31+
--hosting-base-path github-rest-api-swift-openapi;
32+
33+
.PHONY: help
34+
.SILENT: help
35+
help:
36+
echo -----------------------------------------------------------------------
37+
awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-14s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
38+
echo -----------------------------------------------------------------------

Package.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
5+
import Foundation
56

67
/// The generator supports filtering the OpenAPI document prior to generation,
78
/// which can be useful when generating client code for a subset of a large API,
@@ -74,6 +75,11 @@ enum GitHubRestAPIOpenAPITag: String, CaseIterable {
7475
}
7576
}
7677

78+
let gitHubRestAPISwiftOpenAPITarget: PackageDescription.Target = .target(
79+
name: "GitHubRestAPISwiftOpenAPI",
80+
dependencies: GitHubRestAPIOpenAPITag.allCases.map { .target(name: $0.rawValue) }
81+
)
82+
7783
let package = Package(
7884
name: "GitHubRestAPISwiftOpenAPI",
7985
platforms: [.macOS(.v10_15)],
@@ -84,6 +90,16 @@ let package = Package(
8490
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
8591
],
8692
targets: GitHubRestAPIOpenAPITag.allCases.map(\.target) + [
87-
GitHubRestAPIOpenAPITag.users.testTarget
93+
gitHubRestAPISwiftOpenAPITarget,
94+
GitHubRestAPIOpenAPITag.users.testTarget,
8895
]
8996
)
97+
98+
let isBuildDocC = ProcessInfo.processInfo.environment["GITHUB_PAGES"] == "true"
99+
100+
// swift-docs is not needed for package users
101+
if isBuildDocC {
102+
package.dependencies += [
103+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
104+
]
105+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by zwc on 2023/12/31.
6+
//

0 commit comments

Comments
 (0)