name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Version tag to build (e.g. v0.1.0)'
required: true
permissions:
contents: write
jobs:
verify:
name: verify before release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build (release, all features)
run: cargo build --release --all-features --verbose
- name: Run unit tests
run: cargo test --all-features --verbose
- name: Run unit tests (no default features)
run: cargo test --no-default-features --verbose
package:
name: build & package
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Resolve version
id: ver
run: |
REF="${{ github.event.inputs.tag || github.ref_name }}"
VERSION="${REF#v}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$REF" >> "$GITHUB_OUTPUT"
- name: Check tag matches Cargo.toml version
run: |
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | grep -oP '"\K[0-9]+\.[0-9]+\.[0-9]+')
echo "tag version: ${{ steps.ver.outputs.version }}, Cargo.toml version: $CARGO_VERSION"
if [ "${{ steps.ver.outputs.version }}" != "$CARGO_VERSION" ]; then
echo "::error::Tag version (${{ steps.ver.outputs.version }}) does not match version in Cargo.toml ($CARGO_VERSION)"
exit 1
fi
- name: Extract changelog section for this version
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
awk -v ver="$VERSION" '
/^## \[/ {
if (found) exit
if ($0 ~ ("^## \\[" ver "\\]")) { found=1; next }
next
}
/^\[.*\]:/ { if (found) exit }
found { print }
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "::error::No CHANGELOG.md section found for version $VERSION"
exit 1
fi
cat release-notes.md
- name: Build release libraries
run: cargo build --release --all-features --verbose
- name: Stage dist tree
run: |
DIST_DIR="dist/librtmp2-${{ steps.ver.outputs.version }}"
mkdir -p "$DIST_DIR/lib"
for artifact in liblibrtmp2.so liblibrtmp2.a; do
test -f "target/release/$artifact" || {
echo "::error::Missing target/release/$artifact"
exit 1
}
cp "target/release/$artifact" "$DIST_DIR/lib/"
done
cp README.md LICENSE Cargo.toml "$DIST_DIR/"
- name: Create binary tarball
run: |
cd dist
tar czf "librtmp2-${{ steps.ver.outputs.version }}-linux-x86_64.tar.gz" \
"librtmp2-${{ steps.ver.outputs.version }}"
sha256sum "librtmp2-${{ steps.ver.outputs.version }}-linux-x86_64.tar.gz" \
> "librtmp2-${{ steps.ver.outputs.version }}-linux-x86_64.tar.gz.sha256"
- name: Create source tarball
run: |
git archive --format=tar.gz \
--prefix="librtmp2-${{ steps.ver.outputs.version }}/" \
-o "dist/librtmp2-${{ steps.ver.outputs.version }}-src.tar.gz" HEAD
cd dist
sha256sum "librtmp2-${{ steps.ver.outputs.version }}-src.tar.gz" \
> "librtmp2-${{ steps.ver.outputs.version }}-src.tar.gz.sha256"
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: librtmp2-${{ steps.ver.outputs.version }}
path: |
dist/*.tar.gz
dist/*.sha256
- name: Publish GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.ver.outputs.tag }}
target_commitish: ${{ github.sha }}
name: librtmp2 ${{ steps.ver.outputs.version }}
body_path: release-notes.md
files: |
dist/*.tar.gz
dist/*.sha256