Build And Publish #346
This file contains 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 Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
build-shared-libs: | |
description: 'Build shared libraries' | |
required: false | |
default: true | |
type: boolean | |
build-static-libs: | |
description: 'Build static libraries' | |
required: false | |
default: true | |
type: boolean | |
build-wheels: | |
description: 'Build wheels' | |
required: false | |
default: false | |
type: boolean | |
linux-build: | |
description: 'Build for Linux' | |
required: false | |
default: true | |
type: boolean | |
linux-arm64-build: | |
description: 'Build for Linux ARM64' | |
required: false | |
default: true | |
type: boolean | |
macos-build: | |
description: 'Build for macOS' | |
required: false | |
default: false | |
type: boolean | |
windows-build: | |
description: 'Build for Windows' | |
required: false | |
default: false | |
type: boolean | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
build_list="" | |
if [[ "${{ github.event.inputs.linux-build }}" == "true" ]]; then | |
build_list+=",{\"os\":\"ubuntu-latest\",\"cibw_archs\":\"native\",\"shared_name\":\"linux-x86_64\",\"cibw_os_build\":\"manylinux_\"}" | |
fi | |
if [[ "${{ github.event.inputs.linux-arm64-build }}" == "true" ]]; then | |
build_list+=",{\"os\":\"arm64-server\",\"cibw_archs\":\"aarch64\",\"shared_name\":\"linux-arm64\",\"cibw_os_build\":\"manylinux_\"}" | |
fi | |
if [[ "${{ github.event.inputs.macos-build }}" == "true" ]]; then | |
build_list+=",{\"os\":\"macos-14\",\"cibw_archs\":\"native\",\"shared_name\":\"macos-arm64\",\"cibw_os_build\":\"macosx_\"}" | |
fi | |
if [[ "${{ github.event.inputs.windows-build }}" == "true" ]]; then | |
build_list+=",{\"os\":\"windows-2022\",\"cibw_archs\":\"native\",\"shared_name\":\"windows-x86_64\"}" | |
fi | |
if [[ -n "$build_list" ]]; then | |
build_list="${build_list:1}" | |
fi | |
matrix=$(echo "{\"include\":[$build_list]}") | |
echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
build: | |
needs: setup | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: ${{fromJson(needs.setup.outputs.matrix)}} | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
if: matrix.cibw_archs != 'aarch64' | |
id: python | |
with: | |
python-version: "3.8 - 3.12" | |
update-environment: false | |
- name: Set up Python (ARM64) | |
if: matrix.cibw_archs == 'aarch64' | |
id: python-arm64 | |
run: echo "python-path=python3.12" >> $GITHUB_OUTPUT | |
- name: Install Python Requirements | |
run: | | |
"${{ steps.python.outputs.python-path || steps.python-arm64.outputs.python-path }}" -m pip install setuptools | |
"${{ steps.python.outputs.python-path || steps.python-arm64.outputs.python-path }}" -m pip install pipx | |
shell: bash | |
- name: Set up QEMU | |
if: matrix.cibw_archs == 'aarch64' | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64 | |
- name: Build Shared Libs (Debug and Release) | |
if: matrix.shared_name != 'linux-x86_64' && matrix.shared_name != 'linux-arm64' && github.event.inputs.build-shared-libs == 'true' | |
run: | | |
${{ steps.python.outputs.python-path }} setup.py build_lib --debug | |
${{ steps.python.outputs.python-path }} setup.py build_lib | |
- name: Build Static Libs (Debug and Release) | |
if: matrix.shared_name != 'linux-x86_64' && matrix.shared_name != 'linux-arm64' && github.event.inputs.build-static-libs == 'true' | |
run: | | |
${{ steps.python.outputs.python-path }} setup.py build_lib --static --debug | |
${{ steps.python.outputs.python-path }} setup.py build_lib --static | |
- name: Build Shared Libs (Debug and Release) (Linux) (x86_64) | |
if: matrix.shared_name == 'linux-x86_64' && github.event.inputs.build-shared-libs == 'true' | |
run: | | |
docker run -v $(pwd):/app -w /app quay.io/pypa/manylinux2014_x86_64:latest python3.12 setup.py build_lib --debug | |
docker run -v $(pwd):/app -w /app quay.io/pypa/manylinux2014_x86_64:latest python3.12 setup.py build_lib | |
- name: Build Static Libs (Debug and Release) (Linux) (x86_64) | |
if: matrix.shared_name == 'linux-x86_64' && github.event.inputs.build-static-libs == 'true' | |
run: | | |
docker run -v $(pwd):/app -w /app quay.io/pypa/manylinux2014_x86_64:latest python3.12 setup.py build_lib --static --debug | |
docker run -v $(pwd):/app -w /app quay.io/pypa/manylinux2014_x86_64:latest python3.12 setup.py build_lib --static | |
- name: Build Shared Libs (Debug and Release) (Linux) (ARM64) | |
if: matrix.shared_name == 'linux-arm64' && github.event.inputs.build-shared-libs == 'true' | |
run: | | |
docker run -v $(pwd):/app -w /app ghcr.io/pytgcalls/ntgcalls/arm64:latest python3 setup.py build_lib --debug | |
docker run -v $(pwd):/app -w /app ghcr.io/pytgcalls/ntgcalls/arm64:latest python3 setup.py build_lib | |
- name: Build Static Libs (Debug and Release) (Linux ARM64) | |
if: matrix.shared_name == 'linux-arm64' && github.event.inputs.build-static-libs == 'true' | |
run: | | |
docker run -v $(pwd):/app -w /app ghcr.io/pytgcalls/ntgcalls/arm64:latest python3 setup.py build_lib --static --debug | |
docker run -v $(pwd):/app -w /app ghcr.io/pytgcalls/ntgcalls/arm64:latest python3 setup.py build_lib --static | |
- name: Upload Shared Libs for ${{ matrix.shared_name }} | |
uses: actions/upload-artifact@v4 | |
if: github.event.inputs.build-shared-libs == 'true' | |
with: | |
name: ntgcalls.${{ matrix.shared_name }}-shared_libs | |
path: ./shared-output/* | |
if-no-files-found: error | |
- name: Upload Static Libs for ${{ matrix.shared_name }} | |
uses: actions/upload-artifact@v4 | |
if: github.event.inputs.build-static-libs == 'true' | |
with: | |
name: ntgcalls.${{ matrix.shared_name }}-static_libs | |
path: ./static-output/* | |
if-no-files-found: error | |
- name: Build wheels | |
uses: ./.github/cibuildwheel | |
if: github.event.inputs.build-wheels == 'true' | |
with: | |
python-path: ${{ steps.python.outputs.python-path || steps.python-arm64.outputs.python-path }} | |
env: | |
CIBW_ARCHS: ${{ matrix.cibw_archs }} | |
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8" | |
CIBW_BUILD: cp3*-${{ matrix.cibw_os_build }}* | |
CIBW_SKIP: cp36-* cp37-* | |
CIBW_BUILD_VERBOSITY: 3 | |
CIBW_TEST_SKIP: "cp38-macosx_arm64 *-manylinux_aarch64" | |
CIBW_TEST_COMMAND: python -c "from ntgcalls import NTgCalls; NTgCalls().ping()" | |
CIBW_MANYLINUX_AARCH64_IMAGE: ghcr.io/pytgcalls/ntgcalls/arm64:latest | |
- uses: actions/upload-artifact@v4 | |
if: github.event.inputs.build-wheels == 'true' | |
with: | |
name: ntgcalls-${{ matrix.shared_name }}-wheels | |
path: ./wheelhouse/*.whl | |
if-no-files-found: error | |
publish: | |
runs-on: ubuntu-latest | |
needs: [ build ] | |
permissions: | |
id-token: write | |
contents: write | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Get library Version | |
id: get-library-version | |
run: | | |
VERSION=$(grep -oP -m 1 'ntgcalls VERSION \K[A-Za-z0-9.]+' CMakeLists.txt) | |
echo "Library Version: $VERSION" | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Patch version number | |
id: patch-version | |
run: | | |
version="${{ steps.get-library-version.outputs.version }}" | |
if [[ "$version" == *.*.*.* ]]; then | |
echo "Version contains three dots" | |
major=$(echo "$version" | cut -d. -f1) | |
minor=$(echo "$version" | cut -d. -f2) | |
patch=$(echo "$version" | cut -d. -f3) | |
tweak=$(echo "$version" | cut -d. -f4) | |
new_version="${major}.${minor}.${patch}.dev${tweak}" | |
echo $new_version | |
echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
echo "is_dev=true" >> $GITHUB_OUTPUT | |
else | |
echo "Version does not contain three dots" | |
echo "new_version=${{ steps.get-library-version.outputs.version }}" >> $GITHUB_OUTPUT | |
echo "is_dev=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: tmp/ | |
- name: Prepare source distribution | |
if: github.event.inputs.build-wheels == 'true' | |
run: | | |
python3 -m pip install --upgrade setuptools | |
python3 setup.py sdist | |
- name: Zip releases | |
run: | | |
mkdir releases | |
for dir in tmp/*_libs; do | |
if [ -d "$dir" ]; then | |
echo "$dir" | |
folder_name=$(basename "$dir" .zip) | |
(cd $dir && zip -r "../../releases/${folder_name}.zip" *) | |
fi | |
done | |
- name: Create Release | |
id: create-new-release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
./releases/* | |
tag_name: "v${{ steps.patch-version.outputs.new_version }}" | |
name: "NTgCalls auto build v${{ steps.patch-version.outputs.new_version }}" | |
body: "These are the build files for the commit [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}).\nThese files were built during [this workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})." | |
prerelease: ${{ steps.patch-version.outputs.is_dev }} | |
- name: Extract artifacts | |
run: find tmp -type f -name "*.whl" | xargs -I {} mv {} dist | |
- name: Publish a Python distribution to PyPI. | |
if: github.event.inputs.build-wheels == 'true' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
skip-existing: true | |
packages-dir: dist/ |