Skip to content

Tag and publish to NuGet #27

Tag and publish to NuGet

Tag and publish to NuGet #27

name: Tag and publish to NuGet
on:
workflow_dispatch:
inputs:
major:
description: 'Major version'
required: true
default: '1'
minor:
description: 'Minor version'
required: true
default: '0'
patch:
description: 'Patch version'
required: true
default: '0'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release --no-restore
- name: Run tests with coverage
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage/ --settings coverage.runsettings
- name: Upload coverage to Codacy
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: |
COBERTURA_FILE=$(find . -name coverage.cobertura.xml)
if [ -z "$COBERTURA_FILE" ]; then
echo "Coverage report not found!"
exit 1
fi
echo "Found coverage file at: ${COBERTURA_FILE}"
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r $COBERTURA_FILE
- name: Get the latest tag
id: get_tag
run: echo "::set-output name=TAG::$(git describe --tags --abbrev=0)"
- name: Create new tag
id: create_tag
env:
MAJOR: "${{ github.event.inputs.major }}"
MINOR: "${{ github.event.inputs.minor }}"
PATCH: "${{ github.event.inputs.patch }}"
GITHUB_TOKEN: ${{ secrets.ASUREBUS_PAT }}
run: |
NEW_TAG="${MAJOR}.${MINOR}.${PATCH}"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
git tag "$NEW_TAG"
git push origin "$NEW_TAG"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ASUREBUS_PAT }}
with:
tag_name: ${{ env.NEW_TAG }}
release_name: "Release ${{ env.NEW_TAG }}"
draft: false
prerelease: false
- name: Pack ASureBus.Abstractions
run: dotnet pack ASureBus.Abstractions/ASureBus.Abstractions.csproj --configuration Release --output ./artifacts /p:PackageVersion=${{ env.NEW_TAG }}
- name: Pack ASureBus
run: dotnet pack ASureBus/ASureBus.csproj --configuration Release --output ./artifacts /p:PackageVersion=${{ env.NEW_TAG }}
- name: Push ASureBus.Abstractions to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./artifacts/ASureBus.Abstractions.*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Push ASureBus to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./artifacts/ASureBus.*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate