Build & Release Bangen #33
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: | |
| paths: | |
| - "pyproject.toml" | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| tag: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.extract.outputs.version }} | |
| tag: ${{ steps.extract.outputs.tag }} | |
| exists: ${{ steps.check.outputs.exists }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - id: extract | |
| run: | | |
| VERSION=$(python3 - <<'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 | |
| - id: check | |
| run: | | |
| if git rev-parse "refs/tags/${{ steps.extract.outputs.tag }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - if: steps.check.outputs.exists == 'false' | |
| 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-linux: | |
| needs: tag | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build Linux (manylinux2014) | |
| shell: bash | |
| env: | |
| VERSION: ${{ needs.tag.outputs.version }} | |
| run: | | |
| printf 'from bangen.app import main\nif __name__=="__main__": main()\n' > _entry.py | |
| docker run --rm \ | |
| -u $(id -u):$(id -g) \ | |
| -e HOME=/tmp \ | |
| -e PIP_NO_CACHE_DIR=1 \ | |
| -v "${{ github.workspace }}:/workspace" \ | |
| -w /workspace \ | |
| ghcr.io/yt-dlp/manylinux2014_x86_64-shared \ | |
| bash -c ' | |
| set -euo pipefail | |
| py3.13 -m pip install -U pip wheel pyinstaller --no-cache-dir | |
| py3.13 -m pip install ".[all]" --no-cache-dir | |
| py3.13 -m PyInstaller --onefile --noconfirm --strip --noupx \ | |
| --name bangen \ | |
| --distpath dist \ | |
| --workpath build \ | |
| --collect-all bangen \ | |
| --collect-all pyfiglet \ | |
| --collect-all rich \ | |
| --collect-all PIL \ | |
| --collect-all typer \ | |
| --optimize 2 \ | |
| _entry.py | |
| strings dist/bangen | grep GLIBC_ | sort -V | uniq | |
| ' | |
| - run: | | |
| mkdir -p release | |
| NAME="bangen-linux-${{ needs.tag.outputs.version }}" | |
| mv dist/bangen release/$NAME | |
| cd release && tar -czf "$NAME.tar.gz" "$NAME" && rm "$NAME" | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-build | |
| path: release/* | |
| retention-days: 1 | |
| build-windows-macos: | |
| needs: tag | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| name: windows | |
| bin: bangen.exe | |
| - os: macos-latest | |
| name: macos | |
| bin: bangen | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install deps | |
| shell: bash | |
| run: | | |
| python -m pip install -U pip wheel pyinstaller | |
| pip install ".[all]" | |
| - name: Build | |
| shell: bash | |
| run: | | |
| printf 'from bangen.app import main\nif __name__=="__main__": main()\n' > _entry.py | |
| python -m PyInstaller --onefile --noconfirm --noupx --name bangen --distpath dist --workpath build --optimize 2 _entry.py | |
| - name: Package | |
| shell: bash | |
| run: | | |
| mkdir -p release | |
| NAME="bangen-${{ matrix.name }}-${{ needs.tag.outputs.version }}" | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| mv dist/${{ matrix.bin }} release/$NAME.exe | |
| powershell -Command "Compress-Archive -Path release\\$NAME.exe -DestinationPath release\\$NAME.zip" | |
| rm release/$NAME.exe | |
| else | |
| mv dist/${{ matrix.bin }} release/$NAME | |
| cd release && tar -czf "$NAME.tar.gz" "$NAME" && rm "$NAME" | |
| fi | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.name }}-build | |
| path: release/* | |
| retention-days: 1 | |
| release: | |
| needs: [tag, build-linux, build-windows-macos] | |
| if: needs.tag.outputs.exists == 'false' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - run: | | |
| cd artifacts | |
| sha256sum * > SHA256SUMS.txt | |
| - uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.tag.outputs.tag }} | |
| name: "Bangen ${{ needs.tag.outputs.version }}" | |
| files: artifacts/* |