-
-
Notifications
You must be signed in to change notification settings - Fork 2
168 lines (148 loc) · 5.68 KB
/
ci.yml
File metadata and controls
168 lines (148 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: CI
on:
push:
branches: [main]
tags: ["*"]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# ── Lint, Build & Test on macOS and Linux ──────────────────────
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
include:
- name: "macOS"
runner: macos-15
container: ""
install-swiftlint: brew install swiftlint
- name: "Linux"
runner: ubuntu-latest
container: swift:6.0
install-swiftlint: |
apt-get update && apt-get install -y curl unzip
SWIFTLINT_VERSION="0.58.2"
curl -fsSL "https://github.com/realm/SwiftLint/releases/download/${SWIFTLINT_VERSION}/swiftlint_linux.zip" -o swiftlint.zip
unzip -o swiftlint.zip -d /usr/local/bin
chmod +x /usr/local/bin/swiftlint
rm swiftlint.zip
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install SwiftLint
run: ${{ matrix.install-swiftlint }}
- name: Lint
run: swiftlint
- name: Build
env:
DISABLE_SWIFTLINT: "1"
run: swift build
- name: Test
env:
DISABLE_SWIFTLINT: "1"
run: swift test
# ── Update test count badge in README (main only) ─────────────
update-badge:
name: Update test badge
needs: build
runs-on: macos-15
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
- name: Count tests and suites
id: counts
run: |
TESTS=$(grep -r '@Test\b' Tests/ --include='*.swift' | wc -l | tr -d ' ')
SUITES=$(grep -r '@Suite\b' Tests/ --include='*.swift' | wc -l | tr -d ' ')
echo "tests=$TESTS" >> "$GITHUB_OUTPUT"
echo "suites=$SUITES" >> "$GITHUB_OUTPUT"
echo "Found $TESTS tests in $SUITES suites"
- name: Update README badge and counts
env:
TESTS: ${{ steps.counts.outputs.tests }}
SUITES: ${{ steps.counts.outputs.suites }}
run: |
# Badge: Tests-NNN_passing
sed -i '' "s/Tests-[0-9]*_passing/Tests-${TESTS}_passing/" README.md
# Project structure: NNN tests across NN test suites
sed -i '' "s/[0-9]* tests across [0-9]* test suites/${TESTS} tests across ${SUITES} test suites/" README.md
# Developer notes: All NNN tests run in parallel
sed -i '' "s/All [0-9]* tests run/All ${TESTS} tests run/" README.md
- name: Commit if changed
run: |
git diff --quiet README.md && echo "No changes" && exit 0
git config user.name "Frank Gregor"
git config user.email "phranck@mac.com"
git add README.md
# [skip ci] prevents the push from triggering another workflow run
git commit -m "Chore: Update test count badge to ${{ steps.counts.outputs.tests }} tests [skip ci]"
git push
# ── DocC Documentation (→ docs.tuikit.dev) ───────────────────
deploy-docs:
name: Build & Deploy DocC
needs: build
runs-on: macos-15
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build DocC documentation
env:
DISABLE_SWIFTLINT: "1"
run: |
swift package --allow-writing-to-directory docc-output \
generate-documentation \
--target TUIkit \
--output-path docc-output \
--transform-for-static-hosting
- name: Add routing support for GitHub Pages
run: |
cp Sources/TUIkit/TUIkit.docc/theme-overrides.css docc-output/theme-overrides.css
python3 - <<'PY'
from pathlib import Path
link = '<link rel="stylesheet" href="/theme-overrides.css">'
for path in Path("docc-output").rglob("*.html"):
content = path.read_text(encoding="utf-8")
if link in content or "</head>" not in content:
continue
path.write_text(content.replace("</head>", f" {link}\n</head>"), encoding="utf-8")
PY
# 404.html = copy of SPA index so all deep-link paths route through DocC
cp docc-output/index.html docc-output/404.html
# Root redirect: docs.tuikit.dev/ -> docs.tuikit.dev/documentation/tuikit/
cat > docc-output/index.html << 'REDIRECT'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=/documentation/tuikit/">
<link rel="canonical" href="/documentation/tuikit/">
<title>Redirecting to TUIkit Documentation</title>
</head>
<body>
<p>Redirecting to <a href="/documentation/tuikit/">TUIkit Documentation</a>...</p>
</body>
</html>
REDIRECT
- name: Deploy to tuikit-docs
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
external_repository: phranck/tuikit-docs
publish_branch: gh-pages
publish_dir: docc-output
cname: docs.tuikit.dev