Skip to content

Incluindo badges de status do projeto (build / release / size) #32

Incluindo badges de status do projeto (build / release / size)

Incluindo badges de status do projeto (build / release / size) #32

name: Build and Publish NuGet Package
on:
push:
branches:
- main
tags:
- 'v*.*.*'
- 'v*.*.*-*'
permissions:
contents: write
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:
- run: git config --global advice.detachedHead false
# 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-Host "Building only. Using default Version: 1.0.0"
echo "VERSION=1.0.0" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8
} else {
$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@v2
# Setup NuGet PKG Cache
- name: Setup NuGet Packages Cache
uses: actions/cache@v4
id: nuget-cache
with:
path: ${{ env.NUGET_PACKAGES }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**\packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
# Restore NuGet packages
- name: Restore NuGet packages
if: steps.nuget-cache.outputs.cache-hit != 'true'
run: nuget restore "${{ env.SOLUTION_FILE }}"
# Update Assembly and Package Version
- name: Update version info
if: startsWith(github.ref, 'refs/tags/v')
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 }} /p:ContinuousIntegrationBuild=true /p:RestoreLockedMode=true
# Pack the NuGet package
- name: Pack NuGet package
if: startsWith(github.ref, 'refs/tags/v')
run: nuget pack "${{ env.CSPROJECT_FILE }}" -Prop Configuration=Release -Prop Version=${{ env.VERSION }} -OutputDirectory artifacts
# Configure GitHub Packages repository
- name: Setup GitHub Packages repository
if: startsWith(github.ref, 'refs/tags/v')
run: nuget sources Add -Name github -Source "https://nuget.pkg.github.com/fastchannel/index.json" -UserName fastchannel -Password ${{ secrets.FASTCHANNEL_GITHUB_PAT }} -StorePasswordInClearText
# Publish packages to GitHub Packages
- name: Publish packages to GitHub Packages
if: startsWith(github.ref, 'refs/tags/v')
working-directory: ./artifacts
run: nuget push *.nupkg -Source "github" -ApiKey ${{ secrets.FASTCHANNEL_GITHUB_PAT }} -SkipDuplicate
# Upload both NuGet package and symbols as workflow artifacts
- name: Upload NuGet Packages as Artifacts
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: NuGetPackages
path: artifacts/*.nupkg
if-no-files-found: error
compression-level: 0
# Create a GitHub release
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
id: create_release
uses: softprops/action-gh-release@v2
with:
name: PagSeguro SDK ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
files: artifacts/*.nupkg
body: |
This release contains the latest build of the PagSeguro SDK for the .NET Framework 4.8 class library.
draft: false
prerelease: false
make_latest: true
generate_release_notes: true