Skip to content

Commit

Permalink
update github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
furlongm committed Dec 23, 2024
1 parent cd05d6f commit 64a506b
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 45 deletions.
49 changes: 32 additions & 17 deletions .github/workflows/create-release-and-upload-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ jobs:
run: |
apt update
export DEBIAN_FRONTEND=noninteractive
apt -y install python3-setuptools debhelper dh-exec dh-python git-buildpackage
apt -y install python3-setuptools debhelper dh-exec dh-python git-buildpackage yarnpkg
- name: Fix sh so env vars propogate
run: |
rm /bin/sh
ln -sf /bin/bash /bin/sh
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master
ref: main
- name: git fetch --all
run: |
git config --global --add safe.directory /__w/openvpn-monitor/openvpn-monitor
git fetch --all
- name: Get version
run: |
export version=$(echo "${{ github.ref }}" | cut -dv -f2)
export version=$(echo "${{ github.ref }}" | cut -d/ -f3)
echo "version=${version}" >> $GITHUB_ENV
- name: Download upload_url artifact
uses: actions/download-artifact@v4
Expand All @@ -73,21 +73,25 @@ jobs:
export upload_url=$(<upload_url.txt)
rm upload_url.txt
echo "upload_url=${upload_url}" >> $GITHUB_ENV
- name: Build deb packages
- name: Build deb package
env:
EMAIL: [email protected]
COMMIT_MSG: |
auto-commit
skip-checks: true
run: |
export version=$(echo "${{ github.ref }}" | cut -dv -f2)
export version=$(echo "${{ github.ref }}" | cut -d/ -f3)
echo "${version}" > VERSION.txt
git add VERSION.txt
yarnpkg --prod --modules-folder openvpn_monitor/static/dist install
find openvpn_monitor/static > debian/source/include-binaries
rm yarn.lock
git add debian/source/include-binaries openvpn_monitor/static/dist
git diff --quiet && git diff --staged --quiet || git commit -m "${COMMIT_MSG}"
gbp dch --new-version=${version}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
git tag --delete v${version}
git tag v${version}
gbp buildpackage --git-upstream-tree=${{ github.ref }} -uc -us
gbp dch --ignore-branch --new-version=${version}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
git tag --delete ${version}
git tag ${version}
gbp buildpackage --git-ignore-branch --git-upstream-tree=${{ github.ref }} -uc -us
- name: Get version
run: echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Upload deb
Expand All @@ -97,7 +101,7 @@ jobs:
with:
upload_url: ${{ env.upload_url }}
asset_name: ${{ format('python3-openvpn-monitor_{0}-1_all.deb', env.version) }}
asset_path: ${{ format('deb_dist/python3-openvpn-monitor_{0}-1_all.deb', env.version) }}
asset_path: ${{ format('../python3-openvpn-monitor_{0}-1_all.deb', env.version) }}
asset_content_type: application/vnd.debian.binary-package
build-and-upload-rpm-asset:
needs: create-release
Expand All @@ -107,7 +111,9 @@ jobs:
steps:
- name: Install build dependencies
run: |
dnf -y install rpm-build python3 python3-setuptools git
dnf -y install epel-release
dnf makecache
dnf -y install rpm-build python3 python3-setuptools git yarnpkg
- uses: actions/checkout@v4
- name: Download upload_url artifact
uses: actions/download-artifact@v4
Expand All @@ -118,8 +124,9 @@ jobs:
export upload_url=$(cat upload_url.txt)
rm upload_url.txt
echo "upload_url=${upload_url}" >> $GITHUB_ENV
- name: Build rpm packages
- name: Build rpm package
run: |
yarnpkg --prod --modules-folder openvpn_monitor/static/dist install|
sed -i -e "s/name='.*/name='python3-openvpn-monitor',/" setup.py
python3 setup.py bdist_rpm
- name: Get version
Expand All @@ -136,6 +143,11 @@ jobs:
upload-package-to-pypi:
needs: create-release
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/openvpn-monitor
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up python
Expand All @@ -144,9 +156,12 @@ jobs:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
sudo apt -y install yarnpkg
python3 -m pip install --upgrade pip
pip3 install setuptools wheel
- name: Build dists
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
yarnpkg --prod --modules-folder openvpn_monitor/static/dist install
python3 setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
pip3 install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
Expand Down
6 changes: 4 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
include README.md
recursive-include openvpn_monitor *.py
include openvpn-monitor.conf.example
include AUTHORS
include COPYING
include MANIFEST.in
include VERSION.txt
include requirements.txt
recursive-include openvpn_monitor *.py
recursive-include openvpn_monitor/static/images *
recursive-include openvpn_monitor/templates *
include etc/openvpn-monitor/openvpn-monitor.conf.example
include etc/openvpn-monitor/apache.conf.example
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.2
2.0.3
1 change: 0 additions & 1 deletion debian/.gitignore

This file was deleted.

8 changes: 4 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Section: python
Priority: optional
Maintainer: Marcus Furlong <[email protected]>
Uploaders: Marcus Furlong <[email protected]>
Build-Depends: debhelper (>=10-.0.0), python (>=3), dh-python
Build-Depends: debhelper (>=10.0.0), python3 (>=3.11.0), dh-python
Standards-Version: 3.9.7
Homepage: https://github.com/furlongm/openvpn-monitor
Vcs-Git: git://github.com/furlongm/openvpn-monitor
Vcs-Browser: https://github.com/furlongm/openvpn-monitor
X-Python-Version: >= 3
X-Python-Version: >= 3.11.0

Package: python3-openvpn-monitor
Architecture: all
Homepage: https://github.com/furlongm/openvpn-monitor
Depends: ${misc:Depends}, python3, apache2, libapache2-mod-wsgi,
python3-geoip2, python3-humanize, python3-flask, python3-flaskext.wtf
Depends: ${misc:Depends}, python3, apache2, libapache2-mod-wsgi-py3,
python3-geoip2, python3-humanize, python3-flask, python3-flaskext.wtf,
python3-semver
Description: openvpn-monitor is a web based OpenVPN monitor, that shows
current connection information, such as users, location and data transferred.
20 changes: 16 additions & 4 deletions debian/python3-openvpn-monitor.postinst
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#!/bin/sh -e
#!/bin/bash -e

#DEBHELPER#

if [ "$1" = "configure" ] ; then
apache_conf_file=/etc/apache2/conf-available/openvpn-monitor.conf

echo 'WSGIScriptAlias /openvpn-monitor /usr/lib/python3/dist-packages/openvpn_monitor/app.py' > /etc/apache2/conf-available/python3-openvpn-monitor.conf
if [ ! -e ${apache_conf_file} ] ; then
cp /etc/openvpn-monitor/apache.conf.example ${apache_conf_file}
fi

site_packages=/usr/lib/python3/dist-packages
site_packages="${site_packages//\//\\\/}"
if ! grep ${site_packages} ${apache_conf_file} >/dev/null 2>&1 ; then
sed -i -e "s/^\(Define openvpn_monitor_pythonpath\).*/\1 ${site_packages}/" ${apache_conf_file}
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke enconf python2-openvpn-monitor.conf
apache2_invoke enconf openvpn-monitor.conf
fi

systemctl enable apache2
systemctl restart apache2

chown :www-data /etc/openvpn-monitor/openvpn-monitor.conf.example
4 changes: 3 additions & 1 deletion debian/python3-openvpn-monitor.prerm
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/sh -e

apache_conf_file=/etc/apache2/conf-available/openvpn-monitor.conf

if [ "$1" = "remove" ] ; then
rm /etc/apache2/conf-available/openvpn-monitor.conf
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke disconf openvpn-monitor.conf
rm ${apache_conf_file}
fi

if [ "$1" = "purge" ] ; then
Expand Down
2 changes: 1 addition & 1 deletion etc/openvpn-monitor/apache.conf.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Define openvpn_monitor_pythonpath /srv/openvpn-monitor/
WSGIScriptAlias /openvpn-monitor ${openvpn_monitor_pythonpath}/openvpn-monitor/app.py
WSGIScriptAlias /openvpn-monitor ${openvpn_monitor_pythonpath}/openvpn_monitor/app.py
WSGIPythonPath ${openvpn_monitor_pythonpath}

<Directory ${openvpn_monitor_pythonpath}>
Expand Down
14 changes: 8 additions & 6 deletions rpm/rpm-post-install.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/sh

if [ ! -e /etc/httpd/conf.d/openvpn-monitor.conf ] ; then
cp /etc/openvpn-monitor/apache.conf.example /etc/httpd/conf.d/openvpn-monitor.conf
apache_conf_file=/etc/httpd/conf.d/openvpn-monitor.conf

if [ ! -e ${apache_conf_file} ] ; then
cp /etc/openvpn-monitor/apache.conf.example ${apache_conf_file}
fi

site_packages=$(python3 -c 'import site; print(site.getsitepackages()[-1])')
if ! grep ${site-packages} /etc/httpd/conf.d/openvpn-monitor.conf >/dev/null 2>&1 ; then
sed -i -e "s/^\(Define openvpn_monitor_pythonpath\).*/\1 ${site_packages}" \
/etc/httpd/conf.d/openvpn-monitor.conf
site_packages="${site_packages//\//\\\/}"
if ! grep ${site_packages} ${apache_conf_file} >/dev/null 2>&1 ; then
sed -i -e "s/^\(Define openvpn_monitor_pythonpath\).*/\1 ${site_packages}/" ${apache_conf_file}
fi

systemctl enable httpd
systemctl restart httpd

chown :apache /etc/openvpn-monitor/openvpn-monitor.conf
chown :apache /etc/openvpn-monitor/openvpn-monitor.conf.example

semanage port -a -t openvpn_port_t -p tcp 5555
setsebool -P httpd_can_network_connect 1
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@
with open('requirements.txt', 'r', encoding='utf_8') as rt:
install_requires = rt.read().splitlines()

data_files = []

for dirpath, dirnames, filenames in os.walk('openvpn_monitor/static/images/flags'):
data_files = [('share/openvpn-monitor/images/flags',
[os.path.join(dirpath, f) for f in filenames])]
package_files = []
for directory in ['openvpn_monitor/static', 'openvpn_monitor/templates']:
for (path, directories, filenames) in os.walk(directory):
for filename in filenames:
trimmed_path = path.replace('openvpn_monitor/', '')
package_files.append(os.path.join(trimmed_path, filename))

if sys.prefix == '/usr':
conf_path = '/etc'
else:
conf_path = sys.prefix

data_files = []
for dirpath, dirnames, filenames in os.walk('etc'):
for i, dirname in enumerate(dirnames):
if dirname.startswith('.'):
Expand All @@ -59,6 +61,7 @@
keywords='web openvpn monitor',
url='http://openvpn-monitor.openbytes.ie',
packages=find_packages(),
package_data={'openvpn_monitor': package_files},
install_requires=install_requires,
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 64a506b

Please sign in to comment.