Mais uma correção na etapa de publicação #11
Workflow file for this run
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: Build and Publish NuGet Package | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger only when a tag starting with 'v' is pushed (e.g., v1.0.0) | |
jobs: | |
build-and-publish: | |
runs-on: windows-latest # Use Windows runner for .NET Framework compatibility | |
env: | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages | |
SOLUTION_FILE: ${{ github.workspace }}/source/PagSeguro.sln | |
CSPROJECT_FILE: ${{ github.workspace }}/source/Uol.PagSeguro/Fastchannel.Uol.PagSeguro.csproj | |
steps: | |
# Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# Extract version from tag using PowerShell | |
- name: Extract version from tag | |
id: get-version | |
shell: pwsh | |
run: | | |
$tag = $env:GITHUB_REF -replace 'refs/tags/', '' | |
if (-not $tag.StartsWith('v')) { | |
Write-Error "Version Tags must start with a 'v'. Current Tag: $tag" | |
exit 1 | |
} | |
$version = $tag.Substring(1) # Remove the leading 'v' | |
Write-Host "Extracted version: $version" | |
echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 | |
# Setup NuGet CLI | |
- name: Setup NuGet CLI | |
uses: nuget/setup-nuget@v2 | |
# Setup MSBuild | |
- name: Setup MSBuild | |
uses: microsoft/setup-msbuild@v1 | |
# Restore NuGet packages | |
- name: Restore NuGet packages | |
run: nuget restore "${{ env.SOLUTION_FILE }}" | |
# Update Assembly and Package Version | |
- name: Update version info | |
run: | | |
$version = "${{ env.VERSION }}" | |
Write-Host "Setting version to $version" | |
(Get-Content source/Uol.PagSeguro/Properties/AssemblyInfo.cs).replace('AssemblyVersion("1.0.0.0")', "AssemblyVersion(`"$version.0`")") | Set-Content source/Uol.PagSeguro/Properties/AssemblyInfo.cs | |
(Get-Content source/Uol.PagSeguro/Properties/AssemblyInfo.cs).replace('AssemblyFileVersion("1.0.0.0")', "AssemblyFileVersion(`"$version.0`")") | Set-Content source/Uol.PagSeguro/Properties/AssemblyInfo.cs | |
# Build the project using MSBuild | |
- name: Build with MSBuild | |
run: msbuild "${{ env.SOLUTION_FILE }}" /p:Configuration=Release /p:Platform=x86 /p:Version=${{ env.VERSION }} | |
# Pack the NuGet package | |
- name: Pack NuGet package | |
run: nuget pack "${{ env.CSPROJECT_FILE }}" -Prop Configuration=Release -Prop Version=${{ env.VERSION }} -Symbols -OutputDirectory artifacts | |
# Upload both NuGet package and symbols as workflow artifacts | |
- name: Upload NuGet packages as artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nuget-packages | |
path: artifacts/*.nupkg | |
# Publish the main NuGet package | |
- name: Publish to NuGet.org | |
env: | |
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
run: | | |
for %f in (artifacts\*.nupkg) do nuget push "%f" -Source "https://api.nuget.org/v3/index.json" -ApiKey $NUGET_API_KEY -SkipDuplicate | |
# Create a GitHub release | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: Release ${{ github.ref_name }} | |
body: | | |
This release contains the latest build of the NuGet package for the .NET Framework 4.8 class library. | |
draft: false | |
prerelease: false | |
# Attach NuGet package and symbols to GitHub release | |
- name: Attach NuGet package and symbols to release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: artifacts/*.nupkg | |
asset_name: ${{ env.VERSION }}-symbols.nupkg | |
asset_content_type: application/zip |