Skip to content

Commit c4b1585

Browse files
build common deb in submodule
1 parent 4816090 commit c4b1585

1 file changed

Lines changed: 245 additions & 0 deletions

File tree

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
name: Build Common Deb
2+
3+
# Runs in https://github.com/fiveages-sim/robot-descriptions-common — repo root is the colcon workspace (no parent submodule).
4+
5+
on:
6+
push:
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
inputs:
11+
tag:
12+
description: Release tag to upload the deb asset to
13+
required: false
14+
type: string
15+
ros_distro:
16+
description: ROS distro used in the install path
17+
required: false
18+
default: jazzy
19+
type: string
20+
21+
permissions:
22+
contents: write
23+
24+
jobs:
25+
build-common-deb:
26+
runs-on: ubuntu-24.04
27+
env:
28+
PACKAGE_NAME: robot-descriptions-jazzy-common
29+
DEB_FILE_PREFIX: robot-descriptions-jazzy-common
30+
INSTALL_PREFIX: /opt/ros/jazzy
31+
DEFAULT_ROS_DISTRO: jazzy
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Resolve release metadata
40+
id: meta
41+
shell: bash
42+
env:
43+
INPUT_TAG: ${{ github.event.inputs.tag }}
44+
INPUT_ROS_DISTRO: ${{ github.event.inputs.ros_distro }}
45+
run: |
46+
set -eo pipefail
47+
48+
if [[ -n "${INPUT_TAG:-}" ]]; then
49+
tag="$INPUT_TAG"
50+
elif [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
51+
tag="${GITHUB_REF_NAME}"
52+
else
53+
echo "A release tag is required for workflow_dispatch." >&2
54+
exit 1
55+
fi
56+
if [[ "${tag}" != [vV]* ]]; then
57+
tag="v${tag}"
58+
fi
59+
60+
version="${tag#v}"
61+
version="${version#V}"
62+
version="$(printf '%s' "$version" | sed 's/-/~/g')"
63+
64+
if [[ -z "$version" ]]; then
65+
echo "Unable to derive a package version from tag: $tag" >&2
66+
exit 1
67+
fi
68+
69+
ros_distro="${INPUT_ROS_DISTRO:-$DEFAULT_ROS_DISTRO}"
70+
deb_file="${DEB_FILE_PREFIX}_${version}_amd64.deb"
71+
72+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
73+
echo "version=$version" >> "$GITHUB_OUTPUT"
74+
echo "ros_distro=$ros_distro" >> "$GITHUB_OUTPUT"
75+
echo "deb_file=$deb_file" >> "$GITHUB_OUTPUT"
76+
77+
- name: Validate workspace
78+
shell: bash
79+
run: |
80+
set -eo pipefail
81+
if [[ ! -f robot_common_launch/package.xml ]]; then
82+
echo "robot_common_launch/package.xml not found at repo root." >&2
83+
exit 1
84+
fi
85+
86+
- name: Install system tools
87+
shell: bash
88+
run: |
89+
set -eo pipefail
90+
91+
sudo apt-get update
92+
sudo apt-get install -y curl gnupg lsb-release software-properties-common
93+
sudo add-apt-repository universe
94+
95+
sudo mkdir -p /etc/apt/keyrings
96+
curl -fsSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
97+
| sudo gpg --dearmor -o /etc/apt/keyrings/ros-archive-keyring.gpg
98+
99+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo "${UBUNTU_CODENAME}") main" \
100+
| sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
101+
102+
sudo apt-get update
103+
sudo apt-get install -y \
104+
python3-rosdep \
105+
python3-colcon-core \
106+
python3-colcon-common-extensions \
107+
python3-vcstool \
108+
python3-pip \
109+
python3-catkin-pkg-modules \
110+
fakeroot \
111+
dpkg-dev \
112+
rsync \
113+
build-essential \
114+
cmake \
115+
ros-${{ steps.meta.outputs.ros_distro }}-ament-cmake \
116+
ros-${{ steps.meta.outputs.ros_distro }}-ament-cmake-core \
117+
ros-${{ steps.meta.outputs.ros_distro }}-ament-package \
118+
ros-${{ steps.meta.outputs.ros_distro }}-ros-base
119+
120+
sudo rosdep init || true
121+
rosdep update
122+
123+
source "/opt/ros/${{ steps.meta.outputs.ros_distro }}/setup.bash"
124+
python3 -c "import ament_package; print('ament_package ready:', ament_package.__file__)"
125+
126+
- name: Install common ROS dependencies
127+
shell: bash
128+
env:
129+
ROS_DISTRO: ${{ steps.meta.outputs.ros_distro }}
130+
run: |
131+
set -eo pipefail
132+
source "/opt/ros/${ROS_DISTRO}/setup.bash"
133+
134+
ros_python_path="/opt/ros/${ROS_DISTRO}/lib/python$(python3 -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')/site-packages"
135+
export PYTHONPATH="${ros_python_path}:${PYTHONPATH:-}"
136+
137+
rosdep install \
138+
--from-paths . \
139+
--ignore-src \
140+
--rosdistro "${ROS_DISTRO}" \
141+
--reinstall \
142+
-r \
143+
-y
144+
145+
- name: Build common install space
146+
shell: bash
147+
env:
148+
ROS_DISTRO: ${{ steps.meta.outputs.ros_distro }}
149+
run: |
150+
set -eo pipefail
151+
source "/opt/ros/${ROS_DISTRO}/setup.bash"
152+
153+
ros_python_path="/opt/ros/${ROS_DISTRO}/lib/python$(python3 -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')/site-packages"
154+
export PYTHONPATH="${ros_python_path}:${PYTHONPATH:-}"
155+
156+
build_root="${RUNNER_TEMP}/colcon-common"
157+
package_root="${RUNNER_TEMP}/deb-build/package"
158+
install_prefix="${INSTALL_PREFIX}"
159+
install_root="${package_root}${install_prefix}"
160+
161+
rm -rf "$build_root" "$package_root"
162+
mkdir -p "$build_root" "$package_root"
163+
164+
colcon --log-base "${build_root}/log" build \
165+
--base-paths "${GITHUB_WORKSPACE}" \
166+
--build-base "${build_root}/build" \
167+
--install-base "${install_root}" \
168+
--merge-install
169+
170+
python3 -c "import sys; exec('''import os\ninstall_root = sys.argv[1]\nruntime_prefix = sys.argv[2]\nfor dirpath, _, filenames in os.walk(install_root):\n for filename in filenames:\n path = os.path.join(dirpath, filename)\n try:\n with open(path, 'r', encoding='utf-8') as f:\n content = f.read()\n except Exception:\n continue\n if install_root not in content:\n continue\n with open(path, 'w', encoding='utf-8') as f:\n f.write(content.replace(install_root, runtime_prefix))''')" "$install_root" "$install_prefix"
171+
172+
rm -f \
173+
"${install_root}/setup.bash" \
174+
"${install_root}/setup.sh" \
175+
"${install_root}/setup.zsh" \
176+
"${install_root}/setup.ps1" \
177+
"${install_root}/local_setup.bash" \
178+
"${install_root}/local_setup.sh" \
179+
"${install_root}/local_setup.zsh" \
180+
"${install_root}/local_setup.ps1" \
181+
"${install_root}/_local_setup_util.py" \
182+
"${install_root}/_local_setup_util_sh.py" \
183+
"${install_root}/_local_setup_util_ps1.py" \
184+
"${install_root}/.colcon_install_layout" \
185+
"${install_root}/COLCON_IGNORE"
186+
187+
if [[ ! -d "${install_root}/share/ament_index/resource_index/packages" ]]; then
188+
echo "ament index was not generated in the install space." >&2
189+
exit 1
190+
fi
191+
192+
- name: Build deb package
193+
id: build
194+
shell: bash
195+
env:
196+
ROS_DISTRO: ${{ steps.meta.outputs.ros_distro }}
197+
VERSION: ${{ steps.meta.outputs.version }}
198+
DEB_FILE: ${{ steps.meta.outputs.deb_file }}
199+
run: |
200+
set -eo pipefail
201+
202+
package_root="${RUNNER_TEMP}/deb-build/package"
203+
install_prefix="${INSTALL_PREFIX}"
204+
205+
mkdir -p "$package_root/DEBIAN"
206+
installed_size="$(du -sk "$package_root" | cut -f1)"
207+
208+
cat > "$package_root/DEBIAN/control" <<EOF
209+
Package: ${PACKAGE_NAME}
210+
Version: ${VERSION}
211+
Section: misc
212+
Priority: optional
213+
Architecture: amd64
214+
Depends: ros-${ROS_DISTRO}-ros-base
215+
Maintainer: ${GITHUB_REPOSITORY} maintainers <github-actions[bot]@users.noreply.github.com>
216+
Installed-Size: ${installed_size}
217+
Description: Shared robot_descriptions common ROS packages
218+
Prebuilt packages from fiveages-sim/robot-descriptions-common installed into ${INSTALL_PREFIX} while excluding shared prefix setup files.
219+
EOF
220+
221+
if [[ ! -d "${package_root}${install_prefix}/share/robot_common_launch" ]]; then
222+
echo "robot_common_launch was not installed into the package root." >&2
223+
exit 1
224+
fi
225+
226+
dpkg-deb --root-owner-group --build "$package_root" "$DEB_FILE"
227+
228+
echo "deb_path=${GITHUB_WORKSPACE}/${DEB_FILE}" >> "$GITHUB_OUTPUT"
229+
230+
- name: Upload deb to release
231+
shell: bash
232+
env:
233+
GH_TOKEN: ${{ github.token }}
234+
TAG: ${{ steps.meta.outputs.tag }}
235+
DEB_PATH: ${{ steps.build.outputs.deb_path }}
236+
run: |
237+
set -eo pipefail
238+
239+
if ! gh release view "$TAG" > /dev/null 2>&1; then
240+
gh release create "$TAG" \
241+
--title "$TAG" \
242+
--notes "Automated release for Debian packages."
243+
fi
244+
245+
gh release upload "$TAG" "$DEB_PATH" --clobber

0 commit comments

Comments
 (0)