@@ -2,11 +2,21 @@ name: Build Common Deb
22
33# Runs in https://github.com/fiveages-sim/robot-descriptions-common.
44# The repository root is the colcon workspace.
5+ #
6+ # Release policy:
7+ # - push v* tag -> formal GitHub Release
8+ # - pull_request merged into main -> single rolling pre-release (tag: pre-release)
9+ # - workflow_dispatch -> manual formal release for a given tag
510
611on :
712 push :
813 tags :
914 - " v*"
15+ pull_request :
16+ types :
17+ - closed
18+ branches :
19+ - main
1020 workflow_dispatch :
1121 inputs :
1222 tag :
@@ -23,18 +33,20 @@ permissions:
2333 contents : write
2434
2535concurrency :
26- group : ${{ github.workflow }}-${{ github.ref }}-${{ github.event.inputs.tag || github.ref_name }}
36+ group : ${{ github.workflow }}-${{ github.ref_type == 'tag' && github.ref_name || (github.event_name == 'pull_request' && 'pre-release' || github.ref) }}
2737 cancel-in-progress : true
2838
2939env :
3040 DEFAULT_ROS_DISTRO : jazzy
3141 PACKAGE_NAME : ros-jazzy-robot-descriptions-common
3242 DEB_FILE_PREFIX : ros-jazzy-robot-descriptions-common
3343 INSTALL_PREFIX : /opt/ros/jazzy
44+ PRE_RELEASE_TAG : pre-release
3445
3546jobs :
3647 build_common_deb :
3748 name : build common deb (${{ matrix.arch }})
49+ if : github.event_name != 'pull_request' || github.event.pull_request.merged == true
3850 runs-on : ${{ matrix.runner }}
3951 strategy :
4052 fail-fast : false
5668 uses : actions/checkout@v4
5769 with :
5870 fetch-depth : 0
71+ ref : ${{ github.event.pull_request.merge_commit_sha || github.ref }}
5972
6073 - name : Resolve release metadata
6174 id : meta
@@ -65,19 +78,48 @@ jobs:
6578 INPUT_ROS_DISTRO : ${{ github.event.inputs.ros_distro }}
6679 MATRIX_ROS_DISTRO : ${{ matrix.ros_distro }}
6780 DEB_ARCH : ${{ matrix.arch }}
81+ PRE_RELEASE_TAG : ${{ env.PRE_RELEASE_TAG }}
82+ MERGE_COMMIT_SHA : ${{ github.event.pull_request.merge_commit_sha }}
83+ PR_NUMBER : ${{ github.event.pull_request.number }}
6884 run : |
6985 set -eo pipefail
7086
71- if [[ -n "${INPUT_TAG:-}" ]]; then
87+ is_prerelease="false"
88+
89+ if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
90+ if [[ -z "${MERGE_COMMIT_SHA}" ]]; then
91+ echo "Merge commit SHA is missing for merged pull request." >&2
92+ exit 1
93+ fi
94+ short_sha="$(printf '%s' "${MERGE_COMMIT_SHA}" | cut -c1-7)"
95+ tag="${PRE_RELEASE_TAG}"
96+ base_version="$(grep -m1 '<version>' robot_common_launch/package.xml | sed -E 's@.*<version>([^<]+)</version>.*@\1@')"
97+ if [[ -z "$base_version" ]]; then
98+ echo "Unable to read version from robot_common_launch/package.xml." >&2
99+ exit 1
100+ fi
101+ version="${base_version}~main+${short_sha}"
102+ is_prerelease="true"
103+ elif [[ -n "${INPUT_TAG:-}" ]]; then
72104 tag="$INPUT_TAG"
73105 elif [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
74106 tag="${GITHUB_REF_NAME}"
75107 else
76108 echo "A release tag is required for workflow_dispatch." >&2
77109 exit 1
78110 fi
79- if [[ "${tag}" != [vV]* ]]; then
80- tag="v${tag}"
111+ if [[ "${is_prerelease}" != "true" ]]; then
112+ if [[ "${tag}" != [vV]* ]]; then
113+ tag="v${tag}"
114+ fi
115+
116+ version="${tag#v}"
117+ version="${version#V}"
118+ version="$(printf '%s' "$version" | sed 's/-/~/g')"
119+ fi
120+ if [[ -z "$version" ]]; then
121+ echo "Unable to derive a package version from tag: $tag" >&2
122+ exit 1
81123 fi
82124
83125 ros_distro="${INPUT_ROS_DISTRO:-$MATRIX_ROS_DISTRO}"
@@ -87,21 +129,14 @@ jobs:
87129 exit 1
88130 fi
89131
90- version="${tag#v}"
91- version="${version#V}"
92- version="$(printf '%s' "$version" | sed 's/-/~/g')"
93- if [[ -z "$version" ]]; then
94- echo "Unable to derive a package version from tag: $tag" >&2
95- exit 1
96- fi
97-
98132 deb_file="${DEB_FILE_PREFIX}_${version}_${DEB_ARCH}.deb"
99133
100134 echo "tag=$tag" >> "$GITHUB_OUTPUT"
101135 echo "version=$version" >> "$GITHUB_OUTPUT"
102136 echo "ros_distro=$ros_distro" >> "$GITHUB_OUTPUT"
103137 echo "deb_arch=$DEB_ARCH" >> "$GITHUB_OUTPUT"
104138 echo "deb_file=$deb_file" >> "$GITHUB_OUTPUT"
139+ echo "is_prerelease=$is_prerelease" >> "$GITHUB_OUTPUT"
105140
106141 - name : Validate workspace
107142 shell : bash
@@ -314,37 +349,67 @@ jobs:
314349 tag : ${{ steps.meta.outputs.tag }}
315350 ros_distro : ${{ steps.meta.outputs.ros_distro }}
316351 version : ${{ steps.meta.outputs.version }}
352+ is_prerelease : ${{ steps.meta.outputs.is_prerelease }}
317353
318354 steps :
355+ - name : Checkout repository
356+ uses : actions/checkout@v4
357+ with :
358+ ref : ${{ github.event.pull_request.merge_commit_sha || github.ref }}
359+
319360 - name : Resolve release metadata
320361 id : meta
321362 shell : bash
322363 env :
323364 INPUT_TAG : ${{ github.event.inputs.tag }}
324365 INPUT_ROS_DISTRO : ${{ github.event.inputs.ros_distro }}
366+ PRE_RELEASE_TAG : ${{ env.PRE_RELEASE_TAG }}
367+ MERGE_COMMIT_SHA : ${{ github.event.pull_request.merge_commit_sha }}
368+ PR_NUMBER : ${{ github.event.pull_request.number }}
325369 run : |
326370 set -eo pipefail
327371
328- if [[ -n "${INPUT_TAG:-}" ]]; then
372+ is_prerelease="false"
373+
374+ if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
375+ if [[ -z "${MERGE_COMMIT_SHA}" ]]; then
376+ echo "Merge commit SHA is missing for merged pull request." >&2
377+ exit 1
378+ fi
379+ short_sha="$(printf '%s' "${MERGE_COMMIT_SHA}" | cut -c1-7)"
380+ tag="${PRE_RELEASE_TAG}"
381+ base_version="$(grep -m1 '<version>' robot_common_launch/package.xml | sed -E 's@.*<version>([^<]+)</version>.*@\1@')"
382+ if [[ -z "$base_version" ]]; then
383+ echo "Unable to read version from robot_common_launch/package.xml." >&2
384+ exit 1
385+ fi
386+ version="${base_version}~main+${short_sha}"
387+ is_prerelease="true"
388+ elif [[ -n "${INPUT_TAG:-}" ]]; then
329389 tag="$INPUT_TAG"
330390 elif [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
331391 tag="${GITHUB_REF_NAME}"
332392 else
333393 echo "A release tag is required for workflow_dispatch." >&2
334394 exit 1
335395 fi
336- if [[ "${tag}" != [vV]* ]]; then
337- tag="v${tag}"
338- fi
339396
340397 ros_distro="${INPUT_ROS_DISTRO:-$DEFAULT_ROS_DISTRO}"
341- version="${tag#v}"
342- version="${version#V}"
343- version="$(printf '%s' "$version" | sed 's/-/~/g')"
398+
399+ if [[ "${is_prerelease}" != "true" ]]; then
400+ if [[ "${tag}" != [vV]* ]]; then
401+ tag="v${tag}"
402+ fi
403+
404+ version="${tag#v}"
405+ version="${version#V}"
406+ version="$(printf '%s' "$version" | sed 's/-/~/g')"
407+ fi
344408
345409 echo "tag=$tag" >> "$GITHUB_OUTPUT"
346410 echo "ros_distro=$ros_distro" >> "$GITHUB_OUTPUT"
347411 echo "version=$version" >> "$GITHUB_OUTPUT"
412+ echo "is_prerelease=$is_prerelease" >> "$GITHUB_OUTPUT"
348413
349414 - name : Download built deb artifacts
350415 uses : actions/download-artifact@v4
@@ -357,18 +422,47 @@ jobs:
357422 env :
358423 GH_TOKEN : ${{ github.token }}
359424 TAG : ${{ steps.meta.outputs.tag }}
425+ IS_PRERELEASE : ${{ steps.meta.outputs.is_prerelease }}
426+ PRE_RELEASE_TAG : ${{ env.PRE_RELEASE_TAG }}
427+ RELEASE_TARGET_SHA : ${{ github.event.pull_request.merge_commit_sha || github.sha }}
428+ PR_NUMBER : ${{ github.event.pull_request.number }}
360429 run : |
361430 set -eo pipefail
362431
363432 ls -lh *.deb
364- if ! gh release view "$TAG" --repo "${GITHUB_REPOSITORY}" > /dev/null 2>&1; then
365- gh release create "$TAG" \
433+
434+ if [[ "${IS_PRERELEASE}" == "true" ]]; then
435+ echo "Cleaning up legacy pre-releases..."
436+ gh release list --repo "${GITHUB_REPOSITORY}" --limit 100 \
437+ --json tagName,isPrerelease \
438+ --jq ".[] | select(.isPrerelease and .tagName != \"${PRE_RELEASE_TAG}\") | .tagName" \
439+ | while read -r old_tag; do
440+ [[ -z "$old_tag" ]] && continue
441+ echo "Deleting legacy pre-release: ${old_tag}"
442+ gh release delete "$old_tag" --repo "${GITHUB_REPOSITORY}" --yes --cleanup-tag || true
443+ done
444+
445+ gh release delete "${TAG}" --repo "${GITHUB_REPOSITORY}" --yes --cleanup-tag 2>/dev/null || true
446+
447+ gh release create "${TAG}" \
366448 --repo "${GITHUB_REPOSITORY}" \
367- --title "$TAG " \
368- --notes "Automated release for Debian packages."
369- fi
449+ --target "${RELEASE_TARGET_SHA} " \
450+ --title "Pre- release (main)" \
451+ --notes "Rolling pre-release built from merged PR #${PR_NUMBER} @ ${RELEASE_TARGET_SHA}
370452
371- gh release upload "$TAG" ./*.deb --repo "${GITHUB_REPOSITORY}" --clobber
453+ Workflow run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
454+ --prerelease \
455+ ./*.deb
456+ else
457+ if ! gh release view "$TAG" --repo "${GITHUB_REPOSITORY}" > /dev/null 2>&1; then
458+ gh release create "$TAG" \
459+ --repo "${GITHUB_REPOSITORY}" \
460+ --title "$TAG" \
461+ --notes "Automated release for Debian packages."
462+ fi
463+
464+ gh release upload "$TAG" ./*.deb --repo "${GITHUB_REPOSITORY}" --clobber
465+ fi
372466
373467 verify_common_deb :
374468 name : verify common deb (${{ matrix.arch }})
0 commit comments