-
-
Notifications
You must be signed in to change notification settings - Fork 94
143 lines (126 loc) · 5.92 KB
/
pages.yml
File metadata and controls
143 lines (126 loc) · 5.92 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
name: Deploy GitHub Pages
on:
push:
branches: ["main"] # Run this workflow on every push to the main branch
workflow_dispatch: # Allow manual triggering of the workflow from the GitHub UI
permissions:
contents: read # Required to read the repository contents
pages: write # Required to write/deploy to GitHub Pages
id-token: write # Required for OIDC authentication used by deploy-pages@v4
concurrency:
group: "pages" # Ensure only one Pages deployment runs at a time
cancel-in-progress: true # Cancel any in-progress runs if a new one starts
jobs:
build:
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- name: Checkout
uses: actions/checkout@v6
# This checks out the repository so subsequent steps can read README.md,
# docs/TriceUserManual.md, etc.
- name: Generate index.md from README.md for GitHub Pages
shell: bash
run: |
set -euo pipefail
# Create index.md with Jekyll front matter.
# This file is NOT committed; it only exists in the build workspace
# and becomes the site homepage on GitHub Pages.
{
echo '---'
echo 'layout: default'
echo '---'
echo
# Copy README.md, but rewrite all links that point to
# ./docs/TriceUserManual.md (with or without anchors) so they
# target the rendered HTML page instead.
#
# Examples in README.md:
# [Manual](./docs/TriceUserManual.md)
# [Speed](./docs/TriceUserManual.md#trice-speed)
#
# All become (in index.md for Pages):
# ...](./docs/TriceUserManual.html#trice-speed)
sed -E 's,./docs/TriceUserManual\.md,./docs/TriceUserManual.html,g' README.md
} > index.md
- name: Prepare TriceUserManual.md for GitHub Pages
shell: bash
run: |
set -euo pipefail
# We want docs/TriceUserManual.md to remain GitHub-friendly in the repo
# with relative links like:
# [freedom](../internal/emitter/lineTransformerANSI.go)
# [Something](./StructuredLoggingWithTrice.md)
#
# On the published site we prefer those links to open the GitHub file view,
# so the user sees the source file with syntax highlighting, blame, etc.
#
# Strategy:
# 1. Copy the original manual to a temporary file.
# 2. Rewrite all "normal" Markdown links (NOT images) of the form
# [text](../path...)
# to:
# [text](https://github.com/rokath/trice/blob/main/path...)
#
# and all links of the form
# [text](./path...)
# to:
# [text](https://github.com/rokath/trice/blob/main/docs/path...)
#
# Notes:
# - We explicitly avoid matching image syntax `` by requiring
# that the character before '[' is either start-of-line or not '!'.
# - We rewrite everything inside the parentheses up to the closing ')',
# including any #anchor, so anchors are preserved in the final URL.
cp docs/TriceUserManual.md /tmp/TriceUserManual.md
sed -E '
# Rewrite links of the form [text](../path...)
# Capture:
# (^|[^!]) -> group 1: start of line OR a character that is NOT "!"
# (\[[^]]*\]) -> group 2: the [link text]
# \(\.\./([^)]+)\) -> group 3: everything after "../" up to ")"
#
# Replacement:
# \1\2(https://github.com/rokath/trice/blob/main/\3)
#
# Examples:
# [freedom](../internal/emitter/lineTransformerANSI.go)
# -> [freedom](https://github.com/rokath/trice/blob/main/internal/emitter/lineTransformerANSI.go)
s#(^|[^!])(\[[^]]*\])\(\.\./([^)]+)\)#\1\2(https://github.com/rokath/trice/blob/main/\3)#g
# Rewrite links of the form [text](./path...)
# Here docs/TriceUserManual.md lives in docs/, so "./path"
# corresponds to "docs/path" in the repository.
#
# Examples:
# [Spec](./StructuredLoggingWithTrice.md)
# -> [Spec](https://github.com/rokath/trice/blob/main/docs/StructuredLoggingWithTrice.md)
s#(^|[^!])(\[[^]]*\])\(./([^)]+)\)#\1\2(https://github.com/rokath/trice/blob/main/docs/\3)#g
' /tmp/TriceUserManual.md > docs/TriceUserManual.md
- name: Setup Pages
uses: actions/configure-pages@v6
# Prepares the environment (paths, tokens, etc.) for the Pages build.
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./ # Build from the repository root
destination: ./_site # Generated static site output
# Jekyll will:
# - Use _config.yml in the repository root.
# - Use index.md (generated above) as the homepage.
# - Render docs/TriceUserManual.md (modified above) as a page.
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./_site # Upload the generated site as an artifact
# This artifact is what the deploy job will publish to GitHub Pages.
deploy:
runs-on: ubuntu-latest
needs: build # Only run deploy after build completes successfully
environment:
name: github-pages # Special environment used by GitHub Pages
url: ${{ steps.deployment.outputs.page_url }} # Expose the deployed URL
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
# This takes the uploaded artifact from the build job and
# deploys it to GitHub Pages.