.github/workflows/build.yaml #18
This file contains hidden or 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
| on: workflow_dispatch | |
| jobs: | |
| extract-version: | |
| name: 'Extract version' | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 0 | |
| - name: 'Extract turnierplan.NET version' | |
| id: extract-version | |
| shell: pwsh | |
| run: | | |
| $LatestTag = git describe --tags --abbrev=0 --match=[0-9]*.[0-9]*.[0-9]* | |
| $VersionXmlContent = Get-Content -Path "version.xml" -Raw | |
| $Version = [regex]::Match($VersionXmlContent, '<Version>(\d+\.\d+\.\d+)</Version>').Groups[1].Value | |
| Write-Host "Last git tag: $LatestTag" | |
| Write-Host "Detected version: $Version" | |
| if ($Version -eq $LatestTag) { | |
| Write-Host "Version equals latest tag, failing workflow!" | |
| exit 1 | |
| } | |
| Add-Content -Path $env:GITHUB_OUTPUT -Value "turnierplan_version=$Version" | |
| working-directory: './src' | |
| outputs: | |
| turnierplan_version: ${{ steps.extract-version.outputs.turnierplan_version }} | |
| container-image: | |
| name: 'Build container image' | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| packages: write | |
| needs: | |
| - extract-version | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: 'Replace environment tokens' | |
| uses: cschleiden/replace-tokens@v1 | |
| with: | |
| files: '["**/environment.prod.ts"]' | |
| env: | |
| TOKEN_APPLICATION_VERSION: "${{ needs.extract-version.outputs.turnierplan_version }}" | |
| - name: Login to container registry | |
| uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 'Build and push container image' | |
| uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | |
| with: | |
| context: ./src | |
| file: ./src/Turnierplan.App/Dockerfile | |
| push: true | |
| tags: 'ghcr.io/turnierplan-net/turnierplan:latest,ghcr.io/turnierplan-net/turnierplan:${{ needs.extract-version.outputs.turnierplan_version }}' | |
| nuget-package: | |
| name: 'Build NuGet package' | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - extract-version | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: 'Setup .NET SDK 9.x' | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: '9.x' | |
| - name: 'Restore .NET solution' | |
| run: 'dotnet restore' | |
| working-directory: './src' | |
| - name: 'Pack Turnierplan.Adapter' | |
| run: 'dotnet pack Turnierplan.Adapter/Turnierplan.Adapter.csproj -c Release -o .' | |
| working-directory: './src' | |
| - name: 'Push to NuGet' | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| run: 'dotnet nuget push ./*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate' | |
| working-directory: './src' |