Skip to content
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
333 changes: 182 additions & 151 deletions .github/workflows/build-ubuntu20.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
name: Build Ubuntu 20.04 binary

on:
workflow_dispatch:
inputs:
ref:
description: Git ref to build
description: Existing annotated vX.Y.Z tag from the selected Forge line
required: true
default: v2.1.2
type: string
version:
description: USB camera version without the v prefix
description: Exact node version in the tag and source manifest (not the Forge line)
required: true
default: 2.1.2
type: string
upload_to_release:
description: Attach verified archives to an existing draft release
required: false
type: boolean
default: false

release_line:
description: Forge compatibility line
required: true
type: choice
options:
- 1.x
- 2.x
default: 2.x
workflow_call:
inputs:
ref:
description: Existing annotated vX.Y.Z tag from the selected Forge line
required: true
type: string
version:
description: Exact node version in the tag and source manifest (not the Forge line)
required: true
type: string
release_line:
description: Forge compatibility line
required: true
type: string
permissions:
contents: write

jobs:
build:
name: Build Ubuntu 20.04 (${{ matrix.asset_arch }})
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
asset_arch: x86_64
elf_machine: Advanced Micro Devices X86-64
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
asset_arch: arm64
elf_machine: AArch64
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
asset_arch: x86_64
elf_machine: Advanced Micro Devices X86-64
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
asset_arch: arm64
elf_machine: AArch64
runs-on: ${{ matrix.runner }}
container:
image: ubuntu:20.04
Expand All @@ -43,142 +62,154 @@ jobs:
RUST_TARGET: ${{ matrix.target }}
ASSET_ARCH: ${{ matrix.asset_arch }}
ELF_MACHINE: ${{ matrix.elf_machine }}
RELEASE_TAG: ${{ inputs.ref }}
RELEASE_LINE: ${{ inputs.release_line }}
steps:
- name: Install system tools
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
binutils \
build-essential \
ca-certificates \
clang \
curl \
file \
git \
libclang-dev \
libv4l-dev \
v4l-utils
rm -rf /var/lib/apt/lists/*

- uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}

- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.97.1"
targets: ${{ matrix.target }}

- name: Build release binary
run: |
export RUSTFLAGS="--remap-path-prefix=${HOME}=/build \
--remap-path-prefix=${CARGO_HOME:-${HOME}/.cargo}=/cargo \
--remap-path-prefix=${GITHUB_WORKSPACE}=."
export CARGO_PROFILE_RELEASE_STRIP=symbols
cargo build --locked --release --bin usb_camera \
--target "${RUST_TARGET}"

- name: Verify and package binary
run: |
test "${{ inputs.ref }}" = "v${RELEASE_VERSION}"
mkdir -p dist
install -m 0755 \
"target/${RUST_TARGET}/release/usb_camera" \
dist/usb_camera
./dist/usb_camera --version | tee /tmp/version.txt
grep -Fxq "usb_camera ${RELEASE_VERSION}" /tmp/version.txt
file ./dist/usb_camera | grep -q 'ELF 64-bit LSB'
actual_machine="$(readelf -h ./dist/usb_camera |
sed -n 's/^[[:space:]]*Machine:[[:space:]]*//p')"
echo "ELF machine: ${actual_machine}"
test "${actual_machine}" = "${ELF_MACHINE}"
test -z "$(ldd ./dist/usb_camera | grep 'not found' || true)"
max_glibc="$(objdump -T ./dist/usb_camera |
grep -oE 'GLIBC_[0-9.]+' | sort -Vu | tail -1)"
echo "max glibc symbol version: ${max_glibc}"
test "$(printf '%s\n' '2.31' "${max_glibc#GLIBC_}" |
sort -V | tail -1)" = "2.31"
if strings ./dist/usb_camera |
grep -E '/home/|gitlab\.ex-ai\.cn|git\+ssh://|ssh://'; then
echo "ERROR: private build markers found in binary" >&2
exit 1
fi
ldd --version | sed -n '1p'
archive="usb_camera-v${RELEASE_VERSION}-ubuntu20.04-${ASSET_ARCH}.tar.gz"
tar \
--sort=name \
--mtime='UTC 1970-01-01' \
--owner=0 \
--group=0 \
--numeric-owner \
-C dist \
-czf "${archive}" \
usb_camera
sha256sum "${archive}" > "${archive}.sha256"
test "$(tar -tzf "${archive}")" = "usb_camera"
sha256sum --check "${archive}.sha256"
rm -rf /tmp/usb-camera-archive-smoke
mkdir /tmp/usb-camera-archive-smoke
tar -xzf "${archive}" -C /tmp/usb-camera-archive-smoke
/tmp/usb-camera-archive-smoke/usb_camera --version |
grep -Fxq "usb_camera ${RELEASE_VERSION}"

- uses: actions/upload-artifact@v6
with:
name: usb_camera-v${{ inputs.version }}-ubuntu20.04-${{ matrix.asset_arch }}
path: |
usb_camera-v${{ inputs.version }}-ubuntu20.04-${{ matrix.asset_arch }}.tar.gz
usb_camera-v${{ inputs.version }}-ubuntu20.04-${{ matrix.asset_arch }}.tar.gz.sha256
if-no-files-found: error
retention-days: 30

- name: Attach verified archives to draft release
if: ${{ inputs.upload_to_release }}
uses: actions/github-script@v7
env:
RELEASE_TAG: ${{ inputs.ref }}
with:
script: |
const fs = require('fs');
const crypto = require('crypto');
const { owner, repo } = context.repo;
const tag = process.env.RELEASE_TAG;
const version = process.env.RELEASE_VERSION;
if (!/^\d+\.\d+\.\d+$/.test(version) || tag !== `v${version}`) {
throw new Error('Invalid release tag or version');
}
const releases = await github.paginate(github.rest.repos.listReleases, {
owner, repo, per_page: 100,
});
const release = releases.find(item => item.tag_name === tag);
if (!release || !release.draft) {
throw new Error('An existing draft release is required');
}
const assetArch = process.env.ASSET_ARCH;
const archive = `usb_camera-v${version}-ubuntu20.04-${assetArch}.tar.gz`;
const checksum = `${archive}.sha256`;
const bytes = fs.readFileSync(archive);
const digest = crypto.createHash('sha256').update(bytes).digest('hex');
if (fs.readFileSync(checksum, 'utf8').trim() !== `${digest} ${archive}`) {
throw new Error('Archive checksum mismatch');
}
const assets = await github.paginate(github.rest.repos.listReleaseAssets, {
owner, repo, release_id: release.id, per_page: 100,
});
for (const name of [archive, checksum]) {
const data = fs.readFileSync(name);
const expected = `sha256:${crypto.createHash('sha256').update(data).digest('hex')}`;
const existing = assets.find(item => item.name === name);
if (existing) {
if (existing.digest !== expected) {
throw new Error(`Refusing to replace existing asset: ${name}`);
}
core.info(`Identical asset already attached: ${name}`);
continue;
- name: Install system tools
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
binutils \
build-essential \
ca-certificates \
clang \
curl \
file \
git \
libclang-dev \
libv4l-dev \
v4l-utils
rm -rf /var/lib/apt/lists/*
- uses: actions/checkout@v6
with:
ref: refs/tags/${{ inputs.ref }}
fetch-depth: 0
persist-credentials: false
- name: Check out release tooling from the workflow commit
uses: actions/checkout@v6
with:
ref: ${{ github.workflow_sha }}
path: .release-tools
persist-credentials: false
- name: Install portable release validation Python
run: |
curl -LsSf https://astral.sh/uv/0.13.7/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh
uv python install 3.12
- name: Validate Forge release line and source version
run: |
git config --global --add safe.directory "$(pwd -P)"
uv run --no-project --python 3.12 python .release-tools/scripts/check_release_line.py --line "$RELEASE_LINE" --tag "$RELEASE_TAG" --version "$RELEASE_VERSION" --default-branch master
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.97.1
targets: ${{ matrix.target }}
- name: Build release binary
run: |
export RUSTFLAGS="--remap-path-prefix=${HOME}=/build \
--remap-path-prefix=${CARGO_HOME:-${HOME}/.cargo}=/cargo \
--remap-path-prefix=${GITHUB_WORKSPACE}=."
export CARGO_PROFILE_RELEASE_STRIP=symbols
cargo build --locked --release --bin usb_camera \
--target "${RUST_TARGET}"
- name: Verify and package binary
run: |
test "${RELEASE_TAG}" = "v${RELEASE_VERSION}"
mkdir -p dist
install -m 0755 \
"target/${RUST_TARGET}/release/usb_camera" \
dist/usb_camera
./dist/usb_camera --version | tee /tmp/version.txt
grep -Fxq "usb_camera ${RELEASE_VERSION}" /tmp/version.txt
file ./dist/usb_camera | grep -q 'ELF 64-bit LSB'
actual_machine="$(readelf -h ./dist/usb_camera |
sed -n 's/^[[:space:]]*Machine:[[:space:]]*//p')"
echo "ELF machine: ${actual_machine}"
test "${actual_machine}" = "${ELF_MACHINE}"
test -z "$(ldd ./dist/usb_camera | grep 'not found' || true)"
max_glibc="$(objdump -T ./dist/usb_camera |
grep -oE 'GLIBC_[0-9.]+' | sort -Vu | tail -1)"
echo "max glibc symbol version: ${max_glibc}"
test "$(printf '%s\n' '2.31' "${max_glibc#GLIBC_}" |
sort -V | tail -1)" = "2.31"
if strings ./dist/usb_camera |
grep -E '/home/|gitlab\.ex-ai\.cn|git\+ssh://|ssh://'; then
echo "ERROR: private build markers found in binary" >&2
exit 1
fi
ldd --version | sed -n '1p'
archive="usb_camera-v${RELEASE_VERSION}-ubuntu20.04-${ASSET_ARCH}.tar.gz"
tar \
--sort=name \
--mtime='UTC 1970-01-01' \
--owner=0 \
--group=0 \
--numeric-owner \
-C dist \
-czf "${archive}" \
usb_camera
sha256sum "${archive}" > "${archive}.sha256"
test "$(tar -tzf "${archive}")" = "usb_camera"
sha256sum --check "${archive}.sha256"
rm -rf /tmp/usb-camera-archive-smoke
mkdir /tmp/usb-camera-archive-smoke
tar -xzf "${archive}" -C /tmp/usb-camera-archive-smoke
/tmp/usb-camera-archive-smoke/usb_camera --version |
grep -Fxq "usb_camera ${RELEASE_VERSION}"
- uses: actions/upload-artifact@v6
with:
name: usb_camera-v${{ inputs.version }}-ubuntu20.04-${{ matrix.asset_arch }}
path: |
usb_camera-v${{ inputs.version }}-ubuntu20.04-${{ matrix.asset_arch }}.tar.gz
usb_camera-v${{ inputs.version }}-ubuntu20.04-${{ matrix.asset_arch }}.tar.gz.sha256
if-no-files-found: error
retention-days: 30
- name: Attach verified archives to draft release
if: ${{ inputs.upload_to_release }}
uses: actions/github-script@v7
env:
RELEASE_TAG: ${{ inputs.ref }}
with:
script: |
const fs = require('fs');
const crypto = require('crypto');
const { owner, repo } = context.repo;
const tag = process.env.RELEASE_TAG;
const version = process.env.RELEASE_VERSION;
if (!/^\d+\.\d+\.\d+$/.test(version) || tag !== `v${version}`) {
throw new Error('Invalid release tag or version');
}
const releases = await github.paginate(github.rest.repos.listReleases, {
owner, repo, per_page: 100,
});
const release = releases.find(item => item.tag_name === tag);
if (!release || !release.draft) {
throw new Error('An existing draft release is required');
}
const assetArch = process.env.ASSET_ARCH;
const archive = `usb_camera-v${version}-ubuntu20.04-${assetArch}.tar.gz`;
const checksum = `${archive}.sha256`;
const bytes = fs.readFileSync(archive);
const digest = crypto.createHash('sha256').update(bytes).digest('hex');
if (fs.readFileSync(checksum, 'utf8').trim() !== `${digest} ${archive}`) {
throw new Error('Archive checksum mismatch');
}
const assets = await github.paginate(github.rest.repos.listReleaseAssets, {
owner, repo, release_id: release.id, per_page: 100,
});
for (const name of [archive, checksum]) {
const data = fs.readFileSync(name);
const expected = `sha256:${crypto.createHash('sha256').update(data).digest('hex')}`;
const existing = assets.find(item => item.name === name);
if (existing) {
if (existing.digest !== expected) {
throw new Error(`Refusing to replace existing asset: ${name}`);
}
await github.rest.repos.uploadReleaseAsset({
owner, repo, release_id: release.id, name, data,
headers: { 'content-type': 'application/octet-stream' },
});
core.info(`Identical asset already attached: ${name}`);
continue;
}
await github.rest.repos.uploadReleaseAsset({
owner, repo, release_id: release.id, name, data,
headers: { 'content-type': 'application/octet-stream' },
});
}
24 changes: 24 additions & 0 deletions .github/workflows/release-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release line checks
on:
pull_request:
paths:
- '.github/workflows/**'
- 'scripts/check_release_line.py'
- 'scripts/test_release_line.py'
push:
paths:
- '.github/workflows/**'
- 'scripts/check_release_line.py'
- 'scripts/test_release_line.py'
permissions:
contents: read
jobs:
release-line-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Test source selection, versions and Forge/Dora compatibility
run: python -m unittest discover -s scripts -p test_release_line.py -v
Loading
Loading