Build All Packages CI #21
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 All Packages CI | |
on: | |
push: | |
branches: [ 'dev-**', 'pr-**', staging, master ] | |
tags: [ '**' ] | |
pull_request: | |
branches: [ staging, master ] | |
schedule: | |
# At 02:30 on Saturday | |
- cron: '30 2 * * 6' | |
jobs: | |
py_build: | |
name: Build Python package | |
runs-on: ubuntu-latest | |
steps: | |
# Fetch full git repository and all submodules | |
- name: Checkout project | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
# Checkout tags | |
- name: Fetch tags | |
run: | | |
git fetch --prune --unshallow --tags | |
echo exit code $? | |
git tag --list | |
# Setup python environment | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
# Restore the python cache if it exists | |
- name: Restore python cache | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
# Install python dependencies for building dumb_udev | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi | |
# Build python dist package | |
- name: Build python dist package | |
id: build_py | |
run: | | |
echo "Short version:" | |
python ./setup.py --quiet --version 2> /dev/null | |
echo "Long version:" | |
python ./setup.py --quiet fullversion 2> /dev/null | |
python ./setup.py sdist bdist_wheel | |
# Read the python package distribution data (save version to file) | |
- name: Read python package distribution data | |
id: py_build_data | |
run: | | |
PY_VERSION=$(python ./setup.py --quiet --version 2> /dev/null) | |
PY_BDIST_PATH=$(ls dist/*.whl | head -n1) | |
PY_BDIST_FILE=${PY_BDIST_PATH#*/} | |
echo "py_version=${PY_VERSION}" >> $GITHUB_OUTPUT | |
echo "py_bdist_file=${PY_BDIST_FILE}" >> $GITHUB_OUTPUT | |
echo "py_bdist_path=${PY_BDIST_PATH}" >> $GITHUB_OUTPUT | |
echo ${PY_VERSION} > dist/VERSION.txt | |
# Upload python package distribution data artifact | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: dumb_udev-py-dist-data-${{ steps.py_build_data.outputs.py_version }} | |
path: dist/ | |
build_pypi: | |
name: Publish package to PyPI | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: py_build | |
runs-on: ubuntu-latest | |
steps: | |
# Fetch shallow git repository | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Fetch all artifacts | |
- name: Download Artifact | |
uses: actions/download-artifact@v2 | |
with: | |
path: ./artifacts/ | |
# Restore python package distribution data | |
- name: Restore python package distribution data | |
id: py_build_data | |
run: | | |
mkdir -p ./dist | |
find ./artifacts/ -type f -name "*.whl" -exec cp -n {} ./dist/ \; | |
find ./artifacts/ -type f -name "*.tar.gz" -exec cp -n {} ./dist/ \; | |
ls -l ./dist/ | |
# Push the artifacts to PyPI repo | |
- name: Publish distribution package to PyPI | |
uses: pypa/gh-action-pypi-publish@master | |
with: | |
password: ${{ secrets.PYPI_TOKEN }} |