File forgejo-runner.spec of Package forgejo-runner
%define realname runner
%define srcext tar.gz
%define runner_group runner
%define runner_user runner
%define runner_home %{_localstatedir}/lib/forgejo-runner
# Common info
Name: forgejo-runner
Version: 11.2.0
Release: wiz%{?extraver:0.}1%{?dist}
License: MIT
Group: Development/Tools/Version Control
URL: https://code.forgejo.org/forgejo/runner
Summary: Forgejo Actions runner
# Build-time parameters
BuildRequires: go >= 1.23.10
Source0: https://code.forgejo.org/forgejo/runner/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
# cd runner; go mod vendor -v && tar -Jcvf ../vendor.tar.xz vendor && rm -rf vendor/; cd ..
Source1: vendor.tar.xz
%description
Forgejo Actions provides continuous integration driven from the files found in
the .forgejo/workflows directory of a repository.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname} -a1
# Set default confuration file
%{__sed} -ri \
-e '/^\s+configFile :=/ s|""|"%{_sysconfdir}/%{name}/config.yaml"|' \
internal/app/cmd/cmd.go
# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
export GOPATH=$(pwd -P)/.gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS -DSQLITE_MAX_VARIABLE_NUMBER=32766"
export CGO_LDFLAGS="$_LDFLAGS"
go build -v -mod=vendor -buildmode=pie \
-gcflags='-dwarf=false' \
-ldflags="-s -w -X runner.forgejo.org/internal/pkg/ver.version=v%{version} -linkmode=external -extldflags \"$_LDFLAGS\"" \
-o %{name}
# Install built stuff
%install
%{__install} -d -m0755 %{buildroot}%{_bindir}
%{__install} -d -m0755 %{buildroot}%{_unitdir}
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/%{name}
%{__install} -d -m0755 %{buildroot}%{runner_home}/workdir
%{__install} -m0755 %{name} %{buildroot}%{_bindir}/%{name}
# Config
./forgejo-runner generate-config \
| %{__sed} -r \
-e 's|file: .runner|file: %{runner_home}/.runner|' \
-e 's|dir: ""|dir: %{runner_home}|' \
-e '/^host:/,$ s|workdir_parent:.*$|workdir_parent: %{runner_home}/workdir|' \
> %{buildroot}%{_sysconfdir}/%{name}/config.yaml
# systemd unit file
%{__sed} -r \
-e 's|^(ExecStart=).*$|\1%{_bindir}/forgejo-runner daemon --config %{_sysconfdir}/%{name}/config.yaml|' \
-e 's|^(User=).*$|\1%{runner_user}|' \
-e 's|^(WorkingDirectory=).*$|\1%{runner_home}|' \
contrib/forgejo-runner.service > %{buildroot}%{_unitdir}/forgejo-runner.service
# Files list
%files
%defattr(-,root,root)
%license LICENSE
%doc README.md RELEASE-NOTES.md
%{_bindir}/forgejo-runner
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/config.yaml
%{_unitdir}/forgejo-runner.service
%attr(-,%{runner_user},%{runner_group}) %{runner_home}
%pre
/usr/sbin/groupadd -r %{runner_group} &>/dev/null ||:
/usr/sbin/useradd -g %{runner_group} -s /bin/false -r -M \
-c "Forgejo runner user" -d %{runner_home} %{runner_user} &>/dev/null ||:
%if "%{expand:%_vendor}" == "suse"
%{service_add_pre forgejo-runner.service}
%endif
%if "%{expand:%_vendor}" == "suse"
%post
%{service_add_post forgejo-runner.service}
%preun
%{service_del_preun forgejo-runner.service}
%postun
%{service_del_postun forgejo-runner.service}
%endif
%changelog