Apply EF migrations in GitHub workflow - asp.net-core

I have a GitHub repository for my Asp Net Core project with EF Core 3.0. I added the following workflow to run each time on updating the develop branch
name: Develop Build
on:
push:
branches:
- develop
pull_request:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.0.102-servicing-014397
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Test with dotnet
run: dotnet test --configuration Release
- name: Update database
run: dotnet ef database update --c DataContext --p MyProj --s MyProjFactory
The last line returns with an error:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
##[error]Process completed with exit code 1.
How can I apply the latest migrations to the target database using this workflow?

I also had to add commands to install EF tool and to restore all tools to make my workflow work correctly:
- name: Update database
run: |
dotnet tool install --global dotnet-ef
dotnet tool restore
dotnet ef database update -c DataContext -p MyProj -s MyProjFactory
env:
ASPNETCORE_ENVIRONMENT: Development

You might want to run your workflow in a windows environment, i.e. using windows-latest rather than ubuntu-latest. You can see the software installed on windows here.
For Windows Server 2019, it says:
PATH: contains location of dotnet.exe
There is no mention of dotnet being on the PATH for the Linux environments

Related

Can't find path to the project on virtual machine running workflows

job execution on the VM .
When the job begins, GitHub automatically provisions a new VM for that job. All steps in the job execute on the VM, allowing the steps in that job to share information using the runner's filesystem. You can run workflows directly on the VM or in a Docker container. When the job has finished, the VM is automatically decommissioned.
I found this from https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
I need to know the exact filepath to my project on github virtual machine.
For example:
name: Node Continuous Integration
on:
pull_request:
branches: [ master ]
jobs:
test_pull_request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 12
- run: npm ci
- run: npm test
- run: npm run build
I know that my project will be copied to ubuntu virtual machine but where exactly will it be located?
Since you're using the checkout action, your repository files will be located under the $GITHUB_WORKSPACE directory.
$GITHUB_WORKSPACE - a default environment variable that means the default working directory on the runner for steps, and the default location of your repository when using the checkout action. For example, /home/runner/work/my-repo-name/my-repo-name.
For more details, see:
actions/checkout docs
Default environment variables docs

GitHub Action: Deploy output of vue-cli-service build to Azure App Service

I'm using a GitHub action to deploy to Azure App Service, and, although the npm build succeeds, I cannot figure out how to get the output of that build to be deployed along with the output of the .NET build.
As you can see in my workflow file, for the .NET build, I specified --output ./deploy and then at the bottom, that is deployed via package: './deploy'
However I don't know how to get the npm build output into './deploy'. Currently, the npm build places the output into ClientApp/dist, according to vue.config.js.
Vue config relevant line: outputDir: path.resolve(__dirname, "ClientApp/dist")
Entire action workflow file:
name: CI
on:
push:
branches: [ master ]
jobs:
build-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-dotnet#v1
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
with:
dotnet-version: '5.0.x'
- run: dotnet build ./source/trunk/my/project.csproj --output ./deploy
- name: Frontend build
working-directory: ./source/trunk/my/project
run: |
npm install
npm install #vue/cli-service
npx -p #vue/cli vue-cli-service build --mode development
- name: Azure login
uses: azure/login#v1.1
with:
creds: ${{ secrets.MY_SECRET}}
enable-AzPSSession: false
- name: Azure deploy
uses: azure/webapps-deploy#v2
with:
app-name: my-app-name
package: './deploy'

How to run XUnit tests with ASP.NET Core dependency in Azure DevOps pipeline?

We're setting up CI/CD for an ASP.NET Core Web API project. We want to run unit tests in the build pipeline from an XUnit project that references the Web API project. This is from our build pipeline:
# azure-pipelines.yml
...
pool:
vmImage: 'windows-latest'
...
- task: UseDotNet#2
inputs:
version: 3.1.x
packageType: runtime
- task: DotNetCoreCLI#2
inputs:
command: build
projects: '**/MyWebApi.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
inputs:
command: test
projects: '**/MyUnitTests.csproj'
arguments: '--configuration Release'
...
When we run it, the Web API project is successfully built, but the tests fail to run, giving the following error:
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
Do we need to extract the classes (from Web API project) that we want to test into another library that doesn't depend on AspNetCore framework? Or can we install the framework on the pipeline agent with a task like UseDotNet#2?
Please change your UseDtonet step and ad restore step as follows:
- task: UseDotNet#2
inputs:
version: 3.1.x
packageType: sdk
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '**/*.csproj'

Crash after Azure DevOps CI build succeeded

I have created an Azure DevOps Continuous Integration Pipeline for my React-Native Project. My Yaml is as below:
pool:
name: Azure Pipelines
demands: yarn
steps:
- task: NodeTool#0
displayName: 'Use Node 10.x'
inputs:
versionSpec: 10.x
- task: geeklearningio.gl-vsts-tasks-yarn.yarn-task.Yarn#3
displayName: 'Install NPM modules'
- task: Bash#3
displayName: 'clean '
inputs:
targetType: filePath
filePath: ./android/gradlew
arguments: clean
workingDirectory: android
- task: Bash#3
displayName: 'assembleRelease '
inputs:
targetType: filePath
filePath: ./android/gradlew
arguments: 'assembleRelease -x bundleReleaseJsAndAssets'
workingDirectory: android
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: android/app/build/outputs/apk/release
The build succeeded, but the problem is that the APK always crashes on the devices, but when I build the APK manually it does not crash.
Could any one help me?
I see you didnot specify an agent vmImage to build your apk. You should specify the vmImage under the pool to let your apk be built on the desired OS. Since the apk built locally worked fine. You can specify an agent vmImage the same with you local machine.
pool:
vmImage: windows-latest #or ubuntu-latest if your local machine is linux.
You can try using gradle task to build your apk instead of using bash task. Unsigned APKs can only run in an emulator. APKs must be signed to run on a device. So after your apk is generated. you need to use Android Signing task to sign your apk in azure pipeline.
Please check this detailed tutorial for more information.
In case the difference of jdk version causes the issue. You can compare the Jdk version used locally with the jdk version it used on your pipeline by checking the build task log. And make sure the jdk version used in azure pipeline is the same with your local jdk version by setting the JDK version field of gradle task.

Continuous Deployment not working

I need to continually build a create-react-app application and deploy it to Amazon S3 bucket.
I have written the following CircleCi config.yml:
version: 2
jobs:
build:
docker:
- image: circleci/node:7.10
steps:
- checkout
- run: npm install
- run: npm run build
deployment:
prod:
branch: circle-config-test
commands:
- aws s3 sync build/ s3://http://www.typing-coacher.net.s3-website.eu-central-1.amazonaws.com/ --delete
What I think should happens:
I have a docker container, I install the application, build it and the files are resting ready in build folder.
I am running the command listed in CircleCi docs and the build files are moving from the docker machine to s3 bucket.
To deploy a project to S3, you can use the following command in the
deployment section of circle.yml:
aws s3 sync <path-to-files> s3://<bucket-URL> --delete
What actually happens:
Application is being install and build files are being created, but nothing happen with deployment. it doesn't even appear on the builds console.
What Am i missing?
disclaimer: CircleCI Developer Advocate
Everything from the deployment: line and down shouldn't be there. That's syntax for CircleCI 1.0 while the rest of your config file is CircleCI 2.0.
You can either:
Create a new step and check for the branch name with Bash. If it's circle-config-test, then run the deployment commands. You'll also need to install the AWS CLI in that build.
Using [CircleCI Workflows], create a deployment job with a branch filter for circle-config-test. You can use any image that contains the AWS CLI or install it yourself. The CI Builds: AWS Docker image contains this for you.