jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
534 stars 47 forks source link

Mike deploy in Github Action: permission denied on sitemap.xml #65

Closed Sispheor closed 3 years ago

Sispheor commented 3 years ago

Hi,

I'm trying to deploy my doc from GH Action CI/CD. I get this error.

In my workflow I used the MkDocs action before to build and publish it.

My workflow

name:  Publish docs on GitHub Pages

on:
  push:
    branches:
      - mkdocs_version

jobs:
  build:
    name: Deploy docs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout main
        uses: actions/checkout@v2

      - name: Deploy docs
        uses: mhausenblas/mkdocs-deploy-gh-pages@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Get current app version
        id: vars
        run: |
          echo ::set-output name=version::$(grep "__version__ =" Squest/settings/__init__.py |awk '{printf $3}' | sed -e 's/^"//' -e 's/"$//')

      - name: Print app version
        run: |
          echo ${{ steps.vars.outputs.version }}

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install mkdocs mkdocs-material mike

      - name: Publish last version
        run: |
          mike deploy --push --update-aliases ${{ steps.vars.outputs.version }} latest

Error log

Run mike deploy --push --update-aliases 0.2 latest
INFO     -  Cleaning site directory
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.11/x64/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/mkdocs/__main__.py", line 183, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/mkdocs/commands/build.py", line 256, in build
    utils.clean_directory(config['site_dir'])
  File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/mkdocs/utils/__init__.py", line 167, in clean_directory
    os.unlink(path)
PermissionError: [Errno 13] Permission denied: '/home/runner/work/squest/squest/site/sitemap.xml'
error: Command '['mkdocs', 'build', '--clean', '--config-file', '/home/runner/work/squest/squest/mike-mkdocs6zmdfee8.yml']' returned non-zero exit status 1.
Sispheor commented 3 years ago

It's ok. I needed to use directly mike without calling mkdocs.

FYI, here is the GH action workflow I use. Maybe you can add it to your doc if you think that can be usedfull.

Thanks for this plugin.

name:  Publish docs on GitHub Pages

on:
  push:
    branches:
      - mkdocs_version

jobs:
  build:
    name: Deploy docs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout main
        uses: actions/checkout@v2

      - name: Get current app version
        id: vars
        run: |
          echo ::set-output name=version::$(grep "__version__ =" Squest/settings/__init__.py |awk '{printf $3}' | sed -e 's/^"//' -e 's/"$//')

      - name: Print app version
        run: |
          echo ${{ steps.vars.outputs.version }}

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install mkdocs mkdocs-material mike

      - name: Get current branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch

      - name: Publish last version
        run: |
          set -e
          if ! git config --get user.name; then
              git config --global user.name "${GITHUB_ACTOR}"
          fi
          if ! git config --get user.email; then
              git config --global user.email "${GITHUB_ACTOR}@users.noreply.${GITHUB_DOMAIN:-"github.com"}"
          fi
          remote_repo="https://x-access-token:${GITHUB_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_REPOSITORY}.git"
          git remote rm origin
          git remote add origin "${remote_repo}"
          git checkout --orphan gh-pages
          git pull origin gh-pages
          git checkout ${{ steps.extract_branch.outputs.branch }}
          mike deploy --push --update-aliases ${{ steps.vars.outputs.version }} latest