Skip to content

update github workflows #39

update github workflows

update github workflows #39

name: Create release, build and upload release assets
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: check-version
run: |
version=$(echo "${{ github.ref }}" | cut -d/ -f3)
grep ${version} VERSION.txt || exit 1
create-release:
needs: check-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Create upload_url artifact
run: |
echo "${{ steps.create_release.outputs.upload_url }}" > upload_url.txt
- name: Upload upload_url artifact
uses: actions/upload-artifact@v4
with:
name: upload_url.txt
path: upload_url.txt
build-and-upload-deb-asset:
needs: create-release
runs-on: ubuntu-latest
container:
image: debian:bookworm
steps:
- name: Install build dependencies
run: |
apt update
export DEBIAN_FRONTEND=noninteractive
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: 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 -d/ -f3)
echo "version=${version}" >> $GITHUB_ENV
- name: Download upload_url artifact
uses: actions/download-artifact@v4
with:
name: upload_url.txt
path: /home/runner/work/openvpn-monitor/openvpn-monitor
- name: Get upload_url
run: |
export upload_url=$(<upload_url.txt)
rm upload_url.txt
echo "upload_url=${upload_url}" >> $GITHUB_ENV
- name: Build deb package
env:
EMAIL: [email protected]
COMMIT_MSG: |
auto-commit
skip-checks: true
run: |
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 --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
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.upload_url }}
asset_name: ${{ format('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
runs-on: ubuntu-latest
container:
image: rockylinux:9
steps:
- name: Install build dependencies
run: |
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
with:
name: upload_url.txt
- name: Get upload_url
run: |
export upload_url=$(cat upload_url.txt)
rm upload_url.txt
echo "upload_url=${upload_url}" >> $GITHUB_ENV
- 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
run: echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Upload rpm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.upload_url }}
asset_name: ${{ format('python3-openvpn-monitor-{0}-1.noarch.rpm', env.version) }}
asset_path: ${{ format('dist/python3-openvpn-monitor-{0}-1.noarch.rpm', env.version) }}
asset_content_type: application/x-rpm
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
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
sudo apt -y install yarnpkg
python3 -m pip install --upgrade pip
pip3 install setuptools wheel
- name: Build dists
run: |
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