Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move debian package generation to a dispatch only workflow #2543

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build_deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Debian Package

on: workflow_dispatch

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Build Debian Package
working-directory: ./packages/deb
run: ./setup.sh "$(git describe --tags --abbrev=0)"

- name: Run sanity checks on the Debian package
working-directory: ./packages/deb
run: |
./check_capstone.sh ./libcapstone-dev.deb "$(git describe --tags --abbrev=0)"

- uses: actions/upload-artifact@v4
with:
path: ./packages/deb/libcapstone-dev.deb
25 changes: 1 addition & 24 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,8 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true

- name: Make setup.sh and check_capstone.sh are executable
run: |
chmod +x debian/setup.sh
chmod +x debian/check_capstone.sh

- name: Build Debian Package
working-directory: ./debian
run: ./setup.sh ${{ github.event.release.tag_name }}

- name: Run sanity checks on the Debian package
working-directory: ./debian
run: |
./check_capstone.sh ./libcapstone-dev.deb ${{ github.event.release.tag_name }}

- name: Upload debian package to release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.release.tag_name }}
files: |
./debian/*.deb

- name: archive
- name: Create archive
id: archive
run: |
VERSION=${{ github.event.release.tag_name }}
Expand Down
6 changes: 0 additions & 6 deletions debian/postinst

This file was deleted.

File renamed without changes.
38 changes: 15 additions & 23 deletions debian/Dockerfile → packages/deb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
ARG VERSION=""

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

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

# Copy your project files into the container
# Copy project files into the container
RUN mkdir /capstone
COPY . /capstone
WORKDIR /capstone/
WORKDIR /capstone/

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

# Run cmake install, by default everything goes into /usr/local
RUN cmake --install build
# Make directories as needed
RUN mkdir -p /package-root/usr/include/capstone/
RUN mkdir -p /package-root/usr/lib/pkgconfig/
RUN mkdir -p /package-root/usr/bin/

# Run cmake install
RUN cmake --install build --prefix /package-root/usr/

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

# Make directories as needed
RUN mkdir -p /package-root/usr/local/include/capstone/
RUN mkdir -p /package-root/usr/local/lib/pkgconfig/
RUN mkdir -p /package-root/usr/local/bin/

# Copy /usr/local/include/capstone/ to /package-root/usr/local/include/capstone/ and all other cases
RUN cp -r /usr/local/include/capstone/* /package-root/usr/local/include/capstone/
RUN cp -r /usr/local/lib/libcapstone* /package-root/usr/local/lib/
RUN cp -r /usr/local/lib/pkgconfig/capstone* /package-root/usr/local/lib/pkgconfig/
RUN cp -r /usr/local/bin/cstool /package-root/usr/local/bin/

# Create DEBIAN directory and control file
COPY ./debian/control /package-root/DEBIAN/control
COPY ./packages/deb/control /package-root/DEBIAN/control

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

# Add postinst script to run ldconfig after installation
COPY ./debian/postinst /package-root/DEBIAN/postinst
RUN chmod 755 /package-root/DEBIAN/postinst
# Add triggers script to run ldconfig after installation
COPY ./packages/deb/triggers /package-root/DEBIAN/triggers

# Build the package
RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev.deb
Expand Down
7 changes: 7 additions & 0 deletions packages/deb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Incomplete Debian package implementation.
It can be used to generate an easily installable Capstone, but misses a lot of
mandatory things to add it in the Debian repos (`debian/control` is incomplete, no dependencies added etc.).

You can build the package by dispatching the `Build Debian Package` workflow or executing the commands in the `Dockerfile`.
It assumes the current commit is tagged and `"$(git describe --tags --abbrev=0)"` returns a valid version number.
The package is uploaded as artifact.
8 changes: 4 additions & 4 deletions debian/check_capstone.sh → packages/deb/check_capstone.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEMP_DIR=$(mktemp -d)
dpkg-deb -x "$DEB_FILE" "$TEMP_DIR"

# Path to the capstone.pc file
CAPSTONE_PC="$TEMP_DIR/usr/local/lib/pkgconfig/capstone.pc"
CAPSTONE_PC="$TEMP_DIR/usr/lib/pkgconfig/capstone.pc"

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

# Check if libcapstone.a is included in the package
LIBCAPSTONE_A="$TEMP_DIR/usr/local/lib/libcapstone.a"
LIBCAPSTONE_A="$TEMP_DIR/usr/lib/libcapstone.a"
if [[ ! -f "$LIBCAPSTONE_A" ]]; then
echo "libcapstone.a not found in the package!"
rm -rf "$TEMP_DIR"
exit 1
fi

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

echo "libcapstone-dev.deb file is correct."
rm -rf "$TEMP_DIR"
exit 0
exit 0
File renamed without changes.
12 changes: 6 additions & 6 deletions debian/setup.sh → packages/deb/setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ get_os_version() {
lsb_release -i -s 2>/dev/null
}

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

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

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

# Copy deb file out of container to host
Expand All @@ -50,4 +50,4 @@ docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"
# Check which files existed before and after 'make install' was executed.
# docker run --rm -v $(pwd):/out packager bash -c "cp /before-install.txt /out"
# docker run --rm -v $(pwd):/out packager bash -c "cp /after-install.txt /out"
# diff before-install.txt after-install.txt
# diff before-install.txt after-install.txt
2 changes: 2 additions & 0 deletions packages/deb/triggers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Trigger ldconfig after install
activate-noawait ldconfig
Loading