Skip to content

Commit 0386ea6

Browse files
author
Brean
committed
fix: Refactor release workflow to use BINARY_NAME variable and extract package info from Cargo.toml
1 parent 69030ea commit 0386ea6

1 file changed

Lines changed: 35 additions & 21 deletions

File tree

.github/workflows/release.yml

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
jobs:
1313
release:
1414
runs-on: ubuntu-latest
15+
env:
16+
BINARY_NAME: node-cleaner
1517

1618
steps:
1719
- uses: actions/checkout@v4
@@ -85,9 +87,6 @@ jobs:
8587
mkdir -p dist/deb/usr/bin
8688
mkdir -p dist/rpm
8789
88-
# Replace 'your-actual-binary-name' with the actual binary name
89-
BINARY_NAME="node-cleaner"
90-
9190
# Copy binaries
9291
cp target/x86_64-unknown-linux-musl/release/$BINARY_NAME dist/bin/$BINARY_NAME-x86_64-linux
9392
cp target/aarch64-unknown-linux-musl/release/$BINARY_NAME dist/bin/$BINARY_NAME-aarch64-linux
@@ -101,23 +100,30 @@ jobs:
101100
# Get version from tag
102101
VERSION=${GITHUB_REF#refs/tags/v}
103102
103+
# Extract package info from Cargo.toml
104+
DESCRIPTION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].description')
105+
AUTHORS=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].authors[0]')
106+
REPOSITORY=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].repository')
107+
104108
# Copy binary for deb package
105-
cp target/x86_64-unknown-linux-musl/release/rust-cli dist/deb/usr/bin/
109+
cp target/x86_64-unknown-linux-musl/release/${BINARY_NAME} dist/deb/usr/bin/
106110
107111
# Create Debian control file
108112
cat > dist/deb/DEBIAN/control << EOF
109-
Package: rust-cli
113+
Package: ${BINARY_NAME}
110114
Version: ${VERSION}
111115
Section: utils
112116
Priority: optional
113117
Architecture: amd64
114-
Maintainer: Your Name <your.email@example.com>
115-
Description: Your Rust CLI application
116-
A description of your CLI tool.
118+
Maintainer: ${AUTHORS} <noreply@github.com>
119+
Description: ${DESCRIPTION}
120+
${DESCRIPTION}.
121+
This utility helps developers clean up disk space by finding and
122+
removing unused node_modules directories.
117123
EOF
118124
119125
# Build the deb package
120-
dpkg-deb --build dist/deb dist/rust-cli_${VERSION}_amd64.deb
126+
dpkg-deb --build dist/deb dist/${BINARY_NAME}_${VERSION}_amd64.deb
121127
122128
# Create RPM package
123129
- name: Create RPM package
@@ -128,41 +134,49 @@ jobs:
128134
# Get version from tag
129135
VERSION=${GITHUB_REF#refs/tags/v}
130136
137+
# Extract package info from Cargo.toml
138+
DESCRIPTION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].description')
139+
AUTHORS=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].authors[0]')
140+
REPOSITORY=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].repository')
141+
LICENSE=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].license')
142+
131143
# Create RPM spec file
132144
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
133145
134-
cat > ~/rpmbuild/SPECS/rust-cli.spec << EOF
135-
Name: rust-cli
146+
cat > ~/rpmbuild/SPECS/${BINARY_NAME}.spec << EOF
147+
Name: ${BINARY_NAME}
136148
Version: ${VERSION}
137149
Release: 1%{?dist}
138-
Summary: Your Rust CLI application
150+
Summary: ${DESCRIPTION}
139151
140-
License: MIT
141-
URL: https://github.com/${{ github.repository }}
152+
License: ${LICENSE}
153+
URL: ${REPOSITORY}
142154
Source0: %{name}-%{version}.tar.gz
143155
144156
%description
145-
A description of your CLI tool.
157+
${DESCRIPTION}.
158+
This utility helps developers clean up disk space by finding and
159+
removing unused node_modules directories.
146160
147161
%prep
148162
149163
%build
150164
151165
%install
152166
mkdir -p %{buildroot}/usr/bin
153-
cp $GITHUB_WORKSPACE/target/x86_64-unknown-linux-musl/release/rust-cli %{buildroot}/usr/bin/
167+
cp $GITHUB_WORKSPACE/target/x86_64-unknown-linux-musl/release/${BINARY_NAME} %{buildroot}/usr/bin/
154168
155169
%files
156-
/usr/bin/rust-cli
170+
/usr/bin/${BINARY_NAME}
157171
158172
%changelog
159-
* $(date +'%a %b %d %Y') GitHub Actions <noreply@github.com> - ${VERSION}-1
160-
- Automated build
173+
* $(date +'%a %b %d %Y') ${AUTHORS} <noreply@github.com> - ${VERSION}-1
174+
- Automated build from version ${VERSION}
161175
EOF
162176
163177
# Build RPM
164-
rpmbuild -bb ~/rpmbuild/SPECS/rust-cli.spec
165-
cp ~/rpmbuild/RPMS/x86_64/rust-cli-${VERSION}-1.*.rpm dist/
178+
rpmbuild -bb ~/rpmbuild/SPECS/${BINARY_NAME}.spec
179+
cp ~/rpmbuild/RPMS/x86_64/${BINARY_NAME}-${VERSION}-1.*.rpm dist/
166180
167181
# Create release with GoReleaser
168182
- name: Run GoReleaser

0 commit comments

Comments
 (0)