From 09e2c963cf4aab05fd59bc1a3b32eadec85acb9e Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 28 Apr 2023 11:47:30 +0100 Subject: [PATCH] Fix documentation builds and pull in version picker (#1703) * 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 --- .github/workflows/docker-hub-latest.yml | 3 ++ .github/workflows/docs-latest.yml | 28 ++++++++++++++++ .github/workflows/docs-release.yml | 40 +++++++++++++++++++++++ .github/workflows/docs.yml | 43 ------------------------- book.toml | 5 ++- changelog.d/1703.bugfix | 1 + docs/_site/main.js | 41 +++++++++++++++++++++++ docs/_site/style.css | 27 ++++++++++++++++ docs/_site/version.js | 2 ++ 9 files changed, 146 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/docs-latest.yml create mode 100644 .github/workflows/docs-release.yml delete mode 100644 .github/workflows/docs.yml create mode 100644 changelog.d/1703.bugfix create mode 100644 docs/_site/main.js create mode 100644 docs/_site/style.css create mode 100644 docs/_site/version.js diff --git a/.github/workflows/docker-hub-latest.yml b/.github/workflows/docker-hub-latest.yml index 2cde8070f..ea2693614 100644 --- a/.github/workflows/docker-hub-latest.yml +++ b/.github/workflows/docker-hub-latest.yml @@ -4,6 +4,8 @@ name: "Docker Hub - Latest" on: push: + branches: ["develop", "release-*"] + pull_request: env: DOCKER_NAMESPACE: matrixdotorg @@ -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 }} diff --git a/.github/workflows/docs-latest.yml b/.github/workflows/docs-latest.yml new file mode 100644 index 000000000..9b5b7372a --- /dev/null +++ b/.github/workflows/docs-latest.yml @@ -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 diff --git a/.github/workflows/docs-release.yml b/.github/workflows/docs-release.yml new file mode 100644 index 000000000..6f40301c1 --- /dev/null +++ b/.github/workflows/docs-release.yml @@ -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 }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 7c45e9325..000000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build docs - -on: - push: - branches: - - master - - workflow_dispatch: - -jobs: - docs: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - - name: get-npm-version - id: package-version - uses: martinbeentjes/npm-get-version-action@master - - - name: Setup mdBook - uses: peaceiris/actions-mdbook@v1 - with: - mdbook-version: '0.4.15' - - - run: mdbook build - - - name: Deploy v${{ steps.package-version.outputs.current-version }} - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - keep_files: true - publish_dir: ./book - destination_dir: ./v${{ steps.package-version.outputs.current-version }} - - # TODO: We can't update the config so we have to push twice, it's clearly not - # the best solution but it is A solution. - - name: Deploy latest - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - keep_files: true - publish_dir: ./book - destination_dir: ./latest \ No newline at end of file diff --git a/book.toml b/book.toml index 271b758cd..ecf6fc0d3 100644 --- a/book.toml +++ b/book.toml @@ -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" +] diff --git a/changelog.d/1703.bugfix b/changelog.d/1703.bugfix new file mode 100644 index 000000000..5cf923e93 --- /dev/null +++ b/changelog.d/1703.bugfix @@ -0,0 +1 @@ +Fix documentation not being built and uploaded to GitHub pages on release. \ No newline at end of file diff --git a/docs/_site/main.js b/docs/_site/main.js new file mode 100644 index 000000000..09ce6641b --- /dev/null +++ b/docs/_site/main.js @@ -0,0 +1,41 @@ +window.addEventListener("load", () => { + const scrollbox = document.querySelector(".sidebar-scrollbox"); + scrollbox.innerHTML = `
Version:
${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); +}); \ No newline at end of file diff --git a/docs/_site/style.css b/docs/_site/style.css new file mode 100644 index 000000000..bc9dbe3d0 --- /dev/null +++ b/docs/_site/style.css @@ -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; +} diff --git a/docs/_site/version.js b/docs/_site/version.js new file mode 100644 index 000000000..d7a6c4233 --- /dev/null +++ b/docs/_site/version.js @@ -0,0 +1,2 @@ +// This is modified by the build script +window.BRIDGE_VERSION = "latest"; \ No newline at end of file