Reorganizing the Scripts section (#146) #110
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow | |
name: mdbook-github-pages | |
env: | |
mdbook_version: v0.4.35 | |
mdbook_toc_version: 0.14.1 | |
mdbook_open_on_gh_version: 2.4.1 | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the "main" branch | |
push: | |
branches: [ "main" ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions | |
permissions: | |
id-token: write | |
pages: write | |
jobs: | |
build-and-deploy: | |
# https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment | |
environment: | |
name: github-pages # Use the same environment as used by `Deploy from a branch` | |
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession. | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Install and Build 🔧 | |
run: | | |
function download_and_unpack_api_zip() { | |
cd gh-pages | |
curl -O https://docs.freeplane.org/api.zip | |
unzip api.zip | |
} | |
mkdir -p build/tools | |
cd build/tools | |
curl -O -L https://github.com/rust-lang/mdBook/releases/download/$mdbook_version/mdbook-$mdbook_version-x86_64-unknown-linux-gnu.tar.gz | |
tar xf mdbook-$mdbook_version-x86_64-unknown-linux-gnu.tar.gz | |
curl -O -L https://github.com/badboy/mdbook-toc/releases/download/$mdbook_toc_version/mdbook-toc-$mdbook_toc_version-x86_64-unknown-linux-gnu.tar.gz | |
tar xf mdbook-toc-$mdbook_toc_version-x86_64-unknown-linux-gnu.tar.gz | |
curl -O -L https://github.com/badboy/mdbook-open-on-gh/releases/download/$mdbook_open_on_gh_version/mdbook-open-on-gh-$mdbook_open_on_gh_version-x86_64-unknown-linux-gnu.tar.gz | |
tar xf mdbook-open-on-gh-$mdbook_open_on_gh_version-x86_64-unknown-linux-gnu.tar.gz | |
cd ../.. | |
export PATH="./build/tools/:$PATH" | |
mdbook build src --dest-dir ../build/gh-pages | |
rm -rf build/tools | |
rm -rf 'build/gh-pages/https:' | |
rm -rf 'src/docs/https:' | |
# API docs | |
cd build | |
export FP_GH=https://github.com/freeplane/freeplane | |
# Change TAG_PATTERN when a new major version is released | |
export TAG_PATTERN=release-1.11.* | |
while read -r hash ref; do if [[ $ref != *-pre* ]]; then latest_stable_release_tag=${ref##*/}; fi; done < <(git ls-remote --tags $FP_GH $TAG_PATTERN) | |
_tag=$(curl https://docs.freeplane.org/api/_tag.txt) | |
if [[ $_tag && $_tag = $latest_stable_release_tag ]]; then | |
# It's the same release tag as the API docs saved in GitHub Pages - use this one instead of going to SourceForge | |
download_and_unpack_api_zip | |
else | |
version=${latest_stable_release_tag#release-} | |
# Try to download freeplane-bin-$version.zip from SF and to extract doc/api/ pages | |
[[ $version ]] && | |
curl -L https://sourceforge.net/projects/freeplane/files/freeplane%20stable/freeplane_bin-${version}.zip/download -o freeplane-bin.zip && | |
unzip freeplane-bin.zip "freeplane-${version}/doc/api/*" && | |
mv -v "freeplane-${version}/doc/api" gh-pages/ && | |
echo "$latest_stable_release_tag" > gh-pages/api/_tag.txt && | |
cd gh-pages && | |
zip -r api.zip api/ || # Something went wrong - fall back to the last-successfully-downloaded-from-SF api docs | |
download_and_unpack_api_zip | |
fi | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v1 | |
with: | |
path: 'build/gh-pages' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v1 |