Fix: Correct GitHub token usage for gh-pages branch cleanup and add d… #8
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
name: Deploy Docusaurus to GitHub Pages | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build Docusaurus site | |
run: npm run build | |
- name: Print git remote | |
run: git remote -v | |
- name: Clean gh-pages branch | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git fetch origin | |
git checkout gh-pages || git checkout --orphan gh-pages | |
git rm -rf . | |
git clean -fdx | |
git commit --allow-empty -m "Clean gh-pages branch" | |
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/ttsk-ngo/swdr5-docs.git gh-pages | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./build | |
destination_dir: swdr5-docs |