Skip to content

Commit

Permalink
Add reusable action (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikteliy authored Apr 15, 2023
1 parent 0fca338 commit edb6c5d
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 159 deletions.
41 changes: 41 additions & 0 deletions .github/actions/prepare_snap7/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'prepare to build a package'
description: 'Downloads and unpacks snap7 archive. Copies the required files. Updates wheels'
inputs:
snap7-archive-url:
description: 'Link to download snap7 archive'
required: true
default: 'https://sourceforge.net/projects/snap7/files/1.4.2/snap7-full-1.4.2.7z/download'
runs:
using: "composite"
steps:
- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
with:
path: snap7-full-1.4.2.7z
key: ${{ inputs.snap7-archive-url }}

- name: Install choco packages
if: steps.snap7-archive.outputs.cache-hit != 'true' && runner.os == 'Windows'
shell: bash
run: choco install --allow-downgrade wget --version 1.20.3.20190531

- name: Get snap7
if: steps.snap7-archive.outputs.cache-hit != 'true'
shell: bash
run: wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ inputs.snap7-archive-url }}

- name: Extract archive
shell: bash
run: 7z x snap7-full-1.4.2.7z

- name: Copy files
shell: bash
run: |
mkdir src
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
cp .github/build_scripts/dummy.c ./
- name: Update wheel
shell: bash
run: python -m pip install --upgrade pip wheel
41 changes: 7 additions & 34 deletions .github/workflows/build-and-test-arm32v7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,29 @@ on:
branches: [master]
pull_request:
branches: [master]
env:
snap7-archive-url: https://sourceforge.net/projects/snap7/files/1.4.2/snap7-full-1.4.2.7z/download
jobs:
arm32-build:
name: Build arm32 wheel
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
with:
path: snap7-full-1.4.2.7z
key: ${{ env.snap7-archive-url }}

- name: Get snap7
if: steps.snap7-archive.outputs.cache-hit != 'true'
run: |
wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
- name: Extract archive
run: 7z x snap7-full-1.4.2.7z

- name: Copy files
run: |
mkdir src
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
cp .github/build_scripts/dummy.c ./
ls snap7-full-1.4.2

- name: prepare snap7 archive
uses: ./.github/actions/prepare_snap7

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm

- name: Update wheel
run: python -m pip install --upgrade wheel

- name: Build libsnap7.so
run: |
docker run --rm --interactive -v $PWD/snap7-full-1.4.2:/snap7-full-1.4.2 "arm32v7/gcc:latest" /bin/bash -s <<EOF
cd snap7-full-1.4.2/build/unix/
make -f arm_v7_linux.mk all
EOF
- name: tmp check file
run: ls -la snap7-full-1.4.2/build/bin/arm_v7-linux

- name: Build pure python wheel
run: python3 setup.py bdist_wheel --plat-name=linux_armv7l

Expand All @@ -68,7 +41,6 @@ jobs:
mkdir -p wheelhouse/linux_armv7l
python3 -m wheel pack $unpack_tmp_dir/$packagename -d wheelhouse/linux_armv7l/
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -99,7 +71,8 @@ jobs:

- name: Run tests in docker:arm32v7
run: |
docker run --platform linux/arm/v7 --rm --interactive -v $PWD/test:/test -v $PWD/wheelhouse:/wheelhouse "arm32v7/python:${{ matrix.python-version }}-buster" /bin/bash -s <<EOF
python -m pip install pytest $(ls wheelhouse/linux_armv7l/*.whl)
python -m pytest test/test_server.py test/test_util.py test/test_client.py test/test_mainloop.py test/test_partner.py
docker run --platform linux/arm/v7 --rm --interactive -v $PWD/tests:/tests -v $PWD/setup.cfg:/setup.cfg \
-v $PWD/wheelhouse:/wheelhouse "arm32v7/python:${{ matrix.python-version }}-buster" /bin/bash -s <<EOF
python -m pip install pytest pytest-asyncio $(ls wheelhouse/linux_armv7l/*.whl)
python -m pytest tests/ -m "server or util or client or mainloop or partner"
EOF
35 changes: 8 additions & 27 deletions .github/workflows/build-and-test-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,26 @@ on:
branches: [master]
pull_request:
branches: [master]
env:
snap7-archive-url: https://sourceforge.net/projects/snap7/files/1.4.2/snap7-full-1.4.2.7z/download
jobs:
arm64-build:
name: Build arm64 wheel
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
with:
path: snap7-full-1.4.2.7z
key: ${{ env.snap7-archive-url }}

- name: Get snap7
if: steps.snap7-archive.outputs.cache-hit != 'true'
run: |
wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
- name: Extract archive
run: 7z x snap7-full-1.4.2.7z

- name: prepare snap7 archive
uses: ./.github/actions/prepare_snap7

- name: Copy files
run: |
mkdir src
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
cp .github/build_scripts/dummy.c ./
cp .github/build_scripts/aarch64-linux-gnu.mk snap7-full-1.4.2/build/unix/
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64

- name: Update wheel
run: python -m pip install --upgrade wheel

- name: Build wheels
uses: pypa/cibuildwheel@v2.1.3
with:
Expand Down Expand Up @@ -72,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -90,7 +70,8 @@ jobs:

- name: Run tests in docker:arm64v8
run: |
docker run --rm --interactive -v $PWD/test:/test -v $PWD/wheelhouse:/wheelhouse "arm64v8/python:${{ matrix.python-version }}-buster" /bin/bash -s <<EOF
python -m pip install pytest $(ls wheelhouse/${{ runner.os }}/*.whl)
python -m pytest test/test_server.py test/test_util.py test/test_client.py test/test_mainloop.py test/test_partner.py
docker run --rm --interactive -v $PWD/tests:/tests -v $PWD/setup.cfg:/setup.cfg -v $PWD/wheelhouse:/wheelhouse \
"arm64v8/python:${{ matrix.python-version }}-buster" /bin/bash -s <<EOF
python3 -m pip install pytest pytest-asyncio $(ls wheelhouse/${{ runner.os }}/*.whl)
python3 -m pytest tests/ -m server -m util -m client -m mainloop -m partner
EOF
81 changes: 13 additions & 68 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
branches: [master]
pull_request:
branches: [master]
env:
snap7-archive-url: https://sourceforge.net/projects/snap7/files/1.4.2/snap7-full-1.4.2.7z/download
jobs:
windows-build:
name: Build wheel for windows
Expand All @@ -14,26 +12,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install choco packages
run: choco install --allow-downgrade wget --version 1.20.3.20190531

- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
with:
path: snap7-full-1.4.2.7z
key: ${{ env.snap7-archive-url }}

- name: Get snap7
if: steps.snap7-archive.outputs.cache-hit != 'true'
run: |
wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
- name: Extract archive
run: 7z x snap7-full-1.4.2.7z

- name: Update wheel
run: python3 -m pip install wheel --upgrade
- name: prepare snap7 archive
uses: ./.github/actions/prepare_snap7

- name: Build wheel
run: python3 setup.py bdist_wheel --plat-name win_amd64
Expand All @@ -54,28 +34,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
with:
path: snap7-full-1.4.2.7z
key: ${{ env.snap7-archive-url }}

- name: Get snap7
if: steps.snap7-archive.outputs.cache-hit != 'true'
run: wget -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}

- name: Extract archive
run: 7z x snap7-full-1.4.2.7z

- name: Copy files
run: |
mkdir src
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
cp .github/build_scripts/dummy.c ./
- name: Update wheel
run: python -m pip install --upgrade wheel
- name: prepare snap7 archive
uses: ./.github/actions/prepare_snap7

- name: Build pure python wheel
run: python3 setup.py bdist_wheel --plat-name=manylinux1_x86_64
Expand Down Expand Up @@ -105,27 +65,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache snap7-archive
id: snap7-archive
uses: actions/cache@v3
with:
path: snap7-full-1.4.2.7z
key: ${{ env.snap7-archive-url }}

- name: Get snap7
if: steps.snap7-archive.outputs.cache-hit != 'true'
run: |
wget -nv -O snap7-full-1.4.2.7z --content-disposition -c ${{ env.snap7-archive-url }}
- name: Extract archive
run: 7z x snap7-full-1.4.2.7z

- name: prepare snap7 archive
uses: ./.github/actions/prepare_snap7

- name: Copy files
run: |
mkdir src
cp snap7-full-1.4.2/release/Wrappers/c-cpp/snap7.h src
cp .github/build_scripts/dummy.c ./
cp .github/build_scripts/arm64_osx.mk snap7-full-1.4.2/build/osx/
pushd snap7-full-1.4.2/build/osx/
make -f x86_64_osx.mk all
Expand Down Expand Up @@ -165,7 +110,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -178,7 +123,7 @@ jobs:
- name: Install pytest
run: |
python3 -m pip install --upgrade pip
python3 -m pip install pytest
python3 -m pip install pytest pytest-asyncio
- name: Download artifacts
uses: actions/download-artifact@v3
Expand All @@ -192,16 +137,16 @@ jobs:
- name: Run pytest
run: |
which pytest
pytest test/test_server.py test/test_util.py test/test_client.py test/test_mainloop.py
pytest -m "server or util or client or mainloop"
- name: Run tests required sudo
if: ${{ runner.os == 'Linux'}}
run: sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest test/test_partner.py
run: sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest -m partner

- name: Run tests required sudo
if: ${{ runner.os == 'macOS'}}
run: sudo pytest test/test_partner.py
run: sudo pytest -m partner

- name: Run tests required sudo
if: ${{ runner.os == 'Windows'}}
run: pytest test/test_partner.py
run: pytest -m partner
4 changes: 2 additions & 2 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
sudo python3 -m pip install flake8
- name: Lint with flake8
run: |
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics snap7 test
flake8 --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics snap7 test
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics snap7 tests
flake8 --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics snap7 tests
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
- name: Run pytest
run: |
which pytest
pytest test/test_server.py test/test_client.py test/test_util.py test/test_mainloop.py
sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest test/test_partner.py
pytest -m "server or util or client or mainloop"
sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest -m partner
4 changes: 2 additions & 2 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: python3 -m pip install .[test]
- name: Run pytest
run: |
pytest test/test_server.py test/test_client.py test/test_util.py test/test_mainloop.py
sudo pytest test/test_partner.py
pytest -m "server or util or client or mainloop"
sudo pytest -m partner
2 changes: 1 addition & 1 deletion .github/workflows/pycodestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install pycodestyle
- name: Run pycodestyle
run: pycodestyle snap7 test
run: pycodestyle snap7 tests
16 changes: 8 additions & 8 deletions .github/workflows/test-pypi-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -27,16 +27,16 @@ jobs:
- name: Run pytest
run: |
which pytest
pytest test/test_server.py test/test_util.py test/test_client.py
pytest -m "server or util or client or mainloop"
- name: Run tests required sudo
if: ${{ runner.os == 'Linux'}}
run: sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest test/test_partner.py

- name: Run test_partner.py on windows
if: ${{ runner.os == 'Windows' }}
run: pytest test/test_partner.py
run: sudo /opt/hostedtoolcache/Python/${{ matrix.python-version }}*/x64/bin/pytest -m partner

- name: Run tests required sudo
if: ${{ runner.os == 'macOS'}}
run: sudo pytest test/test_partner.py
run: sudo pytest -m partner

- name: Run tests required sudo
if: ${{ runner.os == 'Windows'}}
run: pytest -m partner
Loading

0 comments on commit edb6c5d

Please sign in to comment.