|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_prefix: |
| 7 | + description: 'Version prefix (e.g., 1.2). Leave empty to auto-increment patch version.' |
| 8 | + required: false |
| 9 | + default: '' |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + runs-on: windows-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Setup .NET |
| 21 | + uses: actions/setup-dotnet@v4 |
| 22 | + with: |
| 23 | + dotnet-version: '10.0.x' |
| 24 | + |
| 25 | + - name: Determine Version |
| 26 | + id: version |
| 27 | + shell: pwsh |
| 28 | + run: | |
| 29 | + # Get all existing tags |
| 30 | + $tags = git tag -l "v*" | Sort-Object { [version]($_ -replace '^v', '') } -Descending |
| 31 | + |
| 32 | + if ($tags) { |
| 33 | + $latestTag = $tags[0] |
| 34 | + $latestVersion = [version]($latestTag -replace '^v', '') |
| 35 | + Write-Host "Latest tag: $latestTag (version: $latestVersion)" |
| 36 | + } else { |
| 37 | + $latestVersion = [version]"1.2.0" |
| 38 | + Write-Host "No existing tags found, starting from 1.2.0" |
| 39 | + } |
| 40 | + |
| 41 | + # Determine new version |
| 42 | + if ("${{ github.event.inputs.version_prefix }}" -ne "") { |
| 43 | + # Manual version prefix provided (e.g., "1.3") |
| 44 | + $newPrefix = "${{ github.event.inputs.version_prefix }}" |
| 45 | + $newVersion = [version]"$newPrefix.0" |
| 46 | + |
| 47 | + # If the same prefix already exists, increment patch |
| 48 | + if ($latestVersion.Major -eq $newVersion.Major -and $latestVersion.Minor -eq $newVersion.Minor) { |
| 49 | + $newVersion = [version]"$newPrefix.$($latestVersion.Build + 1)" |
| 50 | + } |
| 51 | + } else { |
| 52 | + # Auto-increment patch version |
| 53 | + $newVersion = [version]"$($latestVersion.Major).$($latestVersion.Minor).$($latestVersion.Build + 1)" |
| 54 | + } |
| 55 | + |
| 56 | + $versionTag = "v$newVersion" |
| 57 | + Write-Host "New version: $newVersion" |
| 58 | + Write-Host "version=$newVersion" >> $env:GITHUB_OUTPUT |
| 59 | + Write-Host "version_tag=$versionTag" >> $env:GITHUB_OUTPUT |
| 60 | + |
| 61 | + - name: Restore dependencies |
| 62 | + run: dotnet restore |
| 63 | + |
| 64 | + - name: Build Release |
| 65 | + run: dotnet build --configuration Release --no-restore -p:Version=${{ steps.version.outputs.version }} |
| 66 | + |
| 67 | + - name: Publish Executable |
| 68 | + run: dotnet publish Karpach.RemoteShutdown.Controller/Karpach.RemoteShutdown.Controller.csproj --configuration Release --output ./publish -p:Version=${{ steps.version.outputs.version }} |
| 69 | + |
| 70 | + - name: Create Source Archive |
| 71 | + shell: pwsh |
| 72 | + run: | |
| 73 | + # Create source code archive (exclude .git, bin, obj, .vs, etc.) |
| 74 | + $excludePatterns = @('.git', '.github', 'bin', 'obj', '.vs', '.vscode', '*.user', 'packages', '.nuget') |
| 75 | + |
| 76 | + $sourceDir = "." |
| 77 | + $archiveName = "SourceCode-${{ steps.version.outputs.version }}.zip" |
| 78 | + |
| 79 | + # Create temporary file list |
| 80 | + $tempFileList = New-TemporaryFile |
| 81 | + Get-ChildItem -Path $sourceDir -Recurse -File | |
| 82 | + Where-Object { |
| 83 | + $file = $_ |
| 84 | + $excluded = $false |
| 85 | + foreach ($pattern in $excludePatterns) { |
| 86 | + if ($file.FullName -like "*$pattern*") { |
| 87 | + $excluded = $true |
| 88 | + break |
| 89 | + } |
| 90 | + } |
| 91 | + -not $excluded |
| 92 | + } | |
| 93 | + ForEach-Object { $_.FullName -replace [regex]::Escape("$sourceDir\"), "" } | |
| 94 | + Out-File -FilePath $tempFileList -Encoding UTF8 |
| 95 | + |
| 96 | + # Create archive |
| 97 | + 7z a -w $sourceDir $archiveName @$tempFileList |
| 98 | + |
| 99 | + Remove-Item $tempFileList |
| 100 | + Write-Host "Created source archive: $archiveName" |
| 101 | + |
| 102 | + - name: Create Executable Archive |
| 103 | + shell: pwsh |
| 104 | + run: | |
| 105 | + $publishDir = "publish" |
| 106 | + $archiveName = "remote-shutdown-pc-${{ steps.version.outputs.version }}.zip" |
| 107 | + |
| 108 | + # Create archive with published files |
| 109 | + 7z a $archiveName "$publishDir\*" |
| 110 | + Write-Host "Created executable archive: $archiveName" |
| 111 | + |
| 112 | + - name: Create Git Tag |
| 113 | + run: | |
| 114 | + git config user.name "GitHub Actions" |
| 115 | + git config user.email "actions@github.com" |
| 116 | + git tag -a ${{ steps.version.outputs.version_tag }} -m "Release version ${{ steps.version.outputs.version }}" |
| 117 | + git push origin ${{ steps.version.outputs.version_tag }} |
| 118 | + |
| 119 | + - name: Create Release |
| 120 | + uses: softprops/action-gh-release@v1 |
| 121 | + with: |
| 122 | + tag_name: ${{ steps.version.outputs.version_tag }} |
| 123 | + name: Release ${{ steps.version.outputs.version }} |
| 124 | + draft: false |
| 125 | + prerelease: false |
| 126 | + files: | |
| 127 | + SourceCode-${{ steps.version.outputs.version }}.zip |
| 128 | + remote-shutdown-pc-${{ steps.version.outputs.version }}.zip |
| 129 | + env: |
| 130 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments