Skip to content

Commit

Permalink
feat(plc4py/github): Add GitHub action for python project. Also added…
Browse files Browse the repository at this point in the history
… dependencies for the python maven project to include the protocols.
  • Loading branch information
hutcheb committed Nov 14, 2022
1 parent ce8fe7e commit 50c3fb6
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 2 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/python-build.yml
@@ -0,0 +1,122 @@
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
name: "Python Platform Compatibility"

on:
push:
branches: [ "develop", "plc4py" ]
paths:
- code-generation/**
- protocols/**
- sandbox/plc4py**
workflow_dispatch:
inputs:
forceUpdates:
description: "Forces a snapshot update"
required: false
default: 'false'

permissions:
contents: read

jobs:
test:
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '${{ matrix.python-version }}'

- name: Set Platform options
id: platform_opts
uses: actions/github-script@v6.3.3
env:
OS: ${{ matrix.os }}
with:
script: |
const { OS } = process.env
if (OS.includes("windows")) {
core.setOutput('platform_opts', ``)
} else if (OS.includes("macos")) {
core.setOutput('platform_opts', `-Djna.library.path="$(find /usr/local/Cellar/libpcap/ -name lib)"`)
} else if (OS.includes("ubuntu")) {
core.setOutput('platform_opts', ``)
} else {
core.setOutput('platform_opts', ``)
}
- name: Calculate platform suffix
id: platform_suffix
uses: actions/github-script@v6.3.3
env:
OS: ${{ matrix.os }}
with:
script: |
const { OS } = process.env
if (OS.includes("windows")) {
core.setOutput('platform_suffix', `.cmd`)
} else {
core.setOutput('platform_suffix', ``)
}
- name: Set extra options
id: extra_options
uses: actions/github-script@v6.3.3
env:
FORCE_UPDATE: ${{ github.event.inputs.forceUpdates }}
with:
script: |
const { FORCE_UPDATE } = process.env
if (FORCE_UPDATE.includes("true")) {
core.setOutput('extra_options', `-U`)
} else {
core.setOutput('extra_options', ``)
}
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ./sandbox/plc4py --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 ./sandbox/plc4py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run mvnw
run: |
./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} ${{ steps.extra_options.outputs.extra_options }} -T 1C -B -P'with-sandbox,with-python' -pl :plc4py ${{ steps.platform_opts.outputs.platform_opts }} install || ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} ${{ steps.extra_options.outputs.extra_options }} -B -P'with-sandbox,with-python' -pl :plc4py ${{ steps.platform_opts.outputs.platform_opts }} install

24 changes: 22 additions & 2 deletions sandbox/plc4py/pom.xml
Expand Up @@ -17,7 +17,8 @@
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -87,7 +88,7 @@
<arguments>
<argument>-m</argument>
<argument>venv</argument>
<argument> ./venv</argument>
<argument>./venv</argument>
</arguments>
</configuration>
</execution>
Expand Down Expand Up @@ -190,4 +191,23 @@
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4x-protocols-modbus</artifactId>
<version>0.11.0-SNAPSHOT</version>
<!-- Scope is 'provided' as this way it's not shipped with the driver -->
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4x-protocols-simulated</artifactId>
<version>0.11.0-SNAPSHOT</version>
<!-- Scope is 'provided' as this way it's not shipped with the driver -->
<scope>provided</scope>
</dependency>

</dependencies>

</project>

0 comments on commit 50c3fb6

Please sign in to comment.