fix(release): build RPM from pre-compiled binary with injected version
rpmbuild's %build shell cannot reliably access the Go toolchain or module cache, risking a 'dev' version string. Build the binary on the runner (where setup-go is active) with the correct -X main.version ldflags, then package it via rpmbuild as a binary-install RPM. Spec changes: Source0/1 are now the binary and LICENSE; %install copies them directly; removed %prep/%build; -bb instead of -ba (no source RPM). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -159,8 +159,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
@@ -174,15 +172,19 @@ jobs:
|
|||||||
|
|
||||||
sudo apt-get install -y rpm
|
sudo apt-get install -y rpm
|
||||||
|
|
||||||
git archive --format=tar.gz --prefix=pgtidy-${PKGVER}/ HEAD \
|
CGO_ENABLED=0 go build \
|
||||||
> pgtidy-${PKGVER}.tar.gz
|
-trimpath \
|
||||||
|
-ldflags "-X main.version=${PKGVER}" \
|
||||||
|
-o pgtidy \
|
||||||
|
./cmd/pgtidy
|
||||||
|
|
||||||
sed -i "s/^Version:.*/Version: ${PKGVER}/" linux/centos/pgtidy.spec
|
sed -i "s/^Version:.*/Version: ${PKGVER}/" linux/centos/pgtidy.spec
|
||||||
|
|
||||||
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
||||||
cp pgtidy-${PKGVER}.tar.gz ~/rpmbuild/SOURCES/
|
cp pgtidy ~/rpmbuild/SOURCES/pgtidy
|
||||||
|
cp LICENSE ~/rpmbuild/SOURCES/LICENSE
|
||||||
cp linux/centos/pgtidy.spec ~/rpmbuild/SPECS/
|
cp linux/centos/pgtidy.spec ~/rpmbuild/SPECS/
|
||||||
rpmbuild --nodeps -ba ~/rpmbuild/SPECS/pgtidy.spec
|
rpmbuild --nodeps -bb ~/rpmbuild/SPECS/pgtidy.spec
|
||||||
|
|
||||||
mkdir -p rpm-out
|
mkdir -p rpm-out
|
||||||
find ~/rpmbuild/RPMS/ -name '*.rpm' -exec cp {} rpm-out/ \;
|
find ~/rpmbuild/RPMS/ -name '*.rpm' -exec cp {} rpm-out/ \;
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ Summary: PostgreSQL SQL formatter and linter
|
|||||||
|
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://git.warky.dev/wdevs/pgtidy
|
URL: https://git.warky.dev/wdevs/pgtidy
|
||||||
Source0: %{name}-%{version}.tar.gz
|
Source0: pgtidy
|
||||||
|
Source1: LICENSE
|
||||||
BuildRequires: golang >= 1.26
|
ExclusiveArch: x86_64
|
||||||
|
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
%define _debugsource_packages 0
|
%define _debugsource_packages 0
|
||||||
@@ -17,24 +17,15 @@ BuildRequires: golang >= 1.26
|
|||||||
PgTidy formats and lints PostgreSQL SQL, enforcing a consistent style
|
PgTidy formats and lints PostgreSQL SQL, enforcing a consistent style
|
||||||
for migrations, schemas, functions, procedures, and triggers.
|
for migrations, schemas, functions, procedures, and triggers.
|
||||||
|
|
||||||
%prep
|
|
||||||
%autosetup
|
|
||||||
|
|
||||||
%build
|
|
||||||
export CGO_ENABLED=0
|
|
||||||
go build \
|
|
||||||
-trimpath \
|
|
||||||
-ldflags "-X main.version=%{version}" \
|
|
||||||
-o %{name} ./cmd/pgtidy
|
|
||||||
|
|
||||||
%install
|
%install
|
||||||
install -Dm755 %{name} %{buildroot}%{_bindir}/%{name}
|
install -Dm755 %{SOURCE0} %{buildroot}%{_bindir}/%{name}
|
||||||
install -Dm644 LICENSE %{buildroot}%{_licensedir}/%{name}/LICENSE
|
mkdir -p %{buildroot}%{_datadir}/licenses/%{name}
|
||||||
|
install -m644 %{SOURCE1} %{buildroot}%{_datadir}/licenses/%{name}/LICENSE
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%license LICENSE
|
|
||||||
%{_bindir}/%{name}
|
%{_bindir}/%{name}
|
||||||
|
%{_datadir}/licenses/%{name}/LICENSE
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Sun Jun 29 2026 Hein (Warky Devs) <hein@warky.dev> - 0.1.0-1
|
* Sun Jun 29 2026 Hein (Warky Devs) <hein@warky.dev> - 0.0.1-1
|
||||||
- Initial package
|
- Initial package
|
||||||
|
|||||||
Reference in New Issue
Block a user