Skip to content

Downgrade truncation warnings to infos as applications may intentiona… #92

Downgrade truncation warnings to infos as applications may intentiona…

Downgrade truncation warnings to infos as applications may intentiona… #92

name: CI and Release
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
branches:
- master
jobs:
build:
runs-on: windows-latest
outputs:
version: ${{ steps.version.outputs.VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Setup .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Determine version
id: version
shell: bash
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
TAG_NAME=${TAG_NAME#v}
VERSION="${TAG_NAME}.${GITHUB_RUN_NUMBER}"
else
VERSION="2.1.0.${GITHUB_RUN_NUMBER}"
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Building version $VERSION"
- name: Restore
run: dotnet restore CoreJ2K.sln
- name: Build
run: dotnet build CoreJ2K.sln -c Release --no-restore /p:Version=${{ steps.version.outputs.VERSION }}
- name: Test
run: dotnet test CoreJ2K.sln -c Release --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage"
- name: Pack
run: |
dotnet pack CoreJ2K.sln -c Release --no-build -o ./artifacts `
/p:Version=${{ steps.version.outputs.VERSION }} `
/p:PackageVersion=${{ steps.version.outputs.VERSION }} `
/p:IncludeSymbols=true `
/p:SymbolPackageFormat=snupkg
- name: Upload packages (artifact)
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: artifacts/*.nupkg
if-no-files-found: error
- name: Upload symbol packages (artifact)
uses: actions/upload-artifact@v4
with:
name: nuget-symbols
path: artifacts/*.snupkg
if-no-files-found: warn
publish:
needs: build
runs-on: windows-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
id-token: write # required for NuGet Trusted Publishing OIDC token
contents: write # required for GitHub release creation
steps:
- name: Download packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ./artifacts
- name: Download symbol packages
uses: actions/download-artifact@v4
with:
name: nuget-symbols
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: NuGet login
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ secrets.NUGET_USER }}
- name: Push to NuGet.org
shell: pwsh
run: |
$packages = Get-ChildItem ./artifacts/*.nupkg -ErrorAction SilentlyContinue
if ($packages.Count -eq 0) {
Write-Error "No packages found to publish!"
exit 1
}
foreach ($pkg in $packages) {
Write-Host "Publishing $($pkg.Name)..."
dotnet nuget push $pkg.FullName `
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate `
--no-symbols
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to push $($pkg.Name)"
exit 1
}
}
$symbols = Get-ChildItem ./artifacts/*.snupkg -ErrorAction SilentlyContinue
foreach ($sym in $symbols) {
Write-Host "Publishing symbols $($sym.Name)..."
dotnet nuget push $sym.FullName `
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate
}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ needs.build.outputs.version }}
body: |
## CoreJ2K Release ${{ needs.build.outputs.version }}
### Changes in this release
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md)
### Installation
```
dotnet add package CoreJ2K --version ${{ needs.build.outputs.version }}
```
### NuGet Packages
- [CoreJ2K on NuGet.org](https://www.nuget.org/packages/CoreJ2K/${{ needs.build.outputs.version }})
files: |
./artifacts/*.nupkg
./artifacts/*.snupkg
draft: false
prerelease: false
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Draft Release
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const draft = releases.data.find(r => r.draft && r.tag_name === context.ref.replace('refs/tags/', ''));
if (draft) {
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: draft.id,
draft: false
});
console.log(`Published draft release: ${draft.name}`);
}