From d3d913b0341478b15b25bf1c26029984cc8537e6 Mon Sep 17 00:00:00 2001 From: Moritz Johner <100202497+moritzjohner-form3@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:30:34 +0100 Subject: [PATCH] fix: add action to deploy docs on change (#4) * fix: add action to deploy docs on change Signed-off-by: Moritz Johner --- .github/actions/mkdocs/action.sh | 21 +++++++++---- .github/workflows/docs.yaml | 52 ++++++++++++++++++++++++++++++++ docs/Makefile | 16 ---------- docs/extra.css | 9 ------ docs/mkdocs.yml | 4 +-- 5 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/docs.yaml delete mode 100644 docs/extra.css diff --git a/.github/actions/mkdocs/action.sh b/.github/actions/mkdocs/action.sh index 48401db..e81d575 100644 --- a/.github/actions/mkdocs/action.sh +++ b/.github/actions/mkdocs/action.sh @@ -31,20 +31,29 @@ fi git config --global user.name "$GITHUB_ACTOR" git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" -mkdocs build --config-file "${GITHUB_WORKSPACE}/docs/mkdocs.yml" +docs_site_tmp_dir=$(mktemp -d) +cd docs && mkdocs build --config-file "${GITHUB_WORKSPACE}/docs/mkdocs.yml" -d "${docs_site_tmp_dir}" -git clone --branch=gh-pages --depth=1 "${remote_repo}" gh-pages -cd gh-pages +gh_pages_tmp_dir=$(mktemp -d) + +cd $gh_pages_tmp_dir +git clone --branch=gh-pages --depth=1 "${remote_repo}" . # copy current index file index.yaml before any change temp_worktree=$(mktemp -d) -cp --force "index.yaml" "$temp_worktree/index.yaml" +if [ -f "index.yaml" ]; then + cp --force "index.yaml" "$temp_worktree/index.yaml" +fi # remove current content in branch gh-pages git rm -r . # copy new doc. -cp -r ../site/* . +cp -r "${docs_site_tmp_dir}"/* . + # restore chart index -cp "$temp_worktree/index.yaml" . +if [ -f "index.yaml" ]; then + cp "$temp_worktree/index.yaml" . +fi + # commit changes git add . git commit -m "Deploy GitHub Pages" diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml new file mode 100644 index 0000000..511abc7 --- /dev/null +++ b/.github/workflows/docs.yaml @@ -0,0 +1,52 @@ +name: Documentation + +on: + push: + branches: + - main + - mj-deploy-docs + +permissions: + contents: read + +jobs: + + changes: + permissions: + contents: read # for dorny/paths-filter to fetch a list of changed files + pull-requests: read # for dorny/paths-filter to read pull requests + runs-on: ubuntu-latest + outputs: + docs: ${{ steps.filter.outputs.docs }} + charts: ${{ steps.filter.outputs.charts }} + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: filter + with: + token: ${{ secrets.GITHUB_TOKEN }} + filters: | + docs: + - 'docs/**/*' + + docs: + name: Update + runs-on: ubuntu-latest + needs: + - changes + if: needs.changes.outputs.docs == 'true' + + permissions: + contents: write # needed to write releases + + steps: + - name: Checkout master + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Deploy + uses: ./.github/actions/mkdocs + env: + PERSONAL_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/docs/Makefile b/docs/Makefile index 1a954d8..78676c8 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,11 +1,3 @@ -.PHONY: check_dead_links -check_dead_links: ## Check if the documentation contains dead links. - @docker run -t \ - -w /tmp \ - -v $$PWD:/tmp dkhamsing/awesome_bot:1.20.0 \ - --allow-dupe \ - --allow-redirect $(shell find $$PWD -mindepth 1 -name vendor -prune -o -name .modcache -prune -o -iname Changelog.md -prune -o -name "*.md" | sed -e "s#$$PWD/##") - .PHONY: build-image build-image: @docker build \ @@ -29,11 +21,3 @@ live-docs: build-image ## Build and launch a local copy of the documentation web --entrypoint /bin/bash \ xpdb-docs \ -c "pip install -r /docs/requirements.txt && mkdocs serve --dev-addr=0.0.0.0:8000" - -.PHONY: misspell -misspell: ## Check for spelling errors. - @go install github.com/client9/misspell/cmd/misspell@latest - misspell \ - -locale US \ - -error \ - . diff --git a/docs/extra.css b/docs/extra.css deleted file mode 100644 index 469503c..0000000 --- a/docs/extra.css +++ /dev/null @@ -1,9 +0,0 @@ -.md-typeset__table { - min-width: 100%; -} - -@media only screen and (min-width: 768px) { - td:nth-child(1) { - white-space: nowrap; - } -} diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 7d0a84b..c7c9c8e 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -3,7 +3,7 @@ repo_name: "form3tech-oss/x-pdb" repo_url: https://github.com/form3tech-oss/x-pdb site_url: https://form3tech-oss.github.io/x-pdb edit_uri: edit/main/docs/src -docs_dir: "/docs/src" +docs_dir: "src" # Extensions markdown_extensions: @@ -63,8 +63,6 @@ plugins: - minify: minify_html: true -extra_css: [extra.css] - nav: - Introduction: - Overview: "index.md"