Skip to content
name: Build and publish netlify (master) or github pages (other branches)
on:
push:
branches: [ "*" ]
env:
WEBAPP_PATH: src
ASPNETCORE_ENVIRONMENT: Production
WEBAPP_CSPROJ: Zodoc.csproj
jobs:
deploy:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Tailwind - download and run cli
run: |
wget https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -O /usr/local/bin/tailwindcss
chmod +x /usr/local/bin/tailwindcss
cd ${{ env.WEBAPP_PATH }}
tailwindcss --input ./wwwroot/app.css --output ./wwwroot/app.min.css --minify
# for master branch, keep the base href as /, but otherwise change it to repo name (for gh pages)
- name: Change <base href="" /> in App.razor to match gh repo name
if: github.ref != 'refs/heads/master'
run: |
REPO_NAME=$(echo "${{ github.repository }}" | awk -F '/' '{print $NF}')
sed -i 's/<base href="\/" \/>/<base href="\/'$REPO_NAME'\/" \/>/g' ${{ env.WEBAPP_PATH }}/Components/App.razor
- name: Run webapp and generate static files
run: |
rm ${{ env.WEBAPP_PATH }}/Properties/launchSettings.json #otherwise it overrides the ASPNETCORE_ENVIRONMENT
dotnet run --project ${{ env.WEBAPP_PATH }}/${{env.WEBAPP_CSPROJ}}
- name: Deploy to GitHub Pages
if: github.ref != 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@v4
with:
FOLDER: ${{ env.WEBAPP_PATH }}/output
- name: Deploy to netlify-deploy branch
# if: github.ref == 'refs/heads/master'
run: |
git config user.email "deploy@zodoc.tech"
git config user.name "Deploy Bot"
git checkout --orphan ${{ env.NETLIFY_DEPLOY_BRANCH }}
git rm -rf .
cp -r ${{ env.WEBAPP_PATH }}/output/* .
git add . && git commit -m "deploy from github actions"
git push origin ${{ env.NETLIFY_DEPLOY_BRANCH }} --force
env:
NETLIFY_DEPLOY_BRANCH: netlify-deploy