Skip to content

Commit

Permalink
feat: add RPM package build
Browse files Browse the repository at this point in the history
  • Loading branch information
petlack committed Jul 13, 2024
1 parent ae516f0 commit 9cbc582
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/rpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build RPM Package
on:
push:
tags:
- "v*.*.*"
jobs:
build:
runs-on: ubuntu-latest
container:
image: fedora:41
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install build tools and dependencies
run: |
dnf install -y git rpm-build sudo golang
- name: Setup environment
run: |
mkdir -p ${GITHUB_WORKSPACE}/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
- name: Copy necessary files to the build environment
run: |
cp *.go go.mod version.txt ${GITHUB_WORKSPACE}/rpmbuild/SOURCES/
cp .pkgs/rpm/SPECS/*.spec ${GITHUB_WORKSPACE}/rpmbuild/SPECS/
- name: Build the source tarball
run: |
cd ${GITHUB_WORKSPACE}/rpmbuild/SOURCES
tar -czf dotp-$(cat version.txt).tar.gz --transform "s,^,dotp-$(cat version.txt)/," *.go go.mod version.txt
- name: Build RPM Package
run: |
cd ${GITHUB_WORKSPACE}/rpmbuild
rpmbuild -ba \
--define "_topdir ${GITHUB_WORKSPACE}/rpmbuild" \
--define "_sourcedir ${GITHUB_WORKSPACE}/rpmbuild/SOURCES" \
SPECS/*.spec
- name: Setup artifact path
run: |
rpm_path=$(find ${GITHUB_WORKSPACE}/rpmbuild/RPMS -type f -name "*.rpm" | head -n1)
echo "RPM_PATH=$rpm_path" >> $GITHUB_ENV
echo "RPM_NAME=$(basename $rpm_path)" >> $GITHUB_ENV
- name: Upload RPM to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.RPM_PATH }}
asset_name: ${{ env.RPM_NAME }}
tag: ${{ github.ref }}
overwrite: true
- name: Upload RPM Package
uses: actions/upload-artifact@v3
with:
name: rpm-packages
path: /home/builder/rpmbuild/RPMS/x86_64/*.rpm
permissions:
contents: write
31 changes: 31 additions & 0 deletions .pkgs/rpm.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM fedora:41 AS builder

RUN dnf install -y git rpm-build sudo golang

RUN useradd -m builder && \
echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

WORKDIR /home/builder

RUN mkdir -p /home/builder/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} && \
chown -R builder:builder /home/builder

USER builder

COPY *.go go.mod version.txt /home/builder/rpmbuild/SOURCES/
COPY .pkgs/rpm/SPECS/*.spec /home/builder/rpmbuild/SPECS/

WORKDIR /home/builder/rpmbuild/SOURCES

RUN tar -czf dotp-$(cat version.txt).tar.gz \
--transform "s,^,dotp-$(cat version.txt)/," \
*.go go.mod version.txt

WORKDIR /home/builder/rpmbuild

RUN rpmbuild -ba SPECS/*.spec

FROM scratch
WORKDIR /pkg
COPY --from=builder /home/builder/rpmbuild/RPMS/x86_64/*.rpm .
ENTRYPOINT ["dotp"]
36 changes: 36 additions & 0 deletions .pkgs/rpm/SPECS/dotp.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Name: dotp
Version: 0.0.1.20240712.02
Release: 1%{?dist}
Summary: Command-line tool for managing Time-based One-Time Passwords (TOTPs)

License: GPL-3.0-or-later
URL: https://github.com/petlack/dotp
Source: %{name}-%{version}.tar.gz

BuildRequires: go

%global debug_package %{nil} # Disable automatic debuginfo package generation

%description
%{summary}

%prep
%autosetup -n %{name}-%{version}

%build
export GOOS=linux
go version
go build -a -ldflags="-linkmode=external" -o build/%{name} .

%install
install -Dm755 build/%{name} %{buildroot}%{_bindir}/%{name}

%check
go test ./...

%files
%{_bindir}/%{name}

%changelog
* Fri Jul 12 2024 John Doe <email@example.com> - %{version}-%{release}
- Initial RPM release

0 comments on commit 9cbc582

Please sign in to comment.