Skip to content

Create main.yml

Create main.yml #1

Workflow file for this run

name: Build and Publish NuGet
permissions:
contents: read
packages: write
on:
push:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0'
publishclient:
runs-on: windows-latest
steps:
- name: Restore dependencies
run: dotnet restore
working-directory: ./RDSServiceClient
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ./RDSServiceClient
- name: Pack
run: dotnet pack --configuration Release --no-build --output ../nupkgs
working-directory: ./RDSServiceClient
- name: Push to GitHub Packages
run: dotnet nuget push "*.nupkg" --source "https://nuget.pkg.github.com/kyle079/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
working-directory: ./nupkgs
publishservice:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Restore dependencies
run: dotnet restore
working-directory: ./RDSService
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ./RDSService
- name: Pack
run: dotnet publish --configuration Release --no-build --output ../release
working-directory: ./RDSService
- name: Zip
run: Compress-Archive -Path ./release/* -DestinationPath ./RDSService.zip
- name: Extract Version
id: get_version
shell: pwsh
run: |
$csprojPath = './RDSService/RDSService.csproj' # Adjust the path to your project file
$csproj = [xml](Get-Content $csprojPath)
$version = $csproj.Project.PropertyGroup.Version
echo "::set-output name=version::$version"
- name: Check if Release Exists
id: check_release
uses: octokit/[email protected]
with:
route: GET /repos/:repository/releases/tags/:tag
tag: ${{ steps.get_version.outputs.version }}
repository: ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Create Release if Not Exists
if: steps.check_release.outputs.data == null
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: Release ${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
- name: Get Release Upload URL
id: get_upload_url
run: |
if [ "${{ steps.check_release.outputs.data }}" == "" ]; then
echo "::set-output name=upload_url::${{ steps.create_release.outputs.upload_url }}"
else
echo "::set-output name=upload_url::$(echo '${{ steps.check_release.outputs.data }}' | jq -r .upload_url)"
fi
shell: bash
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_upload_url.outputs.upload_url }}
asset_path: ./RDSService.zip
asset_name: RDSService.zip
asset_content_type: application/zip