Build And Publish #285
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: | |
push: | |
branches: [ master ] | |
paths: | |
- '.github/workflows/build.yml' | |
- 'cmake/*' | |
- 'deps/*' | |
- 'include/*' | |
- 'ntgcalls/*' | |
- 'wrtc/*' | |
- 'CMakeLists.txt' | |
- 'setup.py' | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-latest | |
cibw_archs: "native" | |
shared_name: "linux-x86_64" | |
cibw_os_build: "manylinux_" | |
- os: arm64-server | |
cibw_archs: "aarch64" | |
shared_name: "linux-arm64" | |
cibw_os_build: "manylinux_" | |
- os: windows-2019 | |
cibw_archs: "native" | |
shared_name: "windows-x86_64" | |
- os: macos-14 | |
cibw_archs: "arm64" | |
cibw_os_build: "macosx_arm64" | |
shared_name: "macos-arm64" | |
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.cibw_archs != 'aarch64' | |
run: | | |
python3 setup.py build_lib --debug | |
python3 setup.py build_lib | |
- name: Build Static Libs (Debug and Release) | |
if: matrix.cibw_archs != 'aarch64' | |
run: | | |
python3 setup.py build_lib --static --debug | |
python3 setup.py build_lib --static | |
- name: Build Shared Libs (Debug and Release) (ARM64) | |
if: matrix.cibw_archs == 'aarch64' | |
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) (ARM64) | |
if: matrix.cibw_archs == 'aarch64' | |
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 | |
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 | |
with: | |
name: ntgcalls.${{ matrix.shared_name }}-static_libs | |
path: ./static-output/* | |
if-no-files-found: error | |
- name: Build wheels | |
uses: ./.github/cibuildwheel | |
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 | |
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 | |
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/[email protected] | |
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.ref == 'refs/heads/master' && github.repository == 'pytgcalls/ntgcalls' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
skip-existing: true | |
packages-dir: dist/ |