|
| 1 | +name: Build & Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version to publish (e.g. 1.0.0)" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | + push: |
| 12 | + tags: |
| 13 | + - "v*.*.*" |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: Build Windows Binary |
| 21 | + runs-on: windows-latest # WindowsDesktop.App.WindowsForms requires Windows |
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + |
| 25 | + env: |
| 26 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 27 | + DOTNET_NOLOGO: true |
| 28 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository (with full history) |
| 32 | + uses: actions/checkout@v6 |
| 33 | + with: |
| 34 | + fetch-depth: 0 # Full history needed for changelog |
| 35 | + submodules: recursive |
| 36 | + |
| 37 | + - name: Setup .NET SDK |
| 38 | + uses: actions/setup-dotnet@v5 |
| 39 | + with: |
| 40 | + dotnet-version: "10.0.x" |
| 41 | + cache: true |
| 42 | + cache-dependency-path: "**/ghb.csproj" |
| 43 | + |
| 44 | + - name: Determine version (manual dispatch) |
| 45 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + TAG="v${{ github.event.inputs.version }}" |
| 49 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 50 | + echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Determine version (tag push) |
| 53 | + if: ${{ github.event_name == 'push' }} |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + TAG="${{ github.ref_name }}" |
| 57 | + VERSION="${TAG#v}" |
| 58 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 59 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 60 | +
|
| 61 | + - name: Restore dependencies |
| 62 | + run: dotnet restore --no-cache |
| 63 | + |
| 64 | + - name: Build solution |
| 65 | + run: dotnet build -c Release --no-restore --no-incremental |
| 66 | + |
| 67 | + - name: Publish self-contained executable |
| 68 | + run: | |
| 69 | + dotnet publish ghb/ghb.csproj -c Release ` |
| 70 | + --self-contained true ` |
| 71 | + -r win-x64 ` |
| 72 | + -p:PublishSingleFile=true ` |
| 73 | + -p:IncludeNativeLibrariesForSelfExtract=true |
| 74 | +
|
| 75 | + - name: Generate changelog |
| 76 | + id: changelog |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + # Get the previous tag for comparison |
| 80 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") |
| 81 | +
|
| 82 | + if [ -z "$PREV_TAG" ]; then |
| 83 | + # First release - get all commits |
| 84 | + echo "## What's Changed" > CHANGELOG.md |
| 85 | + echo "" >> CHANGELOG.md |
| 86 | + git log --pretty=format:"* %s by @%an in %h" --no-merges >> CHANGELOG.md |
| 87 | + else |
| 88 | + # Get commits since previous tag |
| 89 | + echo "## What's Changed" > CHANGELOG.md |
| 90 | + echo "" >> CHANGELOG.md |
| 91 | + echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${{ env.TAG }}" >> CHANGELOG.md |
| 92 | + echo "" >> CHANGELOG.md |
| 93 | + echo "### Commits" >> CHANGELOG.md |
| 94 | + echo "" >> CHANGELOG.md |
| 95 | + git log ${PREV_TAG}..HEAD --pretty=format:"* %s by @%an in %h" --no-merges >> CHANGELOG.md |
| 96 | + fi |
| 97 | +
|
| 98 | + echo "" >> CHANGELOG.md |
| 99 | + echo "### SHA256 Checksums" >> CHANGELOG.md |
| 100 | + echo "\`\`\`" >> CHANGELOG.md |
| 101 | +
|
| 102 | + # Show the changelog for debugging |
| 103 | + cat CHANGELOG.md |
| 104 | +
|
| 105 | + - name: Create release artifacts |
| 106 | + shell: powershell |
| 107 | + run: | |
| 108 | + New-Item -ItemType Directory -Force -Path "dist" |
| 109 | +
|
| 110 | + # 1. Framework-dependent build (from bin folder) |
| 111 | + $binPath = Resolve-Path "./bin" |
| 112 | + $frameworkZip = "dist/ghb-${{ env.VERSION }}-framework-dependent.zip" |
| 113 | + Compress-Archive -Path "$binPath\*" -DestinationPath $frameworkZip -Force |
| 114 | + Write-Host "Created framework-dependent zip: $frameworkZip" |
| 115 | +
|
| 116 | + # 2. Self-contained single-file executable (from publish folder) |
| 117 | + $sourceExe = "./publish/ghb.exe" |
| 118 | + $destExe = "dist/ghb-${{ env.VERSION }}-win-x64.exe" |
| 119 | + if (Test-Path $sourceExe) { |
| 120 | + Copy-Item $sourceExe $destExe |
| 121 | + Write-Host "Copied self-contained executable: $destExe" |
| 122 | + } else { |
| 123 | + Write-Error "Publish output not found at $sourceExe" |
| 124 | + exit 1 |
| 125 | + } |
| 126 | +
|
| 127 | + # 3. Also zip the self-contained executable for convenience |
| 128 | + $selfContainedZip = "dist/ghb-${{ env.VERSION }}-win-x64-self-contained.zip" |
| 129 | + Compress-Archive -Path $destExe -DestinationPath $selfContainedZip -Force |
| 130 | + Write-Host "Created self-contained zip: $selfContainedZip" |
| 131 | +
|
| 132 | + # List artifacts |
| 133 | + Get-ChildItem dist/ |
| 134 | +
|
| 135 | + - name: Generate checksums |
| 136 | + shell: bash |
| 137 | + run: | |
| 138 | + cd dist |
| 139 | + sha256sum *.exe *.zip > checksums.txt |
| 140 | + cat checksums.txt |
| 141 | + cd .. |
| 142 | + cat dist/checksums.txt >> CHANGELOG.md |
| 143 | + echo "\`\`\`" >> CHANGELOG.md |
| 144 | +
|
| 145 | + - name: Upload artifacts |
| 146 | + uses: actions/upload-artifact@v4 |
| 147 | + with: |
| 148 | + name: ghb-${{ env.VERSION }} |
| 149 | + path: dist/ |
| 150 | + retention-days: 30 |
| 151 | + |
| 152 | + - name: Create GitHub Release |
| 153 | + uses: softprops/action-gh-release@v2 |
| 154 | + with: |
| 155 | + tag_name: ${{ env.TAG }} |
| 156 | + name: "ghb ${{ env.VERSION }}" |
| 157 | + body_path: CHANGELOG.md |
| 158 | + draft: false |
| 159 | + prerelease: ${{ contains(env.TAG, '-') || contains(env.TAG, 'alpha') || contains(env.TAG, 'beta') || contains(env.TAG, 'rc') }} |
| 160 | + files: | |
| 161 | + dist/* |
| 162 | + env: |
| 163 | + GITHUB_TOKEN: ${{ github.token }} |
0 commit comments