Skip to content

Deploying package to nuget #49

Deploying package to nuget

Deploying package to nuget #49

name: CleanArchitecture.Blazored.Deploy
run-name: Deploying package to nuget
on:
workflow_dispatch:
push:
branches: [ "main" ]
release:
types:
- published
env:
NuGetDirectory: ${{github.workspace }}/nuget
jobs:
create_nuget:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .Net
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.x
- name: Restore dependencies
run: dotnet restore src/CleanArchitecture.Blazored.csproj
- name: Build Project
run: dotnet build --no-restore src/CleanArchitecture.Blazored.csproj -c Release
- name: Get latest release tag
id: get_tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "REPOSITORY_NAME=${{ github.repository }}"
tag=$(curl -s \
"https://api.github.com/repos/${{ github.repository }}/releases/latest" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ env.GH_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
| jq -r '.tag_name')
echo "Tag=$tag"
echo "::set-output name=tag::$tag"
- name: Ensure Release Tag
if: steps.get_tag.outputs.tag == null || steps.get_tag.outputs.tag == ''
run: exit 1
- name: Prepare Version tag
id: prep_version
run: |
export test_version=$(echo ${{ steps.get_tag.outputs.tag }} | sed -E 's/^[^0-9\.]*([0-9\.].*)$/\1/')
echo "Prep Tag=$test_version"
echo ::set-output name=version::$test_version
- name: Ensure Version
if: steps.prep_version.outputs.version == null || steps.prep_version.outputs.version == ''
run: exit 1
- name: Pack Nuget package
run: dotnet pack src/CleanArchitecture.Blazored.csproj /p:PackageVersionNumber=${{ steps.prep_version.outputs.version }} --configuration Release --output ${{ env.NuGetDirectory }}
- uses: actions/upload-artifact@v3
if: github.event_name =='release'
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg
deploy:
if: github.event_name =='release'
runs-on: ubuntu-latest
needs:
- create_nuget
steps:
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Setup .NET
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.x
- name: Publish Nuget package
run: |
cd ${{ env.NuGetDirectory }}
for file in *.nupkg; do
dotnet nuget push "$file" --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
done