ci(px4_msgs): fix the stable tag sync and set the package version

v1.18.0 was the first stable tag this workflow ran on, and it failed with
"PX4 branch release/1.18 not found". The check looked for a local
refs/heads/release/1.18, but actions/checkout only creates remote-tracking
refs for branches it does not check out, so on a tag push that ref never
exists. The push further down would have failed too: it still put the
token in the clone URL, which stopped working for sync_to_px4_msgs.yml in
October.

Move the logic into Tools/ci/px4_msgs_tag.sh so it can be run outside of
Actions. The script fetches the PX4 tag and px4_msgs into a scratch
directory instead of relying on the refs of the checkout, so it no longer
needs the PX4 release branch at all, and it authenticates through gh's
credential helper like the sync workflow does.

Two things behave differently:

- The definitions are compared against the PX4 tag instead of the tip of
  the PX4 release branch, and a file missing from px4_msgs now fails the
  check. git diff did not report those because they were untracked.
- The package.xml version in px4_msgs is set to the release version
  before tagging. release/1.18 still says 1.17.0, and a package built
  from the tag takes its version from that file.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche committed 2026-11-23 20:04:26 -08:00
1 parent 2f0dc16b4f
commit fdbc999ed8
2 files changed
+119 -104

No files matched your search

@@ -20,116 +20,20 @@ jobs:
runs-on: [runs-on,runner=4cpu-linux-x64,image=ubuntu22-full-x64,"run-id=${{ github.run_id }}",spot=false]
env:
TAG_NAME: ${{ github.event_name == 'workflow_dispatch' && inputs.tag_name || github.ref_name }}
# read by gh's git credential helper at push time
GH_TOKEN: ${{ secrets.PX4BUILTBOT_PERSONAL_ACCESS_TOKEN }}
# fail on a rejected token instead of prompting for a username
GIT_TERMINAL_PROMPT: 0
steps:
- name: Checkout PX4 repo
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: Setup git credentials
run: |
git config --global user.name "${{ secrets.PX4BUILDBOT_USER }}"
git config --global user.email "${{ secrets.PX4BUILDBOT_EMAIL }}"
# same reason as in sync_to_px4_msgs.yml: a token in the clone URL is dropped before the push
gh auth setup-git
- name: Resolve release branch from tag
id: tag_info
shell: bash
run: |
set -euo pipefail
if [[ ! "${TAG_NAME}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Tag format is not stable vX.Y.Z, skipping: ${TAG_NAME}"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "should_run=true" >> "$GITHUB_OUTPUT"
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
release_branch="release/${major}.${minor}"
git show-ref --verify --quiet "refs/heads/${release_branch}" || {
echo "PX4 branch ${release_branch} not found"
exit 1
}
tag_date="$(git for-each-ref --format='%(creatordate:iso8601)' "refs/tags/${TAG_NAME}")"
if [[ -z "${tag_date}" ]]; then
echo "Unable to resolve tag date for ${TAG_NAME}"
exit 1
fi
echo "release_branch=${release_branch}" >> "$GITHUB_OUTPUT"
echo "tag_date=${tag_date}" >> "$GITHUB_OUTPUT"
- name: Clone px4_msgs repo
if: steps.tag_info.outputs.should_run == 'true'
run: |
git clone https://${{ secrets.PX4BUILTBOT_PERSONAL_ACCESS_TOKEN }}@github.com/PX4/px4_msgs.git
- name: Checkout matching px4_msgs release branch
if: steps.tag_info.outputs.should_run == 'true'
shell: bash
run: |
set -euo pipefail
cd px4_msgs
release_branch="${{ steps.tag_info.outputs.release_branch }}"
if git show-ref --verify --quiet "refs/remotes/origin/${release_branch}"; then
git checkout -B "${release_branch}" "origin/${release_branch}"
else
echo "px4_msgs branch ${release_branch} does not exist"
exit 1
fi
- name: Verify msg and srv trees are identical
if: steps.tag_info.outputs.should_run == 'true'
shell: bash
run: |
set -euo pipefail
release_branch="${{ steps.tag_info.outputs.release_branch }}"
git checkout "${release_branch}"
# Use the same synchronization logic as sync_to_px4_msgs.yml,
# then verify there are no changes in px4_msgs.
rm -f px4_msgs/msg/*.msg
rm -f px4_msgs/msg/versioned/*.msg
rm -f px4_msgs/srv/*.srv
rm -f px4_msgs/srv/versioned/*.srv
cp msg/*.msg px4_msgs/msg/
cp msg/versioned/*.msg px4_msgs/msg/ || true
cp srv/*.srv px4_msgs/srv/
cp srv/versioned/*.srv px4_msgs/srv/ || true
if ! git -C px4_msgs diff --exit-code -- msg srv; then
echo "Message/service definitions differ between PX4 ${release_branch} and px4_msgs ${release_branch}"
exit 1
fi
- name: Create and push tag in px4_msgs
if: steps.tag_info.outputs.should_run == 'true'
shell: bash
run: |
set -euo pipefail
cd px4_msgs
target="$(git rev-parse HEAD)"
existing_target="$(git rev-parse "refs/tags/${TAG_NAME}^{}" 2>/dev/null || true)"
if [[ -n "${existing_target}" ]]; then
if [[ "${existing_target}" == "${target}" ]]; then
echo "Tag ${TAG_NAME} already exists on ${target}; nothing to do"
exit 0
fi
echo "Tag ${TAG_NAME} already exists on ${existing_target}, expected ${target}"
exit 1
fi
GIT_COMMITTER_DATE="${{ steps.tag_info.outputs.tag_date }}" \
git tag -a "${TAG_NAME}" "${target}" \
-m "PX4 msgs and srvs definitions matching PX4 stable release ${TAG_NAME#v}"
git push origin "refs/tags/${TAG_NAME}"
- name: Tag px4_msgs
run: Tools/ci/px4_msgs_tag.sh "$TAG_NAME"
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env bash
# Tag PX4/px4_msgs to match a stable PX4 release tag.
#
# For a stable tag vX.Y.Z this checks that the release/X.Y branch of px4_msgs
# carries exactly the message and service definitions of that PX4 tag, sets
# the px4_msgs package version to X.Y.Z, and pushes that commit together with
# an annotated vX.Y.Z tag.
#
# Pre-release tags (alpha, beta, rc) are skipped. A tag that already sits on
# the tip of the px4_msgs release branch is left alone, so the script can be
# run again for the same tag.
#
# Both repositories are fetched into a scratch directory, so the result does
# not depend on the refs or the history of the checkout this runs from.
#
# Usage:
# Tools/ci/px4_msgs_tag.sh <tag>
#
# Environment:
# PX4_URL PX4-Autopilot remote to read the tag from
# PX4_MSGS_URL px4_msgs remote to tag and push to
set -euo pipefail
PX4_URL="${PX4_URL:-https://github.com/PX4/PX4-Autopilot.git}"
PX4_MSGS_URL="${PX4_MSGS_URL:-https://github.com/PX4/px4_msgs.git}"
die() {
echo "error: $*" >&2
exit 1
}
tag="${1:-}"
if [ -z "$tag" ]; then
echo "Usage: $0 <tag>" >&2
exit 2
fi
if [[ ! "$tag" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "${tag} is not a stable vX.Y.Z tag, skipping"
exit 0
fi
version="${tag#v}"
branch="release/${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
px4="$work/px4.git"
git init --quiet --bare "$px4"
git -C "$px4" fetch --quiet --depth 1 "$PX4_URL" \
"refs/tags/${tag}:refs/tags/${tag}" ||
die "could not fetch ${tag} from ${PX4_URL}"
tag_date="$(git -C "$px4" for-each-ref \
--format='%(creatordate:iso8601)' "refs/tags/${tag}")"
git clone --quiet "$PX4_MSGS_URL" "$work/px4_msgs"
cd "$work/px4_msgs"
git show-ref --verify --quiet "refs/remotes/origin/${branch}" ||
die "px4_msgs has no ${branch} branch"
git checkout --quiet -B "$branch" "origin/${branch}"
head="$(git rev-parse HEAD)"
existing="$(git rev-parse --verify --quiet "refs/tags/${tag}^{commit}" || true)"
if [ -n "$existing" ]; then
if [ "$existing" = "$head" ]; then
echo "px4_msgs ${tag} is already on the tip of ${branch}, nothing to do"
exit 0
fi
die "px4_msgs ${tag} is on ${existing}, but ${branch} is at ${head}"
fi
# Lay the PX4 definitions over the checkout the same way sync_to_px4_msgs.yml
# does. Anything git then reports as changed never reached px4_msgs.
paths=(msg)
if git -C "$px4" cat-file -e "refs/tags/${tag}:srv" 2>/dev/null; then
paths+=(srv)
fi
mkdir "$work/px4"
git -C "$px4" archive "refs/tags/${tag}" "${paths[@]}" | tar -x -C "$work/px4"
for kind in msg srv; do
rm -f "$kind"/*."$kind" "$kind"/versioned/*."$kind"
[ -d "$work/px4/$kind" ] || continue
mkdir -p "$kind"
cp "$work/px4/$kind"/*."$kind" "$kind"/
cp "$work/px4/$kind"/versioned/*."$kind" "$kind"/ 2>/dev/null || true
done
if [ -n "$(git status --porcelain -- msg srv)" ]; then
git status --short -- msg srv
die "definitions differ between PX4 ${tag} and px4_msgs ${branch}"
fi
sed "s:<version>.*</version>:<version>${version}</version>:" package.xml \
> "$work/package.xml"
cat "$work/package.xml" > package.xml
grep -q "<version>${version}</version>" package.xml ||
die "could not set the version in package.xml"
if ! git diff --quiet -- package.xml; then
git commit --quiet -m "Set version to ${version}" -- package.xml
fi
GIT_COMMITTER_DATE="$tag_date" git tag -a "$tag" \
-m "PX4 msgs and srvs definitions matching PX4 stable release ${version}"
git push --atomic origin "refs/heads/${branch}" "refs/tags/${tag}"
echo "px4_msgs ${tag} pushed on $(git rev-parse --short HEAD) (${branch})"