Skip to content

Testando com o Workflow com um PAT invés do GITHUB_TOKEN #18

Testando com o Workflow com um PAT invés do GITHUB_TOKEN

Testando com o Workflow com um PAT invés do GITHUB_TOKEN #18

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)
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 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-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@v2
# 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
# Configure GitHub Packages repository
- name: Setup GitHub Packages repository
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
shell: pwsh
run: |
$files = Get-ChildItem -Path artifacts -Filter *.nupkg
if ($files.Count -eq 0) {
Write-Error "No .nupkg files found in the artifacts directory."
exit 1
}
foreach ($file in $files) {
Write-Host "Publishing $file.FullName"
nuget push $file.FullName -Source "github" -ApiKey ${{ secrets.FASTCHANNEL_GITHUB_PAT }} -SkipDuplicate
}
# Upload both NuGet package and symbols as workflow artifacts
- name: Upload NuGet packages as Artifacts
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
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