# Do not try to package empty debug_package
%global debug_package %{nil}

Name:          forgejo-runner
Version:       5.0.4
Release:       1%{?dist}
Summary:       A daemon for Forgejo instances that runs jobs for continuous integration

License:       Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND CC-BY-SA-4.0 AND ISC AND MIT
URL:           https://code.forgejo.org/forgejo/runner/archive/v%{version}.tar.gz
Source0:       runner-v%{version}.tar.gz
Source1:       runner-v%{version}-vendor.tar.gz

Source3:       config.yml

BuildRequires: golang >= 1.22
%if 0%{?fedora} || 0%{?rhel} >= 9
BuildRequires: go-rpm-macros
%endif

Requires:      openssl-libs
Recommends:    container-tools


%description
The Forgejo runner is a daemon that fetches work-flows to run from
a Forgejo instance, executes them, sends back with the logs and
ultimately reports its success or failure.


%prep
%setup -T -b 0 -a 1 -q -n runner

%build
# Workaround OS's update cycle
sed -i s/go\ 1.23/go\ 1.22/ go.mod
export CGO_CPPFLAGS="${CPPFLAGS} -D_FORTIFY_SOURCE=2 -fstack-protector-all"
export CGO_CFLAGS="${CFLAGS}"
export CGO_CXXFLAGS="${CXXFLAGS}"
export CGO_LDFLAGS="${LDFLAGS} -s -w"
go build \
    -trimpath \
    -buildmode=pie \
    -mod=vendor \
    -modcacherw \
    -ldflags "-linkmode=external -X gitea.com/gitea/act_runner/internal/pkg/ver.version=v%{version}" -o %{name}


%install
mkdir -p %{buildroot}%{_bindir}
install -m 0755 %{name} %{buildroot}%{_bindir}/%{name}
mkdir -p %{buildroot}%{_sysconfdir}/%{name}/
install -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/%{name}/config.yml
install -m 0644 internal/pkg/config/config.example.yaml %{buildroot}%{_sysconfdir}/%{name}/config.dist.yml


%verifyscript
%{_bindir}/forgejo-runner --version


%files
%doc RELEASE-NOTES.md README.md 
%license LICENSE vendor/modules.txt
%{_bindir}/%{name}
%dir %{_sysconfdir}/%{name}
%{_sysconfdir}/%{name}/config.yml
%{_sysconfdir}/%{name}/config.dist.yml


%changelog
* Sat Dec 21 2024 Builder <builder@localhost> - 5.0.4-1
- Update to 5.0.4