Is a personal access token needed?

I have the following Action set up in order to push files to the GitHub Pages branch using MkDocs.

The question I now have is, if the GH_TOKEN, which is a Personal Access Token, is required for this to work, or if I can replace it with something else (or remove it altogether).

The YAML file I have setup

name: Deploy Site

on:
  push:
    paths:
    - 'docs/**'
    - '**.yml'
    - 'theme/**'
    branches:
    - master

jobs:
  build:
    runs-on: [ubuntu-latest]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.7
      uses: actions/setup-python@v1
      with:
        python-version: 3.7
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools
        python -m pip install -r requirements.txt # File only has mkdocs-material >= 5.0.0
    - name: Deploy Files
      run: |
        git config user.name "github-actions[bot]" # I use the GitHub Actions bot here.
        git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
        git remote add gh-token "https://${{ secrets.GH_TOKEN}}@github.com/Andre601/MyRepo.git" # Example
        git fetch gh-token && git fetch gh-token gh-pages:gh-pages
        python -m mkdocs gh-deploy --clean --remote-name gh-token
        git push gh-token gh-pages

Hi @andre601 ,

If you’re pushing commit to ‘gh-pages’ branch in same repository, you can skip token:

git remote add gh-token "https://github.com/Andre601/MyRepo.git"

This is due to ‘actions/checkout’ will automatically add GITHUB_TOKEN to later git operations, and the token has write permission to current repo.

If you push commit to another repository, personal access token is needed. Code sample as below:

git remote add gh-token "https://weide-zhou:${{ secrets.PAT1 }}@github.com/weide-zhou/ticket14.git"

Thanks.

1 Like

Thanks.

It works without any issues.