diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index beef9f3..3a25c83 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -6,6 +6,7 @@ on: push: branches: - 'master' # Run the workflow when pushing to the master branch + pull_request: # Run the workflow on pull requests env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 @@ -87,10 +88,21 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 + # Authenticate with GitHub Packages using the GITHUB_TOKEN secret + - name: Authenticate with GitHub Packages + run: dotnet nuget add source https://nuget.pkg.github.com/hootanht/index.json -n github -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text + + # Publish all NuGet packages to GitHub Packages + - name: Publish NuGet package to GitHub Packages + run: | + foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) { + dotnet nuget push $file --api-key "${{ secrets.GITHUB_TOKEN }}" --source https://nuget.pkg.github.com/hootanht/index.json --skip-duplicate + } + # Publish all NuGet packages to NuGet.org # Use --skip-duplicate to prevent errors if a package with the same version already exists. # If you retry a failed workflow, already published packages will be skipped without error. - - name: Publish NuGet package + - name: Publish NuGet package to NuGet.org run: | foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) { dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/.github/workflows/ci.yml b/.github/workflows/CI.yml similarity index 77% rename from .github/workflows/ci.yml rename to .github/workflows/CI.yml index 0a5c985..315ad4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/CI.yml @@ -1,9 +1,8 @@ name: CI on: - pull_request: - branches: - - master + workflow_dispatch: # Allow running the workflow manually from the GitHub UI + pull_request: # Run the workflow on pull requests jobs: build: diff --git a/PersianDate/PersianDate.csproj b/PersianDate/PersianDate.csproj index 1222ebb..e11a6ec 100644 --- a/PersianDate/PersianDate.csproj +++ b/PersianDate/PersianDate.csproj @@ -16,11 +16,11 @@ en-US https://github.com/hootanht/PrsianDate 1.0.5 - https://github.com/hootanht/PrsianDate + https://github.com/hootanht/PersianDate git disable enable - https://api.nuget.org/v3/index.json + https://nuget.pkg.github.com/hootanht/index.json nuget true true diff --git a/README.md b/README.md index ae7497c..3e73f8b 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ Persian Data Library is a library that can be convert **Gregorian** (Milady) yea ## Persian Date Public Version | Target | Branch | Version | Download link | Total downloads | CI Build Status | CD Build Status | | ------ | ------ | ------ | ------ | ------ | ------ | ------ | -| Nuget | master | v1.0.5 | [![NuGet](https://img.shields.io/nuget/v/PersianDateShamsi.svg)](https://www.nuget.org/packages/PersianDateShamsi) | [![NuGet downloads](https://img.shields.io/nuget/dt/PersianDateShamsi.svg)](https://www.nuget.org/packages/PersianDateShamsi) | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/ci.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CD.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | -| Release | master | v1.0.5 | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/ci.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/ci.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CD.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | +| Nuget | master | v1.0.5 | [![NuGet](https://img.shields.io/nuget/v/PersianDateShamsi.svg)](https://www.nuget.org/packages/PersianDateShamsi) | [![NuGet downloads](https://img.shields.io/nuget/dt/PersianDateShamsi.svg)](https://www.nuget.org/packages/PersianDateShamsi) | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CI.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CD.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | +| Release | master | v1.0.5 | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CI.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CI.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | [![Build Status](https://github.com/hootanht/PersianDate/actions/workflows/CD.yml/badge.svg)](https://github.com/hootanht/PersianDate/actions) | ## Cross Platform @@ -81,8 +81,31 @@ Version 1.0.1 ## CI Pipeline -The CI pipeline is now integrated into the CD pipeline and is defined in `.github/workflows/CD.yml`. It uses `macos-latest` as the VM image. The pipeline handles manual triggers, pull requests, and releases. It restores NuGet packages, builds the solution, runs tests, and validates the NuGet package. The pipeline installs .NET version 8.0.x to ensure compatibility with all targeted frameworks. +The CI pipeline is now integrated into the CD pipeline and is defined in `.github/workflows/CI.yml`. It uses `macos-latest` as the VM image. The pipeline handles manual triggers, pull requests, and releases. It restores NuGet packages, builds the solution, runs tests, and validates the NuGet package. The pipeline installs .NET version 8.0.x to ensure compatibility with all targeted frameworks. ## CD Pipeline The CD pipeline is defined in `.github/workflows/CD.yml` and uses `macos-latest` as the VM image. It includes steps for creating, validating, testing, and deploying the NuGet package. The pipeline handles manual triggers, pull requests, and releases. It uses environment variables for the NuGet directory and the latest versions of GitHub Actions for checkout, setup-dotnet, and upload-artifact. The pipeline installs .NET version 8.0.x to ensure compatibility with all targeted frameworks. Additionally, it includes a step to delete existing tags if they already exist before creating a new release to avoid the 'Validation Failed: already_exists' error. The step now handles the case where the tag deletion fails and ensures the deletion step successfully removes the existing tag before proceeding to create a new release. + +## Requirements + +- .NET 8.0 SDK + +## Setup and Run + +1. **Install .NET 8.0 SDK**: Download and install the .NET 8.0 SDK from the official [.NET website](https://dotnet.microsoft.com/download/dotnet/8.0). + +2. **Restore Dependencies**: Open a terminal or command prompt in the project directory and run: + ```sh + dotnet restore + ``` + +3. **Build the Project**: Build the project by running: + ```sh + dotnet build + ``` + +4. **Run Tests**: Run the tests to ensure everything is working correctly: + ```sh + dotnet test + ```