Files
DataRouter/.gitea/workflows/release.yml
T

84 lines
3.0 KiB
YAML

name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-builder
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify merge commit
run: |
PARENTS=$(git log --format="%P" -1 | wc -w)
[ "$PARENTS" -ge 2 ] || exit 78
- name: Read tag from HEAD
id: tag
run: |
TAG=$(git tag --points-at HEAD | grep '^v' | head -n1)
[ -n "$TAG" ] || exit 78
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Install cross-compilers
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-arm-linux-gnueabihf \
gcc-aarch64-linux-gnu \
gcc-mingw-w64-x86-64 \
gcc-arm-none-eabi
- name: Build all targets
run: |
for entry in \
"linux-amd64|ON|" \
"linux-arm64|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-linux-arm64.cmake" \
"linux-armhf|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-linux-armhf.cmake" \
"windows-amd64|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-windows-amd64.cmake -DBUILD_EXAMPLES=OFF" \
"baremetal-arm32|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-baremetal-arm32.cmake -DBUILD_EXAMPLES=OFF -DBUILD_SHARED=OFF"
do
IFS='|' read -r name testing extra <<< "$entry"
echo ">>> Building $name"
cmake -S . -B "build-$name" -DBUILD_TESTING=$testing $extra
cmake --build "build-$name"
[ "$testing" = "ON" ] && ctest --test-dir "build-$name" --output-on-failure
pkg="datarouter-$name"
mkdir -p "dist/$pkg"
for f in datarouter.h datarouter_config_template.h LICENSE README.md; do
if [ -f "$f" ]; then cp "$f" "dist/$pkg/"; fi
done
for f in libDataRouter.a libDataRouter.so libDataRouter.dll libDataRouter.dll.a example example.exe; do
if [ -f "build-$name/$f" ]; then cp "build-$name/$f" "dist/$pkg/"; fi
done
done
- name: Create release & upload assets
run: |
TAG="${{ steps.tag.outputs.tag }}"
API="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
echo "=== Creating release $TAG ==="
RESP=$(curl -s -X POST \
-H "Authorization: token ${{ gitea.token }}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"DataRouter ${TAG}\"}" \
"$API")
ID=$(echo "$RESP" | python3 -c "import sys,json;print(json.load(sys.stdin)['id'])")
for dir in dist/*/; do
name="$(basename "$dir").tar.gz"
tar czf "/tmp/$name" -C "$dir" .
echo "Uploading $name"
curl -s -X POST \
-H "Authorization: token ${{ gitea.token }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"/tmp/$name" \
"${API}/${ID}/assets?name=${name}"
done