From 2cd9bcce498e73c97f243ea5109b16f0577a1b9f Mon Sep 17 00:00:00 2001 From: Saeed Esmaeelinejad Date: Sun, 29 Jan 2023 00:10:26 +0700 Subject: [PATCH 1/4] Create package.yml --- .github/workflows/package.yml | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/package.yml diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml new file mode 100644 index 0000000..a275302 --- /dev/null +++ b/.github/workflows/package.yml @@ -0,0 +1,84 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + outputs: + Version: ${{ steps.gitversion.outputs.SemVer }} + CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 #fetch-depth is needed for GitVersion + + #Install and calculate the new version with GitVersion + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0.9.7 + with: + versionSpec: 5.x + - name: Determine Version + uses: gittools/actions/gitversion/execute@v0.9.7 + id: gitversion # step id used as reference for output values + - name: Display GitVersion outputs + run: | + echo "Version: ${{ steps.gitversion.outputs.SemVer }}" + echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}" + + #Build/pack the project + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 6.0.x + 7.0.x + + - name: Build and Pack NuGet package + run: | + dotnet pack src/DotNet.RateLimiter/DotNet.RateLimiter.csproj -p:Version='${{ steps.gitversion.outputs.SemVer }}' -c Release + - name: Upload NuGet package to GitHub + uses: actions/upload-artifact@v2 + with: + name: nugetPackage + path: src/DotNet.RateLimiter/bin/Release/ + + release: + runs-on: ubuntu-latest + needs: build + if: github.ref == 'refs/heads/main' # only run job if on the main branch + + steps: + #Push NuGet package to GitHub packages + - name: Download nuget package artifact + uses: actions/download-artifact@v1.0.0 + with: + name: nugetPackage + - name: Prep packages + run: dotnet nuget add source --username sa-es-ir --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/sa-es-ir/index.json" + - name: Push package to GitHub packages + if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change + run: dotnet nuget push nugetPackage/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" + + #Create release + - name: Create Release + if: 1 == 0 #needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ needs.build.outputs.Version }} + release_name: Release ${{ needs.build.outputs.Version }} + - name: Create Release + if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change + uses: ncipollo/release-action@v1 + with: + tag: ${{ needs.build.outputs.Version }} + name: Release ${{ needs.build.outputs.Version }} + artifacts: "nugetPackage/*" + token: ${{ secrets.GITHUB_TOKEN }} From 9d77db79857b29bda9ac2a5986f94b370ee35195 Mon Sep 17 00:00:00 2001 From: Saeed Esmaeelinejad Date: Sun, 29 Jan 2023 00:20:37 +0700 Subject: [PATCH 2/4] Update package.yml --- .github/workflows/package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index a275302..4b18122 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -41,7 +41,7 @@ jobs: - name: Build and Pack NuGet package run: | - dotnet pack src/DotNet.RateLimiter/DotNet.RateLimiter.csproj -p:Version='${{ steps.gitversion.outputs.SemVer }}' -c Release + dotnet pack src/DotNet.RateLimiter/DotNet.RateLimiter.csproj -p:PackageVersion=${{ github.event.inputs.versionIncrement }} -c Release - name: Upload NuGet package to GitHub uses: actions/upload-artifact@v2 with: From f2cf5e84131a113a6bf6b94b3dea327778c789f5 Mon Sep 17 00:00:00 2001 From: Saeed Esmaeelinejad Date: Sun, 29 Jan 2023 00:27:02 +0700 Subject: [PATCH 3/4] Update package.yml --- .github/workflows/package.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 4b18122..b5d677c 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -1,10 +1,17 @@ name: CI on: - push: - branches: [ main ] - pull_request: - branches: [ main ] + workflow_dispatch: + inputs: + versionIncrement: + description: 'The new version. For example: 1.1.0' + required: true + default: '' + prerelease: + description: 'Is this a pre-release?' + type: boolean + required: false + default: false jobs: build: From f91c6368451f87e09efb6ecb9c0074780ca152a2 Mon Sep 17 00:00:00 2001 From: Saeed Esmaeelinejad Date: Sun, 29 Jan 2023 00:46:09 +0700 Subject: [PATCH 4/4] Update package.yml --- .github/workflows/package.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index b5d677c..5b8657e 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -73,19 +73,12 @@ jobs: run: dotnet nuget push nugetPackage/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" #Create release - - name: Create Release - if: 1 == 0 #needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: ${{ needs.build.outputs.Version }} - release_name: Release ${{ needs.build.outputs.Version }} - name: Create Release if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change uses: ncipollo/release-action@v1 with: - tag: ${{ needs.build.outputs.Version }} - name: Release ${{ needs.build.outputs.Version }} + tag: ${{ github.event.inputs.versionIncrement }} + tag_name: v${{ github.event.inputs.versionIncrement }} + name: Release ${{ github.event.inputs.versionIncrement }} artifacts: "nugetPackage/*" token: ${{ secrets.GITHUB_TOKEN }}