|
| 1 | +name: CI Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: windows-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + submodules: recursive |
| 20 | + |
| 21 | + - name: Calculate version |
| 22 | + id: version |
| 23 | + shell: pwsh |
| 24 | + env: |
| 25 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + run: | |
| 27 | + $year = (Get-Date).Year |
| 28 | + $month = (Get-Date).Month |
| 29 | + $startOfMonth = (Get-Date -Day 1 -Hour 0 -Minute 0 -Second 0).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") |
| 30 | +
|
| 31 | + $headers = @{ |
| 32 | + Authorization = "Bearer $env:GITHUB_TOKEN" |
| 33 | + Accept = "application/vnd.github.v3+json" |
| 34 | + } |
| 35 | + $url = "https://api.github.com/repos/$env:GITHUB_REPOSITORY/actions/workflows/build.yml/runs?created=>=$startOfMonth&per_page=1" |
| 36 | + $response = Invoke-RestMethod -Uri $url -Headers $headers -ErrorAction Stop |
| 37 | + $rev = $response.total_count |
| 38 | +
|
| 39 | + $version = "1.$year.$month.$rev" |
| 40 | + "VERSION=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 41 | + Write-Host "Computed version: $version" |
| 42 | +
|
| 43 | + - name: Patch AssemblyInfo.cs |
| 44 | + shell: pwsh |
| 45 | + run: | |
| 46 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 47 | + $file = "XTB\Properties\AssemblyInfo.cs" |
| 48 | + (Get-Content $file) ` |
| 49 | + -replace 'AssemblyVersion\("[^"]*"\)', "AssemblyVersion(`"$version`")" ` |
| 50 | + -replace 'AssemblyFileVersion\("[^"]*"\)', "AssemblyFileVersion(`"$version`")" | |
| 51 | + Set-Content $file |
| 52 | + Write-Host "Patched $file to version $version" |
| 53 | +
|
| 54 | + - name: Patch nuspec versions |
| 55 | + shell: pwsh |
| 56 | + run: | |
| 57 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 58 | + $nuspecs = @( |
| 59 | + "XTB\ShuffleRunner.nuspec", |
| 60 | + "XTB\ShuffleBuilder.nuspec", |
| 61 | + "XTB\ShuffleDeployer.nuspec" |
| 62 | + ) |
| 63 | + foreach ($nuspec in $nuspecs) { |
| 64 | + $path = Resolve-Path $nuspec |
| 65 | + [xml]$xml = Get-Content $path |
| 66 | + $xml.package.metadata.version = $version |
| 67 | + $xml.Save($path) |
| 68 | + Write-Host "Patched $nuspec to version $version" |
| 69 | + } |
| 70 | +
|
| 71 | + - name: Setup NuGet |
| 72 | + uses: NuGet/setup-nuget@v2 |
| 73 | + |
| 74 | + - name: NuGet restore |
| 75 | + run: nuget restore Rappen.XTB.Shuffle.sln |
| 76 | + |
| 77 | + - name: Setup MSBuild |
| 78 | + uses: microsoft/setup-msbuild@v2 |
| 79 | + |
| 80 | + - name: Build solution |
| 81 | + run: msbuild Rappen.XTB.Shuffle.sln /p:Configuration=Release /p:Platform="Any CPU" /m |
| 82 | + |
| 83 | + - name: NuGet pack |
| 84 | + shell: pwsh |
| 85 | + run: | |
| 86 | + New-Item -ItemType Directory -Force -Path nupkg | Out-Null |
| 87 | + nuget pack "XTB\ShuffleRunner.nuspec" -OutputDirectory nupkg |
| 88 | + nuget pack "XTB\ShuffleBuilder.nuspec" -OutputDirectory nupkg |
| 89 | + nuget pack "XTB\ShuffleDeployer.nuspec" -OutputDirectory nupkg |
| 90 | +
|
| 91 | + - name: Upload nupkg artifacts |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: nupkg-${{ steps.version.outputs.VERSION }} |
| 95 | + path: nupkg/*.nupkg |
0 commit comments