-
Notifications
You must be signed in to change notification settings - Fork 247
117 lines (106 loc) · 4.5 KB
/
Copy pathdocs.yml
File metadata and controls
117 lines (106 loc) · 4.5 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
name: Documentation
on:
workflow_dispatch:
release:
types: [published]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: macos-26
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
# The workflow runs under two very different triggers:
#
# * `release: published` runs on the tag ref of the released version.
# The versioned folder is always deployed, and "latest" only for a
# stable release.
# * `workflow_dispatch` runs on a branch (usually `develop`), which is
# not a released version. Only "latest" is refreshed: deploying a
# versioned folder here would overwrite a published release with
# docs built from the tip of the branch.
- name: Determine Version
id: versioning
run: |
git fetch --tags --force
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Use the tag that triggered the workflow, not the latest one
# reachable from the checked-out ref.
VERSION="${GITHUB_REF#refs/tags/}"
echo "deploy_versioned=true" >> "$GITHUB_OUTPUT"
# A SemVer prerelease (e.g. 4.0.0-alpha.1) is identified by the "-"
# separating the prerelease identifiers from the version core.
# It only gets its versioned folder, as "latest" must keep
# advertising the current stable release.
if [[ $VERSION == *-* ]]; then
echo "deploy_latest=false" >> "$GITHUB_OUTPUT"
else
echo "deploy_latest=true" >> "$GITHUB_OUTPUT"
fi
else
VERSION=$(git describe --tags --match "[0-9]*" --abbrev=0)
echo "deploy_versioned=false" >> "$GITHUB_OUTPUT"
echo "deploy_latest=true" >> "$GITHUB_OUTPUT"
fi
echo "READIUM_VERSION=$VERSION" >> "$GITHUB_OUTPUT"
# The docs are generated once per folder because the version is baked
# into the output (DocC --hosting-base-path and the 404/redirect pages
# embed /swift-toolkit/<version>/ URLs), so the "latest" site cannot be
# a plain copy of the versioned one.
#
# Each generate step is skipped when its folder is not deployed, as the
# script wipes .build and runs a full cross-compiled build every time.
- name: Generate Documentation
if: steps.versioning.outputs.deploy_versioned == 'true'
run: ./scripts/generate-docs.sh ${{ steps.versioning.outputs.READIUM_VERSION }}
- name: Generate Latest Documentation
if: steps.versioning.outputs.deploy_latest == 'true'
run: ./scripts/generate-docs.sh latest
# The generate steps create this directory tree, but they are both
# conditional, so make sure it exists before writing into it.
- name: Setup Root Redirect
run: |
mkdir -p docs-site/swift-toolkit
cat <<EOF > docs-site/swift-toolkit/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./latest/documentation/readium">
<script>window.location.replace("./latest/documentation/readium");</script>
</head>
<body><p>Redirecting to <a href="./latest/documentation/readium">latest documentation</a>...</p></body>
</html>
EOF
- name: Deploy Versioned Folder 🚀
if: steps.versioning.outputs.deploy_versioned == 'true'
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs-site/swift-toolkit/${{ steps.versioning.outputs.READIUM_VERSION }}
target-folder: ${{ steps.versioning.outputs.READIUM_VERSION }}
clean: true
- name: Deploy Latest Folder 🚀
if: steps.versioning.outputs.deploy_latest == 'true'
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs-site/swift-toolkit/latest
target-folder: latest
clean: true
- name: Deploy Root Redirect 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs-site/swift-toolkit
target-folder: .
clean: false