Nuget Release YML updated to fix bug with name of file (#39) #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release NuGet Package | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'Directory.Build.props' | |
permissions: | |
contents: write # Ensure the token has write permissions to contents | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.204' | |
- name: Cache NuGet packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Build.Props') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- name: Verify version change | |
id: version | |
run: | | |
props_file="Directory.Build.Props" | |
version_line=$(grep '<Version>' $props_file) | |
new_version=$(echo $version_line | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/') | |
echo "New version: $new_version" | |
git fetch --tags | |
last_tag=$(git tag --sort=-creatordate | head -n 1) | |
echo "Last tag: $last_tag" | |
if [ "$new_version" == "${last_tag#v}" ]; then | |
echo "Version has not changed. Exiting." | |
exit 0 | |
fi | |
echo "Version has changed. Proceeding." | |
- name: Build project | |
run: dotnet build --configuration Release | |
- name: Pack NuGet package | |
run: dotnet pack --configuration Release --no-build --output ./nupkgs | |
- name: Publish NuGet package | |
env: | |
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
run: | | |
dotnet nuget push ./nupkgs/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json | |
- name: Create GitHub release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
new_version=$(grep '<Version>' Directory.Build.Props | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/') | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git tag v$new_version | |
git push origin v$new_version | |
curl -X POST \ | |
-H "Authorization: token $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases \ | |
-d '{ | |
"tag_name": "v'${new_version}'", | |
"target_commitish": "main", | |
"name": "v'${new_version}'", | |
"body": "Release of version '${new_version}'", | |
"draft": false, | |
"prerelease": false | |
}' |