Skip to content

Tag [v0.4.7] β†’ Create Package #21

Tag [v0.4.7] β†’ Create Package

Tag [v0.4.7] β†’ Create Package #21

# Creation of a version tag will trigger this workflow
# A new release will be created from the tag
---
name: Tag β†’ Create Package
run-name: Tag [${{ github.ref_name }}] β†’ Create Package
on:
push:
tags:
- v**
jobs:
package:
name: Create Package [${{ github.ref_name }}]
runs-on: windows-2022
permissions:
contents: write # Needed for pushing commits and tags
packages: write # Needed for pushing packages to GitHub Packages
steps:
- name: Checkout [${{ github.ref_name }}]
uses: actions/checkout@v4
with:
token: ${{ secrets.TJC_TOKEN || secrets.GITHUB_TOKEN }}
submodules: recursive
fetch-depth: 0
- name: Add GitHub NuGet Source
run: dotnet nuget add source --username "${{ github.repository_owner }}" --password ${{ secrets.TJC_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.*"
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: NuGet/setup-nuget@v2.0.1
- name: Restore NuGet
run: nuget restore ${{ github.event.repository.name }}/${{ github.event.repository.name }}.csproj
- name: Get Version without Prefix/Suffix
id: getVer
uses: actions/github-script@v7.0.1
with:
result-encoding: string
script: |
var tag = '${{ github.ref_name }}'
var simple = tag.replace('v','')
simple = simple.split('-')[0]
console.log('Version:', simple)
return simple
- name: Publish [${{ steps.getVer.outputs.result }}]
run: dotnet publish ${{ github.event.repository.name }}/${{ github.event.repository.name }}.csproj -c Release
- name: Pack NuGet Package [${{ steps.getVer.outputs.result }}]
run: dotnet pack ${{ github.event.repository.name }}/${{ github.event.repository.name }}.csproj -p:Version='${{ steps.getVer.outputs.result }}' -c Release
- name: List Files (Release)
run: ls ${{ github.event.repository.name }}/bin/Release
- name: List Files (net8.0)
run: ls ${{ github.event.repository.name }}/bin/Release/net8.0
- name: List Files (publish)
run: ls ${{ github.event.repository.name }}/bin/Release/net8.0/publish
- name: Push Package to NuGet & GitHub Packages
shell: powershell
run: |
$files = gci -File "${{ github.event.repository.name }}/bin/Release/*.nupkg"
foreach ($file in $files)
{
echo "Pushing NuGet Package: $file"
dotnet nuget push "$file" --api-key ${{ secrets.TJC_NUGET_PUBLISH }} --source https://api.nuget.org/v3/index.json
dotnet nuget push "$file" --api-key ${{ secrets.TJC_TOKEN }} --source github
}
- name: Release [${{ github.ref_name }}]
uses: ncipollo/release-action@v1.14.0
with:
name: ${{ github.event.repository.name }} ${{ steps.getVer.outputs.result }}
tag: ${{ github.ref_name }}
artifacts: "${{ github.event.repository.name }}/bin/Release/*.nupkg,${{ github.event.repository.name }}/bin/Release/net8.0/publish/**.dll,${{ github.event.repository.name }}/bin/Release/net8.0/publish/**.pdb,${{ github.event.repository.name }}/bin/Release/net8.0/publish/**.xml"
generateReleaseNotes: true
- name: ${{ format('Published NuGet Package [{0}]', steps.getVer.outputs.result) }}
if: success()
uses: ./.github/actions/tools/annotation/notice
with:
message: ${{ format('Published NuGet Package [{0}]', steps.getVer.outputs.result) }}
- name: Error - Failed to Publish NuGet Package
if: failure()
uses: ./.github/actions/tools/annotation/error
with:
message: "[Error] Failed to Publish NuGet Package"