Build & Release Bangen #21
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 & Release Bangen | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "pyproject.toml" | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| tag: | |
| name: Extract version & create tag | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.extract.outputs.version }} | |
| tag: ${{ steps.extract.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from pyproject.toml | |
| id: extract | |
| run: | | |
| VERSION=$(python - <<'EOF' | |
| import tomllib | |
| with open("pyproject.toml", "rb") as f: | |
| print(tomllib.load(f)["project"]["version"]) | |
| EOF | |
| ) | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "tag=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Abort if tag already exists | |
| run: | | |
| if git rev-parse "refs/tags/${{ steps.extract.outputs.tag }}" &>/dev/null; then | |
| echo "Tag ${{ steps.extract.outputs.tag }} already exists β skipping release." | |
| exit 1 | |
| fi | |
| - name: Create and push tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "${{ steps.extract.outputs.tag }}" | |
| git push origin "${{ steps.extract.outputs.tag }}" | |
| build: | |
| name: Build (${{ matrix.name }}) | |
| needs: tag | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| name: linux | |
| - os: windows-latest | |
| name: windows | |
| - os: macos-latest | |
| name: macos | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| ~/AppData/Local/pip/Cache | |
| key: pip-${{ runner.os }}-${{ hashFiles('pyproject.toml') }} | |
| restore-keys: pip-${{ runner.os }}- | |
| - name: Cache Nuitka | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/Nuitka | |
| key: nuitka-${{ runner.os }}-${{ hashFiles('**/*.py') }} | |
| restore-keys: nuitka-${{ runner.os }}- | |
| - name: Install system deps (Linux) | |
| if: runner.os == 'Linux' | |
| run: sudo apt-get install -y patchelf | |
| - name: MSVC setup (Windows) | |
| if: runner.os == 'Windows' | |
| uses: ilammy/msvc-dev-cmd@v1 | |
| - name: Install Python deps | |
| shell: bash | |
| run: | | |
| python -m pip install -U pip wheel nuitka zstandard | |
| pip install ".[all]" | |
| - name: Build with Nuitka | |
| shell: bash | |
| env: | |
| VERSION: ${{ needs.tag.outputs.version }} | |
| run: | | |
| printf 'from bangen.app import main\nif __name__ == "__main__":\n main()\n' > _entry.py | |
| python -m nuitka \ | |
| --mode=onefile \ | |
| --assume-yes-for-downloads \ | |
| --output-dir=build \ | |
| --output-filename=bangen \ | |
| --include-package=bangen \ | |
| --include-package=pyfiglet \ | |
| --include-package=rich \ | |
| --include-package=PIL \ | |
| --include-package=typer \ | |
| --nofollow-import-to=tkinter,unittest,test,distutils,setuptools,pkg_resources,email,http,html,xml,xmlrpc \ | |
| --python-flag=no_asserts,no_docstrings,isolated \ | |
| --onefile-tempdir-spec="{CACHE_DIR}/bangen/$VERSION" \ | |
| _entry.py | |
| - name: Package artifact | |
| shell: bash | |
| env: | |
| VERSION: ${{ needs.tag.outputs.version }} | |
| run: | | |
| mkdir -p dist | |
| NAME="bangen-${{ matrix.name }}-$VERSION" | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| mv build/bangen.exe dist/"$NAME.exe" | |
| powershell -Command "Compress-Archive -Path dist\\$NAME.exe -DestinationPath dist\\$NAME.zip" | |
| rm dist/"$NAME.exe" | |
| else | |
| mv build/bangen dist/"$NAME" | |
| (cd dist && tar -czf "$NAME.tar.gz" "$NAME" && rm "$NAME") | |
| fi | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.name }}-build | |
| path: dist/* | |
| retention-days: 1 | |
| release: | |
| name: Publish Release | |
| needs: [tag, build] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: Generate checksums | |
| run: | | |
| cd artifacts | |
| sha256sum * > SHA256SUMS.txt | |
| - name: Build release notes | |
| id: notes | |
| env: | |
| VERSION: ${{ needs.tag.outputs.version }} | |
| run: | | |
| PREV_TAG=$(git tag --sort=-version:refname | grep -v "^$VERSION$" | head -1) | |
| if [[ -n "$PREV_TAG" ]]; then | |
| COMMITS=$(git log "$PREV_TAG"..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| COMPARE_URL="https://github.com/${{ github.repository }}/compare/$PREV_TAG...$VERSION" | |
| SINCE_LINE="> Changes since \`$PREV_TAG\` Β· [Full diff]($COMPARE_URL)" | |
| else | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| SINCE_LINE="> Initial release" | |
| fi | |
| # Bucket commits by conventional prefix | |
| FEATS=$(echo "$COMMITS" | grep -E "^- feat" | sed 's/^- feat[^:]*: /- /' || true) | |
| FIXES=$(echo "$COMMITS" | grep -E "^- fix" | sed 's/^- fix[^:]*: /- /' || true) | |
| CHORES=$(echo "$COMMITS" | grep -E "^- (chore|refactor|perf|build|ci)" | sed 's/^- [^:]*: /- /' || true) | |
| OTHER=$(echo "$COMMITS" | grep -vE "^- (feat|fix|chore|refactor|perf|build|ci)" || true) | |
| { | |
| echo "body<<NOTES_EOF" | |
| echo "# β¨ Bangen $VERSION" | |
| echo "" | |
| echo "$SINCE_LINE" | |
| echo "" | |
| echo "---" | |
| echo "" | |
| if [[ -n "$FEATS" ]]; then | |
| echo "## π What's New" | |
| echo "$FEATS" | |
| echo "" | |
| fi | |
| if [[ -n "$FIXES" ]]; then | |
| echo "## π Bug Fixes" | |
| echo "$FIXES" | |
| echo "" | |
| fi | |
| if [[ -n "$CHORES" ]]; then | |
| echo "## π§ Maintenance" | |
| echo "$CHORES" | |
| echo "" | |
| fi | |
| if [[ -n "$OTHER" ]]; then | |
| echo "## π Other Changes" | |
| echo "$OTHER" | |
| echo "" | |
| fi | |
| echo "---" | |
| echo "" | |
| echo "## π¦ Downloads" | |
| echo "" | |
| echo "| Platform | File |" | |
| echo "|----------|------|" | |
| echo "| π§ Linux | \`bangen-linux-$VERSION.tar.gz\` |" | |
| echo "| πͺ Windows | \`bangen-windows-$VERSION.zip\` |" | |
| echo "| π macOS | \`bangen-macos-$VERSION.tar.gz\` |" | |
| echo "" | |
| echo "> π Verify downloads with \`SHA256SUMS.txt\`" | |
| echo "NOTES_EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| - uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.tag.outputs.tag }} | |
| name: "β¨ Bangen ${{ needs.tag.outputs.version }}" | |
| body: ${{ steps.notes.outputs.body }} | |
| files: artifacts/* |