-
Notifications
You must be signed in to change notification settings - Fork 1
212 lines (173 loc) · 7.16 KB
/
Copy pathrelease.yml
File metadata and controls
212 lines (173 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Release
permissions:
contents: write
on:
push:
tags:
- 'v*'
workflow_dispatch: # For manual triggering
jobs:
release:
runs-on: ubuntu-latest
env:
BINARY_NAME: node-cleaner
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Important for GoReleaser to fetch all tags
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Add build targets
run: |
rustup target add x86_64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-musl
rustup target add aarch64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-musl
- name: Cache Cargo registry & index
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-${{ hashFiles('**/Cargo.lock') }}
# Install cross-compilation tools
- name: Install cross-compilation dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu musl-tools
# Install Zig for cross-compilation
- name: Install Zig
run: |
wget https://ziglang.org/download/0.10.0/zig-linux-x86_64-0.10.0.tar.xz
tar -xf zig-linux-x86_64-0.10.0.tar.xz
sudo mv zig-linux-x86_64-0.10.0 /opt/zig
sudo ln -s /opt/zig/zig /usr/local/bin/zig
rm -rf zig-linux-x86_64-0.10.0.tar.xz
zig version
- name: Install cargo-zigbuild
run: cargo install cargo-zigbuild
# Build static binaries
- name: Build static binaries
run: |
# x86_64 static binary
cargo zigbuild --release --target x86_64-unknown-linux-musl
# aarch64 static binary
cargo zigbuild --release --target aarch64-unknown-linux-musl
# List built binaries for debugging
find target/ -name "*" -type f -executable
ls -la target/x86_64-unknown-linux-musl/release/
ls -la target/aarch64-unknown-linux-musl/release/
# Create directories for packaging
- name: Prepare packaging directories
run: |
mkdir -p dist/bin
mkdir -p dist/deb/DEBIAN
mkdir -p dist/deb/usr/bin
mkdir -p dist/rpm
# Copy binaries
cp target/x86_64-unknown-linux-musl/release/$BINARY_NAME dist/bin/$BINARY_NAME-x86_64-linux
cp target/aarch64-unknown-linux-musl/release/$BINARY_NAME dist/bin/$BINARY_NAME-aarch64-linux
# Make binaries executable
chmod +x dist/bin/*
# Create Debian package
- name: Create Debian package
run: |
# Get version from tag or use Cargo.toml version
if [[ $GITHUB_REF == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
fi
# Extract package info from Cargo.toml
DESCRIPTION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].description')
AUTHORS=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].authors[0]')
REPOSITORY=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].repository')
echo "Building Debian package for version: $VERSION"
# Copy binary for deb package
cp target/x86_64-unknown-linux-musl/release/${BINARY_NAME} dist/deb/usr/bin/
# Create Debian control file
cat > dist/deb/DEBIAN/control << EOF
Package: ${BINARY_NAME}
Version: ${VERSION}
Section: utils
Priority: optional
Architecture: amd64
Maintainer: ${AUTHORS} <noreply@github.com>
Description: ${DESCRIPTION}
${DESCRIPTION}.
This utility helps developers clean up disk space by finding and
removing unused node_modules directories.
EOF
# Build the deb package
dpkg-deb --build dist/deb dist/${BINARY_NAME}_${VERSION}_amd64.deb
# Create RPM package
- name: Create RPM package
run: |
# Install rpm tools
sudo apt-get install -y rpm
# Get version from tag or use Cargo.toml version
if [[ $GITHUB_REF == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
fi
# Extract package info from Cargo.toml
DESCRIPTION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].description')
AUTHORS=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].authors[0]')
REPOSITORY=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].repository')
LICENSE=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].license')
echo "Building RPM package for version: $VERSION"
# Create RPM spec file
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cat > ~/rpmbuild/SPECS/${BINARY_NAME}.spec << EOF
Name: ${BINARY_NAME}
Version: ${VERSION}
Release: 1%{?dist}
Summary: ${DESCRIPTION}
License: ${LICENSE}
URL: ${REPOSITORY}
Source0: %{name}-%{version}.tar.gz
%description
${DESCRIPTION}.
This utility helps developers clean up disk space by finding and
removing unused node_modules directories.
%prep
%build
%install
mkdir -p %{buildroot}/usr/bin
cp $GITHUB_WORKSPACE/target/x86_64-unknown-linux-musl/release/${BINARY_NAME} %{buildroot}/usr/bin/
%files
/usr/bin/${BINARY_NAME}
%changelog
* $(date +'%a %b %d %Y') ${AUTHORS} <noreply@github.com> - ${VERSION}-1
- Automated build from version ${VERSION}
EOF
# Build RPM
rpmbuild -bb ~/rpmbuild/SPECS/${BINARY_NAME}.spec
cp ~/rpmbuild/RPMS/x86_64/${BINARY_NAME}-${VERSION}-1.*.rpm dist/
# Upload artifacts and create release
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
dist/*.deb
dist/*.rpm
dist/bin/*
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Publish to crates.io
- name: Publish to crates.io
if: startsWith(github.ref, 'refs/tags/v')
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}