Skip to content

Commit e3bc578

Browse files
authored
Move debian package generation to a dispatch only workflow (#2543)
* Move deb package gen files int package/deb * Fix basename check * Make debian package generation dispatch only
1 parent abbf32b commit e3bc578

File tree

10 files changed

+61
-63
lines changed

10 files changed

+61
-63
lines changed

.github/workflows/build_deb.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build Debian Package
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
build:
7+
name: build
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
submodules: true
14+
15+
- name: Build Debian Package
16+
working-directory: ./packages/deb
17+
run: ./setup.sh "$(git describe --tags --abbrev=0)"
18+
19+
- name: Run sanity checks on the Debian package
20+
working-directory: ./packages/deb
21+
run: |
22+
./check_capstone.sh ./libcapstone-dev.deb "$(git describe --tags --abbrev=0)"
23+
24+
- uses: actions/upload-artifact@v4
25+
with:
26+
path: ./packages/deb/libcapstone-dev.deb

.github/workflows/build_release.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,8 @@ jobs:
1414
- uses: actions/checkout@v4
1515
with:
1616
submodules: true
17-
18-
- name: Make setup.sh and check_capstone.sh are executable
19-
run: |
20-
chmod +x debian/setup.sh
21-
chmod +x debian/check_capstone.sh
22-
23-
- name: Build Debian Package
24-
working-directory: ./debian
25-
run: ./setup.sh ${{ github.event.release.tag_name }}
26-
27-
- name: Run sanity checks on the Debian package
28-
working-directory: ./debian
29-
run: |
30-
./check_capstone.sh ./libcapstone-dev.deb ${{ github.event.release.tag_name }}
31-
32-
- name: Upload debian package to release
33-
uses: softprops/action-gh-release@v2
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
with:
37-
tag_name: ${{ github.event.release.tag_name }}
38-
files: |
39-
./debian/*.deb
4017

41-
- name: archive
18+
- name: Create archive
4219
id: archive
4320
run: |
4421
VERSION=${{ github.event.release.tag_name }}

debian/postinst

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

debian/Dockerfile renamed to packages/deb/Dockerfile

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
ARG VERSION=""
22

3-
# Assume this is run from capstone/debian directory
43
# Run in the root of the repo
5-
# docker build -f ./debian/Dockerfile -t packager .
4+
# docker build -f ./packages/deb/Dockerfile -t packager .
65
FROM debian:bookworm-slim
76

87
# Install necessary tools for packaging
98
RUN apt-get -qq update && \
109
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \
1110
fakeroot dpkg-dev dos2unix cmake
1211

13-
# Copy your project files into the container
12+
# Copy project files into the container
1413
RUN mkdir /capstone
1514
COPY . /capstone
16-
WORKDIR /capstone/
15+
WORKDIR /capstone/
1716

1817
# Using cmake, see BUILDING.md file
1918
# For debug build change "Release" to "Debug"
@@ -23,36 +22,29 @@ RUN cmake --build build
2322
# List files before cmake install
2423
# RUN find / -type f > /before-install.txt
2524

26-
# Run cmake install, by default everything goes into /usr/local
27-
RUN cmake --install build
25+
# Make directories as needed
26+
RUN mkdir -p /package-root/usr/include/capstone/
27+
RUN mkdir -p /package-root/usr/lib/pkgconfig/
28+
RUN mkdir -p /package-root/usr/bin/
29+
30+
# Run cmake install
31+
RUN cmake --install build --prefix /package-root/usr/
2832

2933
# List files after cmake install
3034
# RUN find / -type f > /after-install.txt
3135

32-
# Make directories as needed
33-
RUN mkdir -p /package-root/usr/local/include/capstone/
34-
RUN mkdir -p /package-root/usr/local/lib/pkgconfig/
35-
RUN mkdir -p /package-root/usr/local/bin/
36-
37-
# Copy /usr/local/include/capstone/ to /package-root/usr/local/include/capstone/ and all other cases
38-
RUN cp -r /usr/local/include/capstone/* /package-root/usr/local/include/capstone/
39-
RUN cp -r /usr/local/lib/libcapstone* /package-root/usr/local/lib/
40-
RUN cp -r /usr/local/lib/pkgconfig/capstone* /package-root/usr/local/lib/pkgconfig/
41-
RUN cp -r /usr/local/bin/cstool /package-root/usr/local/bin/
42-
4336
# Create DEBIAN directory and control file
44-
COPY ./debian/control /package-root/DEBIAN/control
37+
COPY ./packages/deb/control /package-root/DEBIAN/control
4538

4639
# Update capstone.pc file with the correct version and remove archs field
4740
# Update control file with the correct version
4841
ARG VERSION
4942
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/DEBIAN/control
50-
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/local/lib/pkgconfig/capstone.pc
51-
RUN sed -i "/^archs=/d" /package-root/usr/local/lib/pkgconfig/capstone.pc
43+
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/lib/pkgconfig/capstone.pc
44+
RUN sed -i "/^archs=/d" /package-root/usr/lib/pkgconfig/capstone.pc
5245

53-
# Add postinst script to run ldconfig after installation
54-
COPY ./debian/postinst /package-root/DEBIAN/postinst
55-
RUN chmod 755 /package-root/DEBIAN/postinst
46+
# Add triggers script to run ldconfig after installation
47+
COPY ./packages/deb/triggers /package-root/DEBIAN/triggers
5648

5749
# Build the package
5850
RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev.deb

packages/deb/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Incomplete Debian package implementation.
2+
It can be used to generate an easily installable Capstone, but misses a lot of
3+
mandatory things to add it in the Debian repos (`debian/control` is incomplete, no dependencies added etc.).
4+
5+
You can build the package by dispatching the `Build Debian Package` workflow or executing the commands in the `Dockerfile`.
6+
It assumes the current commit is tagged and `"$(git describe --tags --abbrev=0)"` returns a valid version number.
7+
The package is uploaded as artifact.

debian/check_capstone.sh renamed to packages/deb/check_capstone.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TEMP_DIR=$(mktemp -d)
1818
dpkg-deb -x "$DEB_FILE" "$TEMP_DIR"
1919

2020
# Path to the capstone.pc file
21-
CAPSTONE_PC="$TEMP_DIR/usr/local/lib/pkgconfig/capstone.pc"
21+
CAPSTONE_PC="$TEMP_DIR/usr/lib/pkgconfig/capstone.pc"
2222

2323
# Check if the capstone.pc file exists
2424
if [[ ! -f "$CAPSTONE_PC" ]]; then
@@ -48,15 +48,15 @@ if [[ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]]; then
4848
fi
4949

5050
# Check if libcapstone.a is included in the package
51-
LIBCAPSTONE_A="$TEMP_DIR/usr/local/lib/libcapstone.a"
51+
LIBCAPSTONE_A="$TEMP_DIR/usr/lib/libcapstone.a"
5252
if [[ ! -f "$LIBCAPSTONE_A" ]]; then
5353
echo "libcapstone.a not found in the package!"
5454
rm -rf "$TEMP_DIR"
5555
exit 1
5656
fi
5757

5858
# Check if libcapstone.so is included in the package
59-
LIBCAPSTONE_SO="$TEMP_DIR/usr/local/lib/libcapstone.so"
59+
LIBCAPSTONE_SO="$TEMP_DIR/usr/lib/libcapstone.so"
6060
if [[ ! -f "$LIBCAPSTONE_SO" ]]; then
6161
echo "libcapstone.so not found in the package!"
6262
rm -rf "$TEMP_DIR"
@@ -65,4 +65,4 @@ fi
6565

6666
echo "libcapstone-dev.deb file is correct."
6767
rm -rf "$TEMP_DIR"
68-
exit 0
68+
exit 0
File renamed without changes.

debian/setup.sh renamed to packages/deb/setup.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ get_os_version() {
66
lsb_release -i -s 2>/dev/null
77
}
88

9-
# Check if the script is running in the ./debian folder
10-
if [[ $(basename "$PWD") != "debian" ]]; then
11-
echo "ERROR: Script must be run from the ./debian directory"
9+
# Check if the script is running in the ./packages/deb folder
10+
if [[ $(basename "$PWD") != "deb" ]]; then
11+
echo "ERROR: Script must be run from the ./deb directory"
1212
exit 1
1313
fi
1414

@@ -40,8 +40,8 @@ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
4040
fi
4141

4242
# Now build the packager container from that
43-
pushd ../
44-
docker build -f ./debian/Dockerfile -t packager --build-arg VERSION="${version}" .
43+
pushd ../../
44+
docker build -f ./packages/deb/Dockerfile -t packager --build-arg VERSION="${version}" .
4545
popd
4646

4747
# Copy deb file out of container to host
@@ -50,4 +50,4 @@ docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"
5050
# Check which files existed before and after 'make install' was executed.
5151
# docker run --rm -v $(pwd):/out packager bash -c "cp /before-install.txt /out"
5252
# docker run --rm -v $(pwd):/out packager bash -c "cp /after-install.txt /out"
53-
# diff before-install.txt after-install.txt
53+
# diff before-install.txt after-install.txt

packages/deb/triggers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Trigger ldconfig after install
2+
activate-noawait ldconfig

0 commit comments

Comments
 (0)