Created
September 6, 2020 15:53
-
-
Save FoseFx/4b881270737a43acd01e275104bd4969 to your computer and use it in GitHub Desktop.
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
# 1. Create a new empty orphan branch called gh-pages: | |
# $ git checkout --orphan gh-pages && git reset --hard && git commit -m "create gh-pages" --allow-empty && git push origin gh-pages && git checkout master | |
# 2. Enable gh pages for the gh-pages /docs directory and you should be good | |
# 3. Alter the gh-pages step to fit your framework of choice | |
name: Push to Github pages | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
gh-pages: | |
runs-on: ubuntu-latest | |
steps: | |
# checkout master | |
- uses: actions/checkout@v2 | |
# install node | |
- name: Use Node.js 12.x | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 12.x | |
# install deps and build | |
- run: npm ci | |
- run: npm run build | |
env: | |
GH_PAGES: 'true' # when deploying a SPA you need to change the router's base | |
- name: remove docs, if it exists | |
run: rm docs -rf | |
# move dist to docs, so github pages works | |
- run: mv dist docs | |
# checkout gh-pages branch | |
- uses: actions/checkout@v2 | |
with: | |
ref: 'refs/heads/gh-pages' | |
clean: false | |
# set FILES_CHANGED, so following steps are ignored when no change occured | |
- name: set FILES_CHANGED | |
run: echo "::set-env name=FILES_CHANGED::$(git status --short docs | wc -l)" | |
- run: echo $FILES_CHANGED | |
env: | |
FILES_CHANGED: ${{ env.FILES_CHANGED }} | |
# commit dist to gh-pages | |
- name: Commit files | |
if: env.FILES_CHANGED != 0 | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Anon" | |
git add docs | |
git commit -m "$GITHUB_SHA" | |
# push chages to gh-pages branch | |
- name: Push changes | |
if: env.FILES_CHANGED != 0 | |
uses: ad-m/github-push-action@master | |
with: | |
branch: 'gh-pages' | |
github_token: ${{ secrets.GITHUB_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment