Search code examples
githubgithub-pagesgithub-actionsblazor-client-side

trying to publish Blazor to GitHub pages using GitHub Actions


I'm trying to publish Blazor to GitHub Pages using GitHub Actions.

I used this tutorial and this example, use GitHub Pages Deploy Action.

My main.yml:

name: Build and Deploy
on: [push]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.100
    - name: Publish with dotnet
      run: dotnet publish --configuration Release --output build
    - name: Deploy to Github Pages
      uses: JamesIves/github-pages-deploy-action@releases/v3
      with:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
        BASE_BRANCH: master
        BRANCH: gh-pages-people # The branch the action should deploy to.
        FOLDER: build/BlazorGame/dist # The folder the action should deploy.
        CLEAN: true

So, it compiles code in my master, then should create new branch and deploy compiled code there.

I called my branch people-publish and it published fine:

enter image description here

git switch -c gh-action-temp-deployment-branch
Switched to a new branch 'gh-action-temp-deployment-branch'
git commit -m Deploying to people-publish from master 56b7095f73aeb2fa7850956778934c04d3a7eac6 --quiet
git push --force https://***@github.com/alexan1/BlazorGame.git gh-action-temp-deployment-branch:people-publish
To https://github.com/alexan1/BlazorGame.git
   d2a2c28..28c546d  gh-action-temp-deployment-branch -> people-publish
Running post deployment cleanup jobs... 🔧
rm -rf gh-action-temp-deployment-folder
git checkout --progress --force 56b7095f73aeb2fa7850956778934c04d3a7eac6
Note: switching to '56b7095f73aeb2fa7850956778934c04d3a7eac6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 56b7095 Create .nojekyll
Completed Deployment ✅

But this branch was not present in GitHub Pages option, there was only master and doc.

So I decided that branch should start with gh-pages name.

So I changed it to gh-pages-people.

But now deployment failed:

enter image description here

Branch 'master' set up to track remote branch 'master' from 'origin'.
git switch --orphan gh-pages-people
Switched to a new branch 'gh-pages-people'
git reset --hard
git commit --allow-empty -m Initial gh-pages-people commit.
[gh-pages-people (root-commit) bbc1556] Initial gh-pages-people commit.
git push https://***@github.com/alexan1/BlazorGame.git gh-pages-people
remote: 
remote: Create a pull request for 'gh-pages-people' on GitHub by visiting:        
remote:      https://github.com/alexan1/BlazorGame/pull/new/gh-pages-people        
remote: 
To https://github.com/alexan1/BlazorGame.git
 * [new branch]      gh-pages-people -> gh-pages-people
git switch master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
git switch master
Already on 'master'
Your branch is up to date with 'origin/master'.
git fetch https://***@github.com/alexan1/BlazorGame.git
From https://github.com/alexan1/BlazorGame
 * branch            HEAD       -> FETCH_HEAD
git worktree add --checkout gh-action-temp-deployment-folder origin/gh-pages-people
fatal: invalid reference: origin/gh-pages-people
The deployment encountered an error. ❌
##[error]The process 'git' failed with exit code 128
Completed Deployment ✅
##[error]Node run failed with exit code 1
  Complete job 

I tried to change branch name back again, but it's always failing.

New branch created, but it's empty.

What I do wrong?


Solution

  • Deployment is working, but you need to follow 2 conditions:

    1. When Action run first time, branch is created, but deployment failed. You need to run Action second time (new commitment) and it deployed to already created branch. All Action you can after will deploy without problem because branch exists. Not sure how to fix it, maybe add some delay between creating branch and deployment, but I don't need to worry about, because my problem is fixed.

    2. To be able publish GitHub Pages from branch, branch name should be exactly gh-pages without any modifications.