Build and Release #94
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
| name: Build and Release | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| check_version: | |
| name: Check version and release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.get_version.outputs.version }} | |
| should_release: ${{ steps.get_version.outputs.should_release }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Sync pyproject version from bsdd_gui.__version__ | |
| id: get_version | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const initPath = 'src/bsdd_gui/__init__.py'; | |
| const pyprojPath = 'src/bsdd_gui/pyproject.toml'; | |
| const init = fs.readFileSync(initPath, 'utf8'); | |
| const verMatch = init.match(/__version__\s*=\s*"([^"]+)"/); | |
| if (!verMatch) { | |
| core.setFailed(`Could not parse __version__ from ${initPath}`); | |
| return; | |
| } | |
| const version = verMatch[1]; | |
| // Update pyproject version to match | |
| let pyproj = fs.readFileSync(pyprojPath, 'utf8'); | |
| if (!/^version\s*=\s*"([^"]+)"/m.test(pyproj)) { | |
| core.setFailed(`Could not find version field in ${pyprojPath}`); | |
| return; | |
| } | |
| pyproj = pyproj.replace(/^version\s*=\s*"([^"]+)"/m, `version = "${version}"`); | |
| fs.writeFileSync(pyprojPath, pyproj); | |
| core.setOutput('version', version); | |
| // Check if a release with this tag already exists | |
| const tag = `v${version}`; | |
| try { | |
| await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag, | |
| }); | |
| core.info(`Release for ${tag} already exists.`); | |
| core.setOutput('should_release', 'false'); | |
| } catch (e) { | |
| if (e.status === 404) { | |
| core.info(`No release for ${tag}; will create.`); | |
| core.setOutput('should_release', 'true'); | |
| } else { | |
| throw e; | |
| } | |
| } | |
| build: | |
| name: Build (${{ matrix.os }}) | |
| needs: check_version | |
| if: needs.check_version.outputs.should_release == 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ ubuntu-latest, windows-latest ] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install ./src/bsdd_json ./src/bsdd_gui | |
| pip install pyinstaller | |
| - name: Build with PyInstaller | |
| run: | | |
| pyinstaller main.spec -y | |
| - name: Package artifact (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| mkdir -p artifacts | |
| cd dist | |
| zip -r ../artifacts/bSDD-Toolkit-linux-x86_64-v${{ needs.check_version.outputs.version }}.zip bSDD-Toolkit | |
| - name: Package artifact (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force -Path artifacts | Out-Null | |
| Compress-Archive -Path dist\bSDD-Toolkit\* -DestinationPath artifacts\bSDD-Toolkit-windows-x86_64-v${{ needs.check_version.outputs.version }}.zip -Force | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bSDD-Toolkit-${{ runner.os }}-v${{ needs.check_version.outputs.version }} | |
| path: artifacts/* | |
| release: | |
| name: Create GitHub Release | |
| needs: [check_version, build] | |
| if: needs.check_version.outputs.should_release == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: release_assets | |
| - name: Create release and upload assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.check_version.outputs.version }} | |
| name: v${{ needs.check_version.outputs.version }} | |
| generate_release_notes: true | |
| files: | | |
| release_assets/** |