Created
August 27, 2023 22:02
-
-
Save mr-awk/5d0cfd00d96aaaa80ea3500a6ae78f39 to your computer and use it in GitHub Desktop.
workflow for github actions dotnet c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a .NET project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
name: .NET | |
on: [push, pull_request] | |
jobs: | |
test: | |
name: Debug Build & Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --no-restore -c Debug | |
- name: Test | |
run: dotnet test -c Debug --no-build | |
release: | |
name: Create Github Release | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
needs: [test] | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
steps: | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.event.ref }} | |
release_name: Release ${{ github.event.ref }} | |
draft: false | |
prerelease: false | |
publish: | |
name: Publish | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
needs: [test, release] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: | | |
dotnet publish --os win -c Release -o ./publish -p:PublishDir=./publish --no-restore | |
zip -r ./publish/release.zip ./publish | |
- name: Create Release File Name & Upload URL | |
id: get_release_info | |
run: | | |
echo "FILE_NAME=${REPOSITORY_NAME##*/}-${TAG_REF_NAME##*/v}" >> $GITHUB_OUTPUT | |
env: | |
TAG_REF_NAME: ${{ github.event.ref }} | |
REPOSITORY_NAME: ${{ github.repository }} | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: ./publish/release.zip | |
asset_name: ${{ steps.get_release_info.outputs.FILE_NAME }}.zip | |
asset_content_type: application/zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment