|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +env: |
| 10 | + PYTHON_VERSION: '3.14' |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - arch: x64 |
| 21 | + runner: windows-latest |
| 22 | + artifact_name: yasb-gui-x64 |
| 23 | + - arch: arm64 |
| 24 | + runner: windows-11-arm |
| 25 | + artifact_name: yasb-gui-aarch64 |
| 26 | + |
| 27 | + runs-on: ${{ matrix.runner }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout Repository |
| 31 | + uses: actions/checkout@v6 |
| 32 | + |
| 33 | + - name: Set up Python |
| 34 | + uses: actions/setup-python@v6 |
| 35 | + with: |
| 36 | + python-version: ${{ env.PYTHON_VERSION }} |
| 37 | + |
| 38 | + - name: Create virtual environment |
| 39 | + run: python -m venv venv |
| 40 | + shell: pwsh |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: | |
| 44 | + .\venv\Scripts\Activate |
| 45 | + pip install --upgrade pip |
| 46 | + pip install .[build] --no-cache |
| 47 | + shell: pwsh |
| 48 | + |
| 49 | + - name: Build EXE |
| 50 | + run: | |
| 51 | + .\venv\Scripts\Activate |
| 52 | + python app/scripts/build.py build |
| 53 | + shell: pwsh |
| 54 | + |
| 55 | + - name: Build MSI |
| 56 | + run: | |
| 57 | + .\venv\Scripts\Activate |
| 58 | + python app/scripts/build.py bdist_msi |
| 59 | + shell: pwsh |
| 60 | + |
| 61 | + - name: Upload MSI Artifact |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: ${{ matrix.artifact_name }} |
| 65 | + path: dist/out/*.msi |
| 66 | + |
| 67 | + release: |
| 68 | + needs: build |
| 69 | + runs-on: windows-latest |
| 70 | + permissions: |
| 71 | + contents: write |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Checkout Repository |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Download all artifacts |
| 80 | + uses: actions/download-artifact@v4 |
| 81 | + with: |
| 82 | + path: dist-msis |
| 83 | + pattern: yasb-gui-* |
| 84 | + merge-multiple: true |
| 85 | + |
| 86 | + - name: Get version |
| 87 | + id: version |
| 88 | + run: | |
| 89 | + $content = Get-Content -Path "app/core/constants.py" -Raw |
| 90 | + $version = [regex]::Match($content, 'APP_VERSION\s*=\s*"([^"]+)"').Groups[1].Value |
| 91 | + echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 92 | + echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append |
| 93 | + shell: pwsh |
| 94 | + |
| 95 | + - name: Generate Changelog |
| 96 | + id: changelog |
| 97 | + run: | |
| 98 | + $previousTag = git describe --tags --abbrev=0 2>$null |
| 99 | + if (-not $previousTag) { |
| 100 | + $previousTag = git rev-list --max-parents=0 HEAD |
| 101 | + } |
| 102 | + |
| 103 | + $commits = git log "$previousTag..HEAD" --pretty=format:"%h|%s|%an" --no-merges |
| 104 | + |
| 105 | + $repoUrl = "${{ github.server_url }}/${{ github.repository }}" |
| 106 | + |
| 107 | + $features = @() |
| 108 | + $fixes = @() |
| 109 | + $other = @() |
| 110 | + |
| 111 | + foreach ($commit in $commits -split "`n") { |
| 112 | + if (-not $commit) { continue } |
| 113 | + $parts = $commit -split '\|' |
| 114 | + $hash = $parts[0] |
| 115 | + $message = $parts[1] |
| 116 | + |
| 117 | + $entry = "- $message ([$hash]($repoUrl/commit/$hash))" |
| 118 | + |
| 119 | + if ($message -match "^feat|^add|^new") { |
| 120 | + $features += $entry |
| 121 | + } |
| 122 | + elseif ($message -match "^fix|^bug|^patch") { |
| 123 | + $fixes += $entry |
| 124 | + } |
| 125 | + else { |
| 126 | + $other += $entry |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + $changelog = "" |
| 131 | + |
| 132 | + if ($features.Count -gt 0) { |
| 133 | + $changelog += "### ✨ Features`n`n" |
| 134 | + $changelog += ($features -join "`n") + "`n`n" |
| 135 | + } |
| 136 | + |
| 137 | + if ($fixes.Count -gt 0) { |
| 138 | + $changelog += "### 🐛 Bug Fixes`n`n" |
| 139 | + $changelog += ($fixes -join "`n") + "`n`n" |
| 140 | + } |
| 141 | + |
| 142 | + if ($other.Count -gt 0) { |
| 143 | + $changelog += "### 📦 Other Changes`n`n" |
| 144 | + $changelog += ($other -join "`n") + "`n`n" |
| 145 | + } |
| 146 | + |
| 147 | + if (-not $changelog) { |
| 148 | + $changelog = "No significant changes in this release." |
| 149 | + } |
| 150 | + |
| 151 | + $changelog | Out-File -FilePath "CHANGELOG_BODY.md" -Encoding utf8 |
| 152 | + |
| 153 | + echo "Generated changelog:" |
| 154 | + echo $changelog |
| 155 | + shell: pwsh |
| 156 | + |
| 157 | + - name: Generate Checksum |
| 158 | + run: | |
| 159 | + $checksums = Get-FileHash dist-msis/*.msi -Algorithm SHA256 |
| 160 | + $output = @() |
| 161 | + foreach ($checksum in $checksums) { |
| 162 | + $filename = [System.IO.Path]::GetFileName($checksum.Path) |
| 163 | + $output += "$($checksum.Hash) $filename" |
| 164 | + } |
| 165 | + $output -join "`n" | Out-File -FilePath "dist-msis/checksums.txt" -Encoding utf8 |
| 166 | + |
| 167 | + echo "Checksums:" |
| 168 | + Get-Content "dist-msis/checksums.txt" |
| 169 | + shell: pwsh |
| 170 | + |
| 171 | + - name: Create Tag |
| 172 | + uses: actions/github-script@v7 |
| 173 | + env: |
| 174 | + VERSION: ${{ steps.version.outputs.VERSION }} |
| 175 | + with: |
| 176 | + script: | |
| 177 | + const version = `v${process.env.VERSION}`; |
| 178 | + const { owner, repo } = context.repo; |
| 179 | + const sha = context.sha; |
| 180 | + |
| 181 | + try { |
| 182 | + const { data: tags } = await github.rest.repos.listTags({ owner, repo }); |
| 183 | + const tagExists = tags.some(tag => tag.name === version); |
| 184 | + |
| 185 | + if (!tagExists) { |
| 186 | + console.log(`Creating tag ${version}`); |
| 187 | + await github.rest.git.createRef({ |
| 188 | + owner, |
| 189 | + repo, |
| 190 | + ref: `refs/tags/${version}`, |
| 191 | + sha, |
| 192 | + }); |
| 193 | + } else { |
| 194 | + console.log(`Tag ${version} already exists, skipping`); |
| 195 | + } |
| 196 | + } catch (error) { |
| 197 | + console.error(`Error: ${error.message}`); |
| 198 | + throw error; |
| 199 | + } |
| 200 | +
|
| 201 | + - name: Create Release |
| 202 | + uses: softprops/action-gh-release@v2 |
| 203 | + with: |
| 204 | + tag_name: v${{ steps.version.outputs.VERSION }} |
| 205 | + name: 'YASB GUI v${{ steps.version.outputs.VERSION }} (Beta)' |
| 206 | + body_path: CHANGELOG_BODY.md |
| 207 | + draft: true |
| 208 | + prerelease: false |
| 209 | + files: | |
| 210 | + dist-msis/*.msi |
| 211 | + dist-msis/checksums.txt |
0 commit comments