GitHub actions deploys wrong version of Newtonsoft.Json nuget package to Azure - azure

I have a GitHub action doing .net solution build, test and deploy to Azure:
name: Build and deploy ASP.Net Core app to Azure Web App - project-test-api
on:
push:
branches:
- main
workflow_dispatch:
env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: AutoModality/action-clean#v1
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Manually restore
working-directory: SolutionDir
run: dotnet restore --force
- name: Build with dotnet
working-directory: SolutionDir
run: dotnet build --configuration Release --no-restore
- name: Test
working-directory: SolutionDir
run: dotnet test --no-restore --no-build --configuration Release
- name: dotnet publish
working-directory: SolutionDir
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'quickplanner-test-api'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_SECRET }}
package: .
Recently I added a test project to the solution. From what I can see one of the packages used in the test project uses Newtonsoft.Json v9.0 when the rest of the solution uses v13.0. The solution can be built locally, tested and everything is ok. The GitHub action also finishes successfully building the solution, runs tests and deploys it to Azure. The problem occurs on Azure - somewhere along the way GitHub action uses an older version of Newtonsoft.Json. All projects expect newer ones, so the whole website breaks because of this. I'm not sure how to fix this - I've tried adding manually correct version of Newtonsoft.Json to the test project, to all projects, clearing caches in GitHub actions but without luck. What works is just removing test project from the solution, but obviously I want tests to be working. Does anyone has idea why this breaks and how to fix it?

I managed to fix this problem by adding this code to my Tests project csproj file:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
I'm not entirely sure what was the root cause behind this problem

Related

Github Action Build & Deploy .Net Core API & Flutter Web Project to Same Server/Domain

I currently have .Net Core Web API using Github Actions to CI/CD to Azure. (code sample below)
This has been effective for backend work but now am looking to start deploying the front end as well.
The Flutter Web frontend code could either live in the same repo as the API or not which ever is easier to set up - I'm flexible on this point.
I've been trying to figure out what a Github Action YAML would look like to build the Web API backend and also build the Flutter Web Frontend and then deploy them both to the same server/domain
Meaning the end result is:
www.example.com --> would use my flutter web front end
www.example.com/api --> would use my .net core web API backend
Online examples seems to either deploy Flutter apps to Azure Static Webpage or Github Pages which isn't exactly what I'm doing here.
I've seen here how I can built Flutter using actions and can probably save the build artifact created without much issue: How to build Flutter in GitHub Actions CI/CD
But then confused what the configuration would be to deploy both the Flutter and API artifacts. Feeling like perhaps this isn't even possible through Github Actions and maybe need to use Azure DevOps to do something more?
Current Action YAML
name: Build and deploy ASP.Net Core app to Azure Web App - MyApp
on:
push:
branches:
- development
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'DevMyApp'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_XXXXXXXXXXXXX }}
package: .

Angular artifact in Azure contains ~43k files

So I have this this small Angular project of mine and every time I try to deploy it to Azure, it uploads ~43k files as an artifact. I'm not any good at deployment to Azure, so this may as well be a really stupid question, but still.
So, here is my GitHub Actions workflow file
name: Build and deploy Node.js app to Azure Web App - minesweeper
on:
release:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Node.js version
uses: actions/setup-node#v1
with:
node-version: '16.x'
- name: npm install, build, and test
run: |
npm install
npm run build --prod
working-directory: .
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: node-app
path: .
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: node-app
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'minesweeper'
publish-profile: $
package: ./dist/minesweeper_
So, here I have a path, that matches my project's name: minesweeper_ and app name is from azure
What am I doing wrong here
https://github.com/yan14171/Minesweeper - here is the repo itselff
There are over 10,000 files in this artifact, consider creating an archive before upload to improve the upload performance.
As per documentation:
During upload, each file is uploaded concurrently in 4MB chunks using a separate HTTPS connection per file. Chunked uploads are used so that in the event of a failure, the upload can be retried. If there is an error, a retry will be attempted after a certain period of time.
Alternatively, you can try zip and unzip steps as mentioned by Steve.
You can refer to React Deployment on App Service Linux, and Deploying Node.js to Azure App Service with GitHub Actions

exclude files from being sent over github actions

Im trying to find out if there is a way to exclude certain files from being sent over github actions, for example, i have a server and a client in the same repository. right now, both the server (node.js) and the client (its a react.js application) are being hosted together on azure app services. once the / is hit, it serves up the index.html file from the build folder.
however I am finding that hosting these two things together is taking its toll on the overall application, for example, it sometimes takes up to 10 seconds for the server to respond and return the index file to the client. I remember in my training some of my more senior devs didnt like to host the server and client together, and im starting to see why..
so I likely will need to split these up to improve performance, but before i go through a daunting task of splitting the repositories up. is there a way to specify in github actions in a workflow to ignore certain files/folders etc..
the only modification i've made to this is that i added an action to zip the application for faster upload to azure to improve workload performance.
here is my workflow:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js app to Azure Web App
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Node.js version
uses: actions/setup-node#v1
with:
node-version: '14.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Zip artifact for deployment
run: zip release.zip ./* -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: node-app
path: release.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: node-app
- name: unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'Omitted'
slot-name: 'Production'
publish-profile: ${{SECRET}}
package: .
You could create a shell script that excludes the files you don't want.
In .github, create a new folder scripts. Inside the scripts folder, create a new file named exclude.sh.
In the exclude.sh, add the following:
zip -r [file_name.zip] [files/folder to zip] -x [file path/name to exclude]
In your workflow:
- name: unzip artifact for deployment
run: unzip file_name.zip

Github Actions with Azure Devops Pipelines not updating web application

So I have a github repo and an azure app service.
I have created a github actions setup which when I run I get this result (no errors)
However the web app does not update, the main page is the same as before deployment, nothing has changed.
In App Service the GitHub Project value is pointing at the correct project and clicking the link confirms this.
So I am not sure what is failing to happen, below is my yml file.
name: TestDevelopment
on:
push:
branches:
- development
env:
AZURE_WEBAPP_NAME: ^^^^^^^^^^^^^^^^
jobs:
build:
name: BuildDev
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet#v1.7.2
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Publish
run: dotnet publish testApp.Core/ testApp.Core.csproj --configuration Release --framework netcoreapp3.1 --output ./publish --runtime win-x86 --self-contained true -p:PublishTrimmed=true -p:PublishSingleFile=true
unittests:
needs: build
name: Dev Unit Testing
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet#v1.7.2
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Unit Tests
run: dotnet test testApp.Tests --no-restore --verbosity Minimal
webdeploy:
needs: unittests
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Azure webapp deploy
uses: azure/webapps-deploy#v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.azure }}
Interesting, I removed the App Service in Azure and then re-created.
Now it works a treat. not sure why but happy as larry now.

React deployment to firebase using github actions

on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#master
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Archive Production Artifact
uses: actions/upload-artifact#master
with:
name: build
path: build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout#master
- name: Download Artifact
uses: actions/download-artifact#master
with:
name: build
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
now this is the gtihub actions workflow it is executing build job without errors but in deployment there comes an error
this is the error image
the error its shows is Error: Specified public directory 'build' does not exist, can't deploy hosting to site landing-page-design-1 i have followed the blog from where the workflow is copied i did everything same except some of my project details which is obvious please help me out why is this error occuring and how can i fix it
You're probably unpacking artifact to root directory instead of build/.
I'm guessing article was written for download-artifact#v1 while you are using download-artifact#v2 (as that's where master points currently). Difference between both is discussed here.
I'd verify first what is going on after artifact is downloaded
- name: Display directory structure
run: ls -R
shell: bash
If files are indeed in root directory, adding path should fix that.
- name: Download Artifact
uses: actions/download-artifact#v2
with:
name: build
path: build
PS: Using actions/<name>#master is not recommended, as it can always lead to issues if same action behaves differently between versions... for example actions/download-artifact ;)
You can also try to use firebase-publish-react to simplify your workflow file
This particular action plugin takes care of building the application internally and also can reuse the build directory from previous steps.
- name: Deploy to Firebase
uses: mohammed-atif/firebase-publish-react#v1.0
with:
firebase-token: ${{ secrets.FIREBASE_TOKEN }}

Resources