Skip to content

Commit

Permalink
Fix documentation builds and pull in version picker (#1703)
Browse files Browse the repository at this point in the history
* Fix docs builds

* Add JS for version picker

* Update mdbook version

* s/deploy/build

* Don't need node

* changelog

* Ensure we prefix

* Don't prefix

* Only login if we're building
  • Loading branch information
Half-Shot authored Apr 28, 2023
1 parent 64b7bc8 commit 09e2c96
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker-hub-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: "Docker Hub - Latest"

on:
push:
branches: ["develop", "release-*"]
pull_request:

env:
DOCKER_NAMESPACE: matrixdotorg
Expand All @@ -19,6 +21,7 @@ jobs:
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
if: ${{ env.PUSH }}
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/docs-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build docs

on:
pull_request:
push:

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: '0.4.28'

- run: mdbook build

- name: Deploy latest
uses: peaceiris/actions-gh-pages@v3
# Only push if this is main, otherwise we just want to build
if: github.ref == 'refs/heads/develop'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
keep_files: true
publish_dir: ./book
destination_dir: ./latest
40 changes: 40 additions & 0 deletions .github/workflows/docs-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release docs

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16

# We want to install matrix-appservice-bridge, which we depend on.
- run: yarn --ignore-scripts

- name: Get release tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set up mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: '0.4.28'

- name: Set version of docs
run: echo 'window.BRIDGE_VERSION = "${{ env.RELEASE_VERSION }}";' > ./docs/_site/version.js

- run: mdbook build

- name: Deploy latest
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
keep_files: true
publish_dir: ./book
destination_dir: ./${{ env.RELEASE_VERSION }}
43 changes: 0 additions & 43 deletions .github/workflows/docs.yml

This file was deleted.

5 changes: 4 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ git-repository-url = "https://github.com/matrix-org/matrix-appservice-irc"
additional-css = [
"docs/_site/style.css"
]

additional-js = [
"docs/_site/main.js",
"docs/_site/version.js"
]
1 change: 1 addition & 0 deletions changelog.d/1703.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix documentation not being built and uploaded to GitHub pages on release.
41 changes: 41 additions & 0 deletions docs/_site/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
window.addEventListener("load", () => {
const scrollbox = document.querySelector(".sidebar-scrollbox");
scrollbox.innerHTML = `<div class="version-box"><span>Version: </span></div>${scrollbox.innerHTML}`;
const currentVersion = window.BRIDGE_VERSION || 'latest';

const selectElement = document.createElement("select");

fetch("https://api.github.com/repos/matrix-org/matrix-appservice-irc/releases", {
cache: "force-cache",
}).then(res =>
res.json()
).then(releases => {
selectElement.innerHTML = "";
// N.B. We prefix with v
for (const version of ['latest', ...releases.map(r => r.tag_name)]) {
const option = document.createElement("option");
option.innerHTML = version;
selectElement.add(option);
if (currentVersion === version) {
option.setAttribute('selected', '');
}
}
}).catch(ex => {
console.error("Failed to fetch version data", ex);
})

const option = document.createElement("option");
option.innerHTML = 'loading...';
selectElement.add(option);

selectElement.addEventListener('change', (event) => {
const path = [
...window.location.pathname.split('/').slice(0, 2),
event.target.value,
...window.location.pathname.split('/').slice(3),
].join('/');
window.location = `${window.location.origin}${path}`;
});

document.querySelector(".version-box").appendChild(selectElement);
});
27 changes: 27 additions & 0 deletions docs/_site/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.notice {
color: black;
border: 2px solid #0098d4;
border-left-width: 2px;
border-left-width: 5px;
background: #e5f5fb;
padding: 10px 20px;
}

.notice::before {
content: "INFO: ";
font-weight: 700;
}

.warning {
color: black;
border: 2px solid #dda02f;
border-left-width: 2px;
border-left-width: 5px;
background: #fdcd74;
padding: 10px 20px;
}

.warning::before {
content: "WARNING: ";
font-weight: 700;
}
2 changes: 2 additions & 0 deletions docs/_site/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This is modified by the build script
window.BRIDGE_VERSION = "latest";

0 comments on commit 09e2c96

Please sign in to comment.