GitHub Actions only outputting DLL file - c#

I recently tried automatically building and uploading my C# project. The build works fine, but the artifact sadly only contains a DLL file, and not a .exe file. When I build it locally, it outputs an .exe and a DLL file. Is that normal? This is my github actions file:
name: .NET
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
name: Build the app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build
- name: Upload a Build Artifact
uses: actions/upload-artifact#v2.2.2
with:
# Artifact name
name: buildresult #.zip will be added automatically
path: /home/runner/work/ParadoxicalLauncher/ParadoxicalLauncher/ParadoxicalLauncher/bin/Debug/net6.0/*.*

Related

Github Actions publish to Github Package registry fails with 401 using GITHUB_TOKEN (suddenly)

a Github Actions workflow stopped working throwing a 401 error when publishing a repo's package to the Github package registry. Within the workflow (detailed below) I am using semantic-release to publish the artefact to the registry. This is the last step in the yml. The permissions for the GITHUB_TOKEN have not been changed since initial setup of the action. It used to run just fine with these permissions.
./github/workflow.yml
name: ci
on:
push:
branches: [ main, dev ]
paths:
- src/**
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
steps:
- uses: actions/checkout#v3
- uses: actions/setup-dotnet#v2
with:
dotnet-version: '6.x.x'
- name: Build that shit
run: dotnet build ./src/project.csproj --configuration Release --nologo
- uses: actions/setup-node#v3
with:
node-version: 'lts/*'
- name: Release that shit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm ci && npx semantic-release
The GITHUB_TOKEN is mapped to an environment variable GH_TOKEN which then is referenced by semantic-release in the publishCmd.
./.releaserc
{
"branches": [
"main",
{
"name": "dev",
"prerelease": "dev"
}
],
"plugins": [
"#semantic-release/commit-analyzer",
"#semantic-release/release-notes-generator",
"#semantic-release/github",
[
"#semantic-release/exec", {
"prepareCmd": "dotnet pack ./src/project.csproj --no-restore --nologo --configuration Release /p:Version=${nextRelease.version}",
"publishCmd": "dotnet nuget push ./src/bin/Release/project.${nextRelease.version}.nupkg --source https://nuget.pkg.github.com/MY_ORG/index.json --api-key ${process.env.GH_TOKEN}"
}
]
]
}
The logs show the last step failing
[11:05:13 AM] [semantic-release] › ℹ Start step "publish" of plugin "#semantic-release/exec"
[11:05:13 AM] [semantic-release] [#semantic-release/exec] › ℹ Call script dotnet nuget push ./src/bin/Release/project.2.8.6.nupkg --source https://nuget.pkg.github.com/MY_ORG/index.json --api-key [secure]
error: Unable to load the service index for source https://nuget.pkg.github.com/MY_ORG/index.json.
error: Response status code does not indicate success: 401 (Unauthorized).
This is a repo owned by the organization I am employed with. There are no dependencies to private packages registries, only public NUGET. So the GITHUB_TOKEN should suffice according to the docs. And also according to previous successful execution history.
Does someone spot something I am missing?
The only way I made this work again on GH is using a PAT.
Created a PAT in my user/developer settings
Added a secret in my repo called NUGET_PAT
Updated my yaml file to this
name: "Push to main"
on:
push:
tags:
- '*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-dotnet#v3
with:
dotnet-version: '7.0.x'
- name: Add source
run: |
dotnet nuget add source \
--username THE_USER_OWNER_OF_THE_PAT --password "${{ secrets.NUGET_PAT }}" \
--store-password-in-clear-text --name github "https://nuget.pkg.github.com/YOUR_ORG/index.json"
- name: Restore packages
run: dotnet restore
- name: Build
run: dotnet build --configuration Release -p:Version=${{github.ref_name}} --no-restore
- name: Run tests
run: dotnet test --configuration Release --no-restore --no-build --verbosity normal
- name: Create nuget packages
run: dotnet pack --configuration Release -p:Version=${{github.ref_name}} --no-restore --no-build
- name: Publish nuget packages
run: dotnet nuget push **/*.nupkg -s "https://nuget.pkg.github.com/YOUR_ORG/index.json"
It pushes with warnings

Upload build artifacts that have changed using GitHub actions

I am trying to establish a GitHub workflow with the help of GitHub Actions. Theoretically, the workflow would deploy any new changes to the web server each time a pull request is merged into the master branch.
This is my yaml file thus far:
name: .NET
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.1.x
- name: Restore dependencies
run: dotnet restore src/my.Web.sln
- name: Build application
run: dotnet build src/my.Web.sln --no-restore
- name: Test application
run: dotnet test src/my.Web.sln --no-restore --verbosity normal
- name: Publish artifacts to default path
run: dotnet publish src/my.Web.sln
- name: Upload build artifacts for deployment
uses: actions/upload-artifact#v2
with:
name: Application
path: /home/runner/work/my-website/my-website/src/my.Web/bin/Debug/netcoreapp3.1/publish/
I can download the artifacts after each merge fine, but all the .dll files are uploaded even though I only want the ones that were updated in the most recent push.
Stack Overflow answers on other questions suggested adding fetch-depth: 0 under the actions/checkout#v2 step to get only the latest push, but all the files of the application are still uploaded.

Dotnet Semantic Versioning and Release with Github Actions

I have a dotnet project and am trying to build a CI/CD pipeline that does the following using Github Actions:
Builds the project on a PR or master change.
Tests the project on a PR or master change.
On a master change calculates a semver (ideally a changelog too but that's less important).
On a master change uses this semver, builds a nuget package, and publishes it to GitHub and Nuget.
So far, I have this workflow that builds and tests my project. This seems to work nicely. However, it also has a publish step, which never seems to be run (I guess the if is wrong(?)) and I'm really not sure where to start with the SemVer part of what I want.
name: .NET Build, Test and Publish
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
env:
DISCOS_API_KEY: ${{ secrets.DISCOS_API_KEY }}
DISCOS_API_URL: http://localhost:3000/api/
steps:
- uses: actions/checkout#v2
with:
submodules: recursive
- name: Build docker stack
run: docker-compose -f src/DISCOSweb-Sdk/DISCOSweb-Sdk.Tests/docker-compose.yml up -d --force-recreate --build
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
- name: Build
run: dotnet build --no-restore src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
- name: Test
run: dotnet test --no-build --verbosity normal src/DISCOSweb-Sdk/DISCOSweb-Sdk.sln
publish: # This stage is never run
if: github.event.pull_request.merged == 'true'
needs: build
runs-on: ubuntu-latest
steps:
- name: Publish
id: publish_nuget
uses: brandedoutcast/publish-nuget#v2
with:
PACKAGE_NAME: DISCOSweb-Sdk
PROJECT_FILE_PATH: "**/DISCOSweb-Sdk.csproj"
BUILD_CONFIGURATION: Release
NUGET_KEY: ${{secrets.NUGET_KEY}}
VERSION_STATIC: 1.0.0 # Replace with something better
I feel like this should be a relatively common and straightforward thing to do so any assistance would be really appreciated.
I managed to accomplish this by splitting my CI and CD workflows, and making use of some very helpful packages.
CI Workflow
This first workflow runs on PRs and pushes to master. It's worth noting that when branch protection is on, a push to master is synonymous with a merged PR.
name: .NET Continuous Integration
on:
pull_request:
branches: [ master ]
push:
branches: [ master ]
jobs:
test:
name: Test Project (Mock API)
runs-on: ubuntu-latest
env:
DISCOS_API_KEY: ${{ secrets.DISCOS_API_KEY }}
DISCOS_API_URL: http://localhost:3000/api/
steps:
- uses: actions/checkout#v3
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
- name: Build docker stack
run: docker-compose -f ./src/DiscosWebSdk/DiscosWebSdk.Tests/docker-compose.yml up -d --force-recreate --build
- name: Run tests against mock API
run: dotnet test --logger GitHubActions ./src/DiscosWebSdk/DiscosWebSdk.sln
CD Workflow
There's a bit more to the CD workflow. It runs on pushes to master but only when there are changes made to the folder containing the actual source code for the SDK (that's what the paths block does).
I then used the mathieudutour/github-tag-action#v6.0 action to tag the commit with a calculated semantic version (calculated using conventional commits).
The package build is then tagged with this version using the -p:PackageVersion=${{ steps.tag_version.outputs.new_version }} option on dotnet nuget pack.
The ncipollo/release-action#v1 also creates a release on Github.
Finally, building and pushing the release to Github and Nuget is done using dotnet nuget push as usual.
name: .NET Continuous Deployment
on:
push:
branches: [ master ]
paths:
- src/DiscosWebSdk/DiscosWebSdk/**
workflow_dispatch:
jobs:
test:
name: Test Project (Real API)
runs-on: ubuntu-latest
env:
DISCOS_API_KEY: ${{ secrets.DISCOS_API_KEY }}
DISCOS_API_URL: https://discosweb.esoc.esa.int/api/
steps:
- uses: actions/checkout#v3
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
- name: Test against real API
run: dotnet test --logger GitHubActions ./src/DiscosWebSdk/DiscosWebSdk.sln
semantic-release:
needs: test
name: Create a Package Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3 # Need the full commit history for conventional commit
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action#v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub release
uses: ncipollo/release-action#v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
- name: Create Nuget Package
run: dotnet build -c Release ./src/DiscosWebSdk/DiscosWebSdk/DiscosWebSdk.csproj && dotnet pack -c Release -p:PackageVersion=${{ steps.tag_version.outputs.new_version }} -o . ./src/DiscosWebSdk/DiscosWebSdk/DiscosWebSdk.csproj
- name: Upload Package for Publishing
uses: actions/upload-artifact#v3
with:
name: PackedLib
path: ./*.nupkg
github-publish:
needs: semantic-release
name: Publish to Github
runs-on: ubuntu-latest
steps:
- name: Download built project
uses: actions/download-artifact#v3
with:
name: PackedLib
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
- name: Push Package to GitHub
run: dotnet nuget push --api-key ${{secrets.GITHUB_TOKEN}} --source "https://nuget.pkg.github.com/hughesjs/index.json" *.nupkg
nuget-publish:
needs: semantic-release
name: Publish to Nuget
runs-on: ubuntu-latest
steps:
- name: Download built project
uses: actions/download-artifact#v3
with:
name: PackedLib
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
- name: Push Package to Nuget
run: dotnet nuget push --api-key ${{secrets.NUGET_KEY}} --source "https://api.nuget.org/v3/index.json" *.nupkg

Couldn't publish 3 projects because of versionize

I'm trying to publish 3 projects as a nuget package. The following GitHub workflow works fine publishing Project1, but it doesn't publish src/Project2/Project2.csproj and src/Project3/Project3.csproj.
I tried to create 3 files with the exact same code but for each one of the projects and there is a conflict in versionize. The first project is being published just fine but the rest of them fail because of the versions.
How can I make it work that way?
name: Publish
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 6.0.x
source-url: https://nuget.pkg.github.com/Xnt/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
- name: Install dotnet tools
run: dotnet tool install --global Versionize
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Setup git
run: |
git config --global user.name 'GitHub actions'
git config --global user.email '...'
- name: Version
run: versionize
- name: Push tags
run: |
git push --follow-tags
- name: Pack
run: dotnet pack --no-build -c Release -o . src/Project1/Project1.csproj
- name: Publish
run: dotnet nuget push *.nupkg

Change variables in appsettings when deploying with github actions

I am trying to deploy an app with github actions. I linked my azure account to my github repository and the following actions has been created:
name: Build and deploy ASP.Net Core app to Azure Web App - my_app_name
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '3.1.102'
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Deploy to Azure Web App
uses: azure/webapps-deploy#v1
with:
app-name: 'my_app_name'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_xxxxxx }}
package: ${{env.DOTNET_ROOT}}/myapp
I have some variables in my appsettings.json file that I want to overwrite, but I don't find how to do it.
You may add the following action prior to deploying the artifacts to azure.
You can specify multiple files and it is supported with wildcard entries too.
The environment variable key must be specified with dot separated heirarchy.
#substitute production appsettings entries to appsettings json file
- name: App Settings Variable Substitution
uses: microsoft/variable-substitution#v1
with:
files: '${{env.DOTNET_ROOT}}/myapp/appsettings.json'
env:
ConnectionStrings.Default: ${{ secrets.SOME_CONNECTION_STRING }}
App.ServerRootAddress: ${{ env.SERVER_ROOT_ADDRESS }}
The above action can be used for xml and yaml file changes too.

Categories

Resources