diff --git a/.github/linters/.markdownlint.json b/.github/linters/.markdownlint.json new file mode 100644 index 0000000..de7f46b --- /dev/null +++ b/.github/linters/.markdownlint.json @@ -0,0 +1,12 @@ +{ + "MD013": { + "line_length": 120, + "code_blocks": false, + "tables": false + }, + "MD014": false, + "MD024": false, + "MD026": { + "punctuation": ".,:;!" + } +} diff --git a/.github/linters/check-links.yml b/.github/linters/check-links.yml new file mode 100644 index 0000000..8d8b815 --- /dev/null +++ b/.github/linters/check-links.yml @@ -0,0 +1,28 @@ +--- +name: Check links + +on: [push, pull_request] + +jobs: + markdown-link-check: + name: Check links using markdown-link-check + runs-on: ubuntu-latest + + steps: + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + uses: actions/checkout@v3 + with: + # Make sure the actual branch is checked out when running on PR + ref: ${{ github.event.pull_request.head.sha }} + # Full git history needed to get proper list of changed files + fetch-depth: 0 + + - name: Check links on new changes + uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + config-file: ".github/linters/mlc_config.json" + check-modified-files-only: "yes" + use-quiet-mode: "yes" + use-verbose-mode: "yes" + base-branch: "master" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cf4f693 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,79 @@ +--- +name: Create packages and test installation + +on: + pull_request: + +jobs: + centos7: + name: Build CentOS 7 RPMs + runs-on: ubuntu-latest + container: quay.io/centos/centos:7 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Install build requisites + run: | + yum install -y cmake rpm-build rpmlint make rsync + - name: build rpm + run: | + make rpm + - name: Upload rpms + uses: actions/upload-artifact@v3 + with: + name: rpms7 + path: | + build/RPMS/noarch/nagios-*.el7.noarch.rpm + + build-almalinux9: + name: Build AlmaLinux 9 RPMs + runs-on: ubuntu-latest + container: almalinux:9 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install build requisites + run: | + dnf install -y rpm-build cmake rpmlint make rsync systemd-rpm-macros + - name: build rpm + run: | + make rpm + - name: Upload RPMs + uses: actions/upload-artifact@v3 + with: + name: rpms9 + path: | + build/RPMS/noarch/nagios-*.el9.noarch.rpm + + centos7-install: + name: Install CentOS 7 RPMs + needs: centos7 + runs-on: ubuntu-latest + container: quay.io/centos/centos:7 + steps: + - uses: actions/download-artifact@v3 + with: + name: rpms7 + - name: Install generated RPMs + run: | + yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + yum install -y http://repository.egi.eu/sw/production/umd/4/centos7/x86_64/updates/umd-release-4.1.3-1.el7.centos.noarch.rpm + yum localinstall -y nagios-*.rpm + + install-almalinux9: + name: Install AlmaLinux 9 RPMs + needs: build-almalinux9 + runs-on: ubuntu-latest + container: almalinux:9 + steps: + - uses: actions/download-artifact@v3 + with: + name: rpms9 + - name: Install generated RPMs + run: | + # FIXME: remove external repo when UMD5 is available + dnf install -y epel-release + dnf localinstall -y https://github.com/EGI-Federation/nagios-plugins-srm/raw/master/python3-nap-0.1.21-2.el9.noarch.rpm + dnf localinstall -y nagios-*.rpm diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..86296fd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,110 @@ +--- +# When a tag is created +# - create a new release from the tag +# - build and attach packages to the release +name: Create packages and release + +on: + push: + tags: + - "v*" + +jobs: + centos7: + name: Build centOS 7 RPMs + runs-on: ubuntu-latest + container: centos:7 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: install build requisites + run: | + yum install -y rpm-build rpmlint make rsync + - name: build rpm + run: | + make rpm + rpmlint --file .rpmlint.ini build/RPMS/noarch/*.rpm + - name: Upload rpms + uses: actions/upload-artifact@v3 + with: + name: rpms7 + path: | + build/RPMS/noarch/nagios-*.el7.x86_64.rpm + build/SRPMS/nagios-*.el7.src.rpm + + almalinux9: + name: Build AlmaLinux 9 RPMs + runs-on: ubuntu-latest + container: almalinux:9 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install build requisites + run: | + dnf install -y rpm-build make rsync systemd-rpm-macros + - name: build rpm + run: | + make clean rpm + - name: Upload RPMs + uses: actions/upload-artifact@v4 + with: + name: rpms9 + path: | + build/RPMS/noarch/nagios-*.el9.x86_64.rpm + build/SRPMS/nagios-*.el9.src.rpm + + release7: + name: Upload CentOS 7 release artefacts + needs: centos7 + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + with: + name: rpms7 + + - name: Find package name + id: package_name_centos7 + run: | + rpm_path=$(find . -name 'nagios-*.el7.x86_64.rpm') + src_path=$(find . -name 'nagios-*.el7.src.rpm') + echo "rpm_path=${rpm_path}" >> "$GITHUB_OUTPUT" + echo "src_path=${src_path}" >> "$GITHUB_OUTPUT" + + - name: Attach CentOS 7 RPMs to the release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + fail_on_unmatched_files: true + files: | + ${{ steps.package_name_centos7.outputs.rpm_path }} + ${{ steps.package_name_centos7.outputs.src_path }} + + release9: + name: Upload AlmaLinux 9 release artefacts + permissions: + contents: write # to upload release asset (softprops/action-gh-release) + needs: almalinux9 + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: rpms9 + - name: Find package name + id: package_name_almalinux9 + run: | + rpm_path=$(find . -name 'nagios-*.el9.x86_64.rpm') + src_path=$(find . -name 'nagios-*.el9.src.rpm') + echo "rpm_path=${rpm_path}" >> "$GITHUB_OUTPUT" + echo "src_path=${src_path}" >> "$GITHUB_OUTPUT" + - name: Attach AlmaLinux 9 RPMs to the release + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + fail_on_unmatched_files: true + files: | + ${{ steps.package_name_almalinux9.outputs.rpm_path }} + ${{ steps.package_name_almalinux9.outputs.src_path }} diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 9d37c1a..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -project(nagios-plugins-srm NONE) - -# architecture detection -if(UNIX AND NOT WIN32) - if(CMAKE_SIZEOF_VOID_P MATCHES 4) - set (LIB_SUFFIX "") - set (PKG_ARCH "i386") - else(CMAKE_SIZEOF_VOID_P MATCHES 4) - set (LIB_SUFFIX 64) - set (PKG_ARCH "x86_64") - endif(CMAKE_SIZEOF_VOID_P MATCHES 4) -endif(UNIX AND NOT WIN32) - -add_subdirectory (plugins) - diff --git a/Makefile b/Makefile index 29628b4..90850f5 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,41 @@ -NAME=nagios-plugins-srm -SPEC=../$(NAME).spec -VERSION=${shell grep '^Version:' $(SPEC) | awk '{print $$2}' } -# Leave blank. To be overriden by CI tools. -RELEASE= +NAME= $(shell grep Name: *.spec | sed 's/^[^:]*:[^a-zA-Z]*//') +VERSION= $(shell grep Version: *.spec | sed 's/^[^:]*:[^0-9]*//') +RELEASE= $(shell grep Release: *.spec | cut -d"%" -f1 | sed 's/^[^:]*:[^0-9]*//') +build=$(shell pwd)/build +DATE=$(shell date "+%a, %d %b %Y %T %z") +dist=$(shell rpm --eval '%dist' | sed 's/%dist/.el5/') + +default: + @echo "Nothing to do" + +install: + @echo installing ... + +dist: + @mkdir -p $(build)/$(NAME)-$(VERSION)/ + rsync -HaS --exclude ".git" --exclude "$(build)" * $(build)/$(NAME)-$(VERSION)/ + cd $(build); tar --gzip -cf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)/; cd - + +sources: dist + cp $(build)/$(NAME)-$(VERSION).tar.gz . + +prepare: dist + @mkdir -p $(build)/RPMS/noarch + @mkdir -p $(build)/SRPMS/ + @mkdir -p $(build)/SPECS/ + @mkdir -p $(build)/SOURCES/ + @mkdir -p $(build)/BUILD/ + cp $(build)/$(NAME)-$(VERSION).tar.gz $(build)/SOURCES + cp $(NAME).spec $(build)/SPECS + +srpm: prepare + rpmbuild -bs --define="dist ${dist}" --define='_topdir ${build}' $(build)/SPECS/$(NAME).spec -CWD=${shell pwd} - -RPMBUILD=/tmp/rpmbuild -SRPMS=$(CWD) -RPMS=$(CWD)/out - -MOCK_CHROOT=epel-6-x86_64 -MOCK_FLAGS=--verbose - - -RPMDEFINES_SRC=--define='_topdir $(RPMBUILD)' \ - --define='_sourcedir $(CWD)' \ - --define='_builddir %{_topdir}/BUILD' \ - --define='_srcrpmdir $(SRPMS)' \ - --define='_rpmdir $(RPMS)' - -RPMDEFINES_BIN=--define='_topdir $(RPMBUILD)' \ - --define='_sourcedir %{_topdir}/SOURCES' \ - --define='_builddir %{_topdir}/BUILD' \ - --define='_srcrpmdir $(SRPMS).' \ - --define='_rpmdir $(RPMS)' - - -all: srpm +rpm: srpm + rpmbuild --rebuild --define='_topdir ${build}' --define="dist ${dist}" $(build)/SRPMS/$(NAME)-$(VERSION)-$(RELEASE)${dist}.src.rpm clean: - rm -fv *.tar.gz - rm -fv *.rpm - rm -fv *.log - rm -rfv out - rm -rfv "$(RPMBUILD)" - -dist: clean - tar vczf "$(NAME)-$(VERSION).tar.gz" --exclude="build" --exclude=".github" --exclude=".git" --exclude="*.pyc" --transform="s,^,$(NAME)-$(VERSION)/," .. - -$(RPMBUILD): - mkdir -p "$(RPMBUILD)" - -override_release: $(SPEC) - $(if $(RELEASE), sed -i "s/Release:.*/Release: $(RELEASE)/g" "$(SPEC)") - -srpm: dist $(SPEC) $(RPMBUILD) override_release - /usr/bin/rpmbuild --nodeps -bs $(RPMDEFINES_SRC) $(SPEC) - -rpm: srpm - /usr/bin/rpmbuild --rebuild $(RPMDEFINES_BIN) $(NAME)-$(VERSION)-*.src.rpm + rm -f *~ $(NAME)-$(VERSION).tar.gz + rm -rf $(build) -mock: srpm - /usr/bin/mock $(MOCK_FLAGS) -r $(MOCK_CHROOT) $(NAME)-$(VERSION)-*.src.rpm +.PHONY: dist srpm rpm sources clean diff --git a/nagios-plugins-srm.spec b/nagios-plugins-srm.spec index 365bd7a..260833b 100644 --- a/nagios-plugins-srm.spec +++ b/nagios-plugins-srm.spec @@ -17,7 +17,6 @@ Source0: %{name}-%{version}.tar.gz Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch -BuildRequires: cmake Requires: nagios Requires: python3 Requires: openldap-clients @@ -36,15 +35,12 @@ This package provides the nagios probes for SRM. %setup -q -n %{name}-%{version} %build -%cmake . -DCMAKE_INSTALL_PREFIX=/ -make %{?_smp_mflags} %install -rm -rf %{buildroot} -mkdir -p %{buildroot} - make install DESTDIR=%{buildroot} +mkdir -p %{buildroot}%{_libdir}/nagios/plugins/srm +cp --preserve=timestamps plugins/*.py %{buildroot}%{_libdir}/nagios/plugins/srm %clean rm -rf %{buildroot} diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt deleted file mode 100644 index 2849e2f..0000000 --- a/plugins/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -file (GLOB srm_probe *.py) - -install (FILES ${srm_probe} - DESTINATION usr/lib${LIB_SUFFIX}/nagios/plugins/srm/ - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ - GROUP_EXECUTE GROUP_READ - WORLD_EXECUTE WORLD_READ -) -