From 657e2041190b3ea0c5798d819bf55acab8bc3124 Mon Sep 17 00:00:00 2001 From: Qiao Wang Date: Wed, 7 Feb 2024 20:34:04 +0800 Subject: [PATCH] Add github action to release nuget package --- .github/workflows/cli-release.yml | 35 ++++++++++++++++++++ build/extract_version | 6 ++++ src/PwSafeClient.CLI/PwSafeClient.CLI.csproj | 1 - 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cli-release.yml create mode 100644 build/extract_version diff --git a/.github/workflows/cli-release.yml b/.github/workflows/cli-release.yml new file mode 100644 index 0000000..69c27e7 --- /dev/null +++ b/.github/workflows/cli-release.yml @@ -0,0 +1,35 @@ +name: Release .NET Tool + +on: + push: + tags: + "cli-v[0-9]+.[0-9]+.[0-9]+" + +defaults: + run: + working-directory: src/PwSafeClient.CLI + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Extract Version + if: ${{ github.ref_type == 'tag' }} + run: | + version=$(./build/extract_version "${GITHUB_REF#refs/tags/}") + echo "VERSION=$version" >> $GITHUB_ENV + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore /p:Version=$VERSION + - name: Pack + run: dotnet pack --no-restore --no-build /p:PackageVersion=$VERSION + - name: Upload + if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/cli-v') + run: dotnet nuget push nupkg/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json diff --git a/build/extract_version b/build/extract_version new file mode 100644 index 0000000..09d3cb1 --- /dev/null +++ b/build/extract_version @@ -0,0 +1,6 @@ +#!/bin/bash + +# Use sed to extract version pattern +version=$(echo "$1" | sed -E 's/^[^-]+-v?([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?)$/\1/') + +echo "$version" diff --git a/src/PwSafeClient.CLI/PwSafeClient.CLI.csproj b/src/PwSafeClient.CLI/PwSafeClient.CLI.csproj index 32c8098..54fd532 100644 --- a/src/PwSafeClient.CLI/PwSafeClient.CLI.csproj +++ b/src/PwSafeClient.CLI/PwSafeClient.CLI.csproj @@ -3,7 +3,6 @@ net8.0 Exe pwsafe - 1.0.0-beta enable