From 07374c11a750488caae2e2bfa8ab61c4bbd029da Mon Sep 17 00:00:00 2001 From: Hootan Hemmati Date: Thu, 12 Sep 2024 16:09:49 +0330 Subject: [PATCH 1/5] Fix the CI name to CI and ensure CD runs on pull request Update the CD workflow to run on pull requests and ensure the deploy job runs only on push to the master branch. * Add `pull_request` trigger to the `on` section in `.github/workflows/CD.yml` to run the CD workflow on pull requests. * Ensure the `deploy` job in `.github/workflows/CD.yml` runs only when a commit is pushed to the `master` branch. --- .github/workflows/CD.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index beef9f3..dc063c6 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 From c0f3f4813b1bf93c00b2ca1c3f8a8571e7939114 Mon Sep 17 00:00:00 2001 From: Hootan Hemmati Date: Thu, 12 Sep 2024 16:14:57 +0330 Subject: [PATCH 2/5] Update CI pipeline section in README.md to reflect new filename `CI.yml` * Change CI badge links in the Persian Date Public Version table to use `CI.yml` * Update CI pipeline description to reference `.github/workflows/CI.yml` instead of `.github/workflows/CD.yml` --- .github/workflows/{ci.yml => CI.yml} | 0 README.md | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{ci.yml => CI.yml} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/CI.yml similarity index 100% rename from .github/workflows/ci.yml rename to .github/workflows/CI.yml diff --git a/README.md b/README.md index ae7497c..044d514 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,7 +81,7 @@ 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 From 6a67b902c6f691fcae8cf548baae32103096fe0e Mon Sep 17 00:00:00 2001 From: Hootan Hemmati Date: Thu, 12 Sep 2024 16:20:27 +0330 Subject: [PATCH 3/5] Improve readme file and add how to setup and run project and the requirements Add setup and run instructions to `README.md`. * **Requirements**: Add a section mentioning the .NET 8.0 SDK requirement. * **Setup and Run**: Add a section with steps to install .NET 8.0 SDK, restore dependencies, build the project, and run tests. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 044d514..3e73f8b 100644 --- a/README.md +++ b/README.md @@ -86,3 +86,26 @@ The CI pipeline is now integrated into the CD pipeline and is defined in `.githu ## 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 + ``` From f6ba3bfc9c0d5f2c587491e1ac735ec076ccf4e8 Mon Sep 17 00:00:00 2001 From: Hootan Hemmati Date: Thu, 12 Sep 2024 16:22:47 +0330 Subject: [PATCH 4/5] Update CI.yml --- .github/workflows/CI.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.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: From 550734b559dcdff01d348d70a2f6187699dcec60 Mon Sep 17 00:00:00 2001 From: Hootan Hemmati Date: Thu, 12 Sep 2024 16:27:16 +0330 Subject: [PATCH 5/5] Add GitHub Packages support Add GitHub Packages registry configuration and update CD pipeline to publish package to GitHub Packages. * **PersianDate/PersianDate.csproj** - Update `` to `https://github.com/hootanht/PersianDate`. - Change `` to `https://nuget.pkg.github.com/hootanht/index.json`. * **.github/workflows/CD.yml** - Add step to authenticate with GitHub Packages using the `GITHUB_TOKEN` secret. - Add step to publish NuGet package to GitHub Packages. - Rename existing step to publish NuGet package to NuGet.org. --- .github/workflows/CD.yml | 13 ++++++++++++- PersianDate/PersianDate.csproj | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index dc063c6..3a25c83 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -88,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/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