Skip to content

ensure host errata are tracked and updated #112

ensure host errata are tracked and updated

ensure host errata are tracked and updated #112

name: Create release, build and upload release assets
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to build (e.g. 4.0.9-rc1)'
required: true
permissions:
contents: write
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-vars.outputs.version }}
rpm_version: ${{ steps.set-vars.outputs.rpm_version }}
is_prerelease: ${{ steps.set-vars.outputs.is_prerelease }}
steps:
- id: set-vars
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/v}"
fi
# RPM doesn't allow hyphens in version, convert to dots
RPM_VERSION="${VERSION//-/.}"
# Pre-release if version contains -, e.g. 4.0.9-rc1, 4.0.9-dev1
if [[ "$VERSION" == *-* ]]; then
IS_PRERELEASE=true
else
IS_PRERELEASE=false
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "rpm_version=${RPM_VERSION}" >> $GITHUB_OUTPUT
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
echo "Version: $VERSION, RPM Version: $RPM_VERSION, Pre-release: $IS_PRERELEASE"
create-release:
needs: setup
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.setup.outputs.version }}
name: Release v${{ needs.setup.outputs.version }}
draft: false
prerelease: ${{ needs.setup.outputs.is_prerelease }}
generate_release_notes: ${{ needs.setup.outputs.is_prerelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-version-and-changelog:
needs: [setup, create-release]
if: needs.setup.outputs.is_prerelease == 'false'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: git fetch --all
run: |
git fetch --all
- name: git config
run: |
git config user.email furlongm@gmail.com
git config user.name 'Marcus Furlong'
- name: Install dependencies
run: |
sudo apt update
sudo apt -y install python3-setuptools debhelper dh-exec dh-python git-buildpackage
- name: Update repo version if required
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
auto-commit to update version
skip-checks: true
run: |
echo "${{ needs.setup.outputs.version }}" > VERSION.txt
git add VERSION.txt
git diff --quiet && git diff --staged --quiet || git commit -m "${COMMIT_MSG}"
git push origin main
- name: Update debian changelog
env:
EMAIL: furlongm@gmail.com
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
auto-commit to update debian changelog
skip-checks: true
run: |
gbp dch --new-version=${{ needs.setup.outputs.version }}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
git push origin main
build-and-upload-deb-assets:
needs: [setup, create-release, update-version-and-changelog]
# For pre-releases, update-version-and-changelog is skipped, so use always()
if: always() && needs.create-release.result == 'success'
runs-on: ubuntu-latest
container:
image: debian:trixie
steps:
- name: Install build dependencies
run: |
apt update
export DEBIAN_FRONTEND=noninteractive
apt -y install python3-setuptools debhelper dh-exec dh-python git-buildpackage
- 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
# For stable releases, use main (has updated changelog); for pre-releases, use the tag
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && 'main' || github.ref }}
- name: git fetch --all
run: |
git config --global --add safe.directory /__w/patchman/patchman
git fetch --all
- name: Build deb packages (pre-release)
if: needs.setup.outputs.is_prerelease == 'true'
env:
EMAIL: furlongm@gmail.com
VERSION: ${{ needs.setup.outputs.version }}
run: |
echo "${VERSION}" > VERSION.txt
# Generate changelog for pre-release
cat > debian/changelog << EOF
patchman (${VERSION}-1) unstable; urgency=medium
* Pre-release ${VERSION}
-- Marcus Furlong <furlongm@gmail.com> $(date -R)
EOF
dpkg-buildpackage -us -uc -b
- name: Build deb packages (stable)
if: needs.setup.outputs.is_prerelease == 'false'
env:
EMAIL: furlongm@gmail.com
VERSION: ${{ needs.setup.outputs.version }}
run: |
# VERSION.txt and changelog already updated on main by update-version-and-changelog job
# Recreate tag to include those commits
git tag --delete v${VERSION}
git tag v${VERSION}
gbp buildpackage --git-upstream-tree=v${VERSION} -uc -us
- name: Upload deb assets
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.setup.outputs.version }}
files: |
../python3-patchman_${{ needs.setup.outputs.version }}-1_all.deb
../patchman-client_${{ needs.setup.outputs.version }}-1_all.deb
body: ""
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload-rpm-assets:
needs: [setup, create-release, update-version-and-changelog]
if: always() && needs.create-release.result == 'success'
runs-on: ubuntu-latest
container:
image: quay.io/centos/centos:stream10
steps:
- name: Install build dependencies
run: |
dnf -y install epel-release
dnf -y install rpm-build python3 python3-setuptools git
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && 'main' || github.ref }}
- name: git fetch --all
run: |
git config --global --add safe.directory /__w/patchman/patchman
git fetch --all
- name: Build rpm packages
env:
VERSION: ${{ needs.setup.outputs.rpm_version }}
run: |
echo "${VERSION}" > VERSION.txt
python3 setup.py bdist_rpm --python=/usr/bin/python3
rpmbuild -bb patchman-client.spec
- name: Upload rpm assets
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.setup.outputs.version }}
files: |
dist/patchman-${{ needs.setup.outputs.rpm_version }}-1.noarch.rpm
dist/noarch/patchman-client-${{ needs.setup.outputs.rpm_version }}-1.noarch.rpm
body: ""
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
upload-package-to-pypi:
needs: [setup, create-release]
if: needs.setup.outputs.is_prerelease == 'false'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Set version
run: |
echo "${{ needs.setup.outputs.version }}" > VERSION.txt
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 setup.py sdist bdist_wheel
twine upload dist/*