Deploy to GitHub Pages using GitHub Actions
mainTo deploy via GitHub Actions, you must set the git remote URL using the GITHUB_TOKEN and define a user with the -u flag. The GITHUB_TOKEN and GITHUB_REPOSITORY variables are provided automatically by GitHub Actions and should be passed to the environment.
If you are using a named script from package.json (e.g., npm run deploy), you must use the -- separator to pass arguments through to the underlying gh-pages command.
# Example: Direct deployment
- name: Deploy with gh-pages
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
npx gh-pages -d build -u "github-actions-bot <support+actions@github.com>"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Example: Deployment via npm script (e.g., "deploy": "gh-pages -d build")
- name: Deploy with gh-pages
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
npm run deploy -- -u "github-actions-bot <support+actions@github.com>"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}