Jenkins Plugin MSTestRunner equivalent in GitHub Workflow Actions - msbuild

Is there an MSTest.exe YAML equivalent in Github Actions Workflow?
If there is can a get sample yaml that includes how a /testcontainer, /category, and /resultsfile would look like?
I was able to find MSBuild. Not sure if it's possible to use MsBuild to run MSTest's if it is then an example using the above would solve my question as well.
Current Workflow yaml
name: MS Test Build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup MSBuild
uses: microsoft/setup-msbuild#v1.0.2
- name: MSTest
shell: powershell
run: '& "$(vswhere -property installationPath)\Common7\IDE\MSTest.exe" /testcontainer:Test.dll /resultsfile:TestResults.trx'
edit: updated with semi-working solution.

Since you have msbuild at hand you should also be able to run mstest:
name: MSBuild and MSTest CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#master
- name: Dependency - MSBuild
uses: microsoft/setup-msbuild#v1.0.2
with:
vswhere-path: 'C:\Program Files (x86)\Microsoft Visual Studio\Installer'
- name: MSBuild
working-directory: src
continue-on-error: true
run: msbuild MyProject.csproj
- name: MSTest
working-directory: src
continue-on-error: true
run: mstest <paramaters here>
Here you have info how to use msttest

Working solution. Still looking for improvements but this will work
name: MS Test Build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup MSBuild
uses: microsoft/setup-msbuild#v1.0.2
- name: MSTest
shell: powershell
run: '& "$(vswhere -property installationPath)\Common7\IDE\MSTest.exe" /testcontainer:Test.dll /resultsfile:TestResults.trx'

Related

How to fix Github Actions dotnet publish workflow error: The "--output" option isn't supported when building a solution

Something changed in the way the dotnet publish workflow task works. We've been using this pretty straightforward yaml script for some time now.
name: Publish to staging server
env:
AZURE_WEBAPP_NAME: 'my-dotnet-webapp'
AZURE_SLOT_NAME: 'staging'
GITHUB_PUBLISH_SECRET: ${{ secrets.AZURE_DEPLOYMENTSLOT_STAGING }}
AZURE_WEBAPP_PACKAGE_PATH: '.'
DOTNET_VERSION: '7.0.0'
on:
push:
branches:
- staging
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Set up .NET Core
uses: actions/setup-dotnet#v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache#v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- 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#v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
retention-days: 1
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#v3
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
slot-name: ${{ env.AZURE_SLOT_NAME }}
publish-profile: ${{ env.GITHUB_PUBLISH_SECRET }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Today, I tried to run with workflow and received the following error during the dotnet publish step:
Error: /usr/share/dotnet/sdk/7.0.200/Current/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets(36,5): error NETSDK1194: The "--output" option isn't supported when building a solution.
I expected the workflow to run without error as it has done dozens of times previously.
What's really going on here?
After a considerable amount of research and a little trial and error, I realized that I had to explicitly specify the webapp project file as an argument of the command. This is because I do still need to use the output option, so Github knows where to find the files in the subsequent deploy workflow.
Then there was the matter of figuring out the file path for the project file. This may vary for others based on their specific Visual Studio solution file structure.
Here is the fix that worked to resolve this issue (assume that when I created my project in VS, I named it MyWebApp:
- name: dotnet publish
run: dotnet publish ~/work/MyWebApp/MyWebApp/MyWebApp/MyWebApp.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp
Yes, that's 3 directories deep. The project file in my Windows file explorer is only 2 directories deep.
Hope this helps someone.
The reason for this is a update by .NET according to This guy, what worked for me was changing
--output .
To
--property:PackageOutputPath=.

How to pass a github secret to asp.net core app deployed using github action?

I want to use GitHub secrets inside the repository code.
The repository is an asp.net core web app. I am deploying the app to the Azure app service using Github actions.
I have tried declaring env variable in the workflow like this
# Docs for the Azure Web Apps Deploy action: https://go.microsoft.com/fwlink/?linkid=2134798
# More GitHub Actions for Azure: https://go.microsoft.com/fwlink/?linkid=2135048
name: Azure App Service - TestJuzer(Production), Build and deploy DotnetCore app
on:
push:
branches:
- master
env:
TEST_STRING: ${{ secrets.TEST_STRING }}
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
# checkout the repo
- name: 'Checkout Github Action'
uses: actions/checkout#master
- name: Set up Node.js '12.x'
uses: actions/setup-node#v1
with:
node-version: '12.x'
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '5.0.x'
- name: Build with dotnet
run: dotnet build --configuration Release
env:
TEST_STRING: ${{ secrets.TEST_STRING }}
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Run Azure webapp deploy action using publish profile credentials
uses: azure/webapps-deploy#v2
with:
app-name: TestJuzer
slot-name: Production
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_461CFB6B8D42419FA7F58944D621BA78 }}
package: ${{env.DOTNET_ROOT}}/myapp
env:
TEST_STRING: ${{ secrets.TEST_STRING }}
and accessing the env variable in .net like this
Environment.GetEnvironmentVariable("TEST_STRING")
"TEST_STRING" is the name of the secret. But I am getting null.
I want to pass secret as an environment variable in the workflow and use it in the deployed app.
Any help appreciated Thanks
You set env variable on agent machine. And here you should rather set it on App Service. You could use Azure App Service Settings:
Here is sample workflow:
# .github/workflows/configureAppSettings.yml
on: [push]
jobs:
build:
runs-on: windows-latest
steps:
- uses: azure/login#v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
- uses: azure/appservice-settings#v1
with:
app-name: 'my-app'
slot-name: 'staging' # Optional and needed only if the settings have to be configured on the specific deployment slot
app-settings-json: '${{ secrets.APP_SETTINGS }}'
connection-strings-json: '${{ secrets.CONNECTION_STRINGS }}'
general-settings-json: '{"alwaysOn": "false", "webSocketsEnabled": "true"}' #'General configuration settings as Key Value pairs'
id: settings
- run: echo "The webapp-url is ${{ steps.settings.outputs.webapp-url }}"
- run: |
az logout
In you case it could be like:
- name: Set Web App settings
uses: Azure/appservice-settings#v1
with:
app-name: 'node-rnc'
app-settings-json: |
[
{
"name": "TEST_STRING",
"value": "${{ secrets.TEST_STRING }}",
"slotSetting": false
}
]

GitHub CI: Push React build to another repo

I've set a GitHub action that make a build of my React application.
I need that build to be pushed to another repo that I'm using to keep track of the builds.
This is the action that is actually running:
on:
push:
branches: [master]
jobs:
build:
name: create-package
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14]
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
name: Use Node.js 14
with:
node-version: ${{ matrix.node-version }}
#- name: Install dependencies
- run: npm ci
- run: npm run build --if-present
env:
CI: false
copy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Copy to another repo
uses: andstor/copycat-action#v3
with:
personal_token: ${{ secrets.API_TOKEN_GITHUB }}
src_path: build
dst_path: /.
dst_owner: federico-arona
dst_repo_name: test-build
dst_branch: main
By the way when the action run the copy job it fails with the following message:
cp: can't stat 'origin-repo/build': No such file or directory
What am I doing wrong?
For anyone that needs an answer on this.
The problem was related to the fact that I was using two different jobs, one to run the build and one to copy that build to another repo.
This won't work because each job has its own runner and its own file system, meaning that the data aren't shared between jobs.
To avoid this problem I made all on in one job. Another solution is to pass the build between jobs as artifact:
https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts#passing-data-between-jobs-in-a-workflow
Another problem was related to the copy action I was using. For some reason that action didn't find the build directory, probably because its assuming a different working directory. I switched to another action.
Here's the final result:
on:
push:
branches: [master]
jobs:
build:
name: create-package
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14]
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
name: Use Node.js 14
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
env:
CI: false
- run: ls
- name: Copy to another repo
uses: andstor/copycat-action#v3
with:
personal_token: ${{ secrets.API_TOKEN_GITHUB }}
src_path: build
dst_path: /.
dst_owner: federico-arona
dst_repo_name: test-build
dst_branch: main

Github Actions Build Artifact Folder Location

I'm creating a .net build with github actions. I'm stuck on the last step for my build process, I'd like to automatically add the release folder as the artifact to upload, however, I'm not sure which variable, or if there is one to use to identify. Any assistance would be appreciated.
Example code below:
name: Build Capcom
on: [push]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v1
name: Checkout Code
- name: Setup MSBuild Path
uses: warrenbuckley/Setup-MSBuild#v1
- name: Setup NuGet
uses: NuGet/setup-nuget#v1.0.2
- name: Install Windows 8.1 SDK
shell: powershell
run: |
Invoke-WebRequest -Method Get -Uri https://go.microsoft.com/fwlink/p/?LinkId=323507 -OutFile sdksetup.exe -UseBasicParsing
Start-Process -Wait sdksetup.exe -ArgumentList "/q", "/norestart", "/features", "OptionId.WindowsDesktopSoftwareDevelopmentKit", "OptionId.NetFxSoftwareDevelopmentKit"
- name: Restore NuGet Packages
run: nuget restore ExploitCapcom.sln
- name: Build App
run: msbuild ExploitCapcom.sln /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=FolderProfile
- name: Upload artifact
uses: actions/upload-artifact#v2
with:
name: Capcom
path: "D:/a/newbuild/"

Difficults deploying circleci v.2 to AWS S3

I'm a newbie to to CI/CD stuff and I've been trying for a couple of days to deploy an application to our bucket at AWS S3.
I tried this:
https://medium.freecodecamp.org/how-to-set-up-continuous-deployment-to-aws-s3-using-circleci-in-under-30-minutes-a8e268284098
this:
https://circleci.com/docs/1.0/continuous-deployment-with-amazon-s3/
And this:
https://medium.com/#zlwaterfield/circleci-s3-upload-dbffa0956b6f
But somehow I wasn't able to succeed with my attempt to do so. Circleci says my file successful was build, but somehow no deploy was made and no error msg was received. My AWS permissions are set, so it's being really frustrating this task.
Here's my final file:
jobs:
build:
docker:
-
image: "circleci/openjdk:8-jdk"
environment:
JVM_OPTS: "-Xmx3200m"
TERM: dumb
steps:
- checkout
-
restore_cache:
keys:
- "v1-dependencies-{{ checksum \"build.gradle\" }}"
- v1-dependencies-
-
run: "gradle dependencies"
-
save_cache:
key: "v1-dependencies-{{ checksum \"build.gradle\" }}"
paths:
- ~/.gradle
-
run: "gradle test"
working_directory: ~/repo
deploy:
machine:
enabled: true
steps:
-
run:
command: 'aws s3 sync ${myAppName}/ s3://${myBucketName} --region us-west-2'
name: Deploy
working_directory: ~/repo
version: 2
Updated: I was able to find a way. Here's my solution in case anyone needs it:
jobs:
build:
docker:
-
image: "circleci/openjdk:8-jdk"
environment:
JVM_OPTS: "-Xmx3200m"
TERM: dumb
steps:
- checkout
-
restore_cache:
keys:
- "v1-dependencies-{{ checksum \"build.gradle\" }}"
- v1-dependencies-
-
run: "gradle dependencies"
-
save_cache:
key: "v1-dependencies-{{ checksum \"build.gradle\" }}"
paths:
- ~/.gradle
-
run: "gradle build"
-
run: "gradle test"
- run:
command: "sudo apt-get -y -qq install awscli"
name: "Install awscli"
-
run:
command: "aws configure list"
name: "show credentials"
-
run:
command: "aws s3 ls"
name: "List all buckets"
-
run:
command: "aws s3 sync /tmp/app/myProject/build/libs s3://my-aws-bucket"
name: "Deploy to my AWS bucket"
working_directory: /tmp/app
version: 2
workflows:
build-deploy:
jobs:
-
build-job:
filters:
branches:
only:
- /development.*/
- /staging.*/
version: 2