Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Reapism committed Nov 30, 2023
2 parents 0ca2d5c + a9beae2 commit 8198142
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
name: .NET CI/CD pipeline

env:
# The name of the project to build and package
IS_BETA: true
PROJECT_NAME: Sweaj.Patterns

# The path to the project file to build and package
TEST_PROJECT_NAME: Sweaj.Patterns.Tests
PROJECT_FILE: src/Sweaj.Patterns/Sweaj.Patterns.csproj

# The dotnet version to build and publish with
DOTNET_VERSION: 7.0.x

# The build configuration to use (e.g. Debug or Release)
TEST_PROJECT_FILE: tests/Sweaj.Patterns.Tests/Sweaj.Patterns.Tests.csproj
DOTNET_VERSION: 8.0.x
BUILD_CONFIGURATION: Release

# The directory to publish the package to
PACKAGE_DIRECTORY: nuget/

# The URL of the NuGet repository to publish the package to
NUGET_REPOSITORY_URL: https://api.nuget.org/v3/index.json

SWEAJ_NUGET_KEY: ${{ secrets.SWEAJ_NUGET_KEY }}

on:
push:
branches:
- develop
- main

jobs:
Expand All @@ -38,36 +28,30 @@ jobs:
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore dependencies
- name: RESTORE DEPENDENCIES
run: dotnet restore ${{ env.PROJECT_FILE }}

- name: Get package version from project file
id: package-version
run: echo "::set-output name=version::$(dotnet build ${env.PROJECT_FILE} /property:VersionPrefix=1.0 /v:q /nologo | grep -m1 'Version:' | awk '{print $2}')"

- name: Check if version already exists on NuGet
id: check-version

- name: EXTRACT AND INCREMENT VERSION
id: version-update
run: |
version=$(echo "${{ steps.package-version.outputs.version }}" | cut -d'-' -f1)
output=$(dotnet nuget list -s "${{ env.NUGET_REPOSITORY_URL }}" "${{ env.PROJECT_NAME }}" --version "${version}" | grep "${version}")
if [ -n "${output}" ]; then
echo "Package version ${version} already exists on NuGet. Skipping publish step."
echo "::set-output name=version-exists::true"
else
echo "Package version ${version} does not exist on NuGet. Proceeding with publish step."
echo "::set-output name=version-exists::false"
fi
- name: Build
current_version=$(grep -oP '(?<=<Version>)[^<]+' ${{ env.PROJECT_FILE }})
IFS='.' read -ra version_parts <<< "$current_version"
version_parts[2]=$((version_parts[2]+1))
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
sed -i "s/<Version>$current_version<\/Version>/<Version>$new_version<\/Version>/" ${{ env.PROJECT_FILE }}
echo "::set-output name=new_version::$new_version"
echo "Updated version to $new_version"
- name: BUILD ${{ env.PROJECT_FILE }} ${{ env.BUILD_CONFIGURATION }}
run: dotnet build ${{ env.PROJECT_FILE }} -c ${{ env.BUILD_CONFIGURATION }}

- name: Test
run: dotnet test ${{ env.PROJECT_FILE }} -c ${{ env.BUILD_CONFIGURATION }} --no-build
- name: TEST ${{ env.TEST_PROJECT_FILE }} ${{ env.BUILD_CONFIGURATION }}
run: dotnet test ${{ env.TEST_PROJECT_FILE }} -c ${{ env.BUILD_CONFIGURATION }} --no-build

- name: Pack
- name: PACK ${{ env.PROJECT_FILE }}
run: dotnet pack ${{ env.PROJECT_FILE }} -c ${{ env.BUILD_CONFIGURATION }} --output ${{ env.PACKAGE_DIRECTORY }}

- name: Push package to NuGet
- name: PUSH
env:
nuget: ${{ env.PACKAGE_DIRECTORY }}*.nupkg
run: |
Expand Down

0 comments on commit 8198142

Please sign in to comment.