Skip to content

SystemTextJson.Migration #3

SystemTextJson.Migration

SystemTextJson.Migration #3

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: egil-systemtextjson-migration
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'release/egil-systemtextjson-migration/v*'
pull_request:
branches:
- 'main'
concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
TestResultsDirectory: ${{ github.workspace}}/TestResults
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
Project: Egil.SystemTextJson.Migration
permissions:
contents: read
jobs:
create-nuget:
runs-on: ubuntu-latest
if: github.event.inputs.prepare-release != 'true'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- run: |
dotnet build ./Egil.SystemTextJson.Migration/src/Egil.SystemTextJson.Migration/Egil.SystemTextJson.Migration.csproj -c Release -f net10.0
dotnet pack ./Egil.SystemTextJson.Migration/src/Egil.SystemTextJson.Migration/Egil.SystemTextJson.Migration.csproj -c Release --no-build --output ${{ env.NuGetDirectory }}
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg
validate-nuget:
runs-on: ubuntu-latest
if: github.event.inputs.prepare-release != 'true'
needs: [ create-nuget ]
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Install nuget validator
run: dotnet tool restore
- name: Validate package
shell: pwsh
run: dotnet meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg") --excluded-rules IconMustBeSet
run-test:
runs-on: ubuntu-latest
if: github.event.inputs.prepare-release != 'true'
timeout-minutes: 30
env:
TestResultsDirectory: ${{ github.workspace }}/TestResults
permissions:
contents: read
checks: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- name: Run tests
run: dotnet test ./Egil.SystemTextJson.Migration/Egil.SystemTextJson.Migration.slnx --configuration Release
release:
needs: [validate-nuget, run-test]
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/heads/release/egil-systemtextjson-migration/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x
- name: Publish NuGet package
shell: pwsh
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure GIT
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Add git tag using dotnet nbgv
run: |
cd ${{ env.Project }}
dotnet tool restore
dotnet nbgv tag
git push origin --tags
- name: Delete release branch on origin
if: startsWith(github.ref, 'refs/heads/release/egil-systemtextjson-migration/v')
run: git push origin --delete "${{ env.BRANCH_NAME }}"