Compare commits

..

1 Commits

Author SHA1 Message Date
Saman 9e24b1b584
Merge b9eb1406bb into f3598cf309 2026-03-21 10:25:58 +03:00
1 changed files with 70 additions and 147 deletions

View File

@ -4,213 +4,136 @@ on:
push: push:
tags: tags:
- '[0-9]+.[0-9]+.[0-9]+' - '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-*'
workflow_dispatch: workflow_dispatch:
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
permissions: permissions:
contents: read contents: read
packages: write
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
RUST_BACKTRACE: "1"
BINARY_NAME: telemt
jobs: jobs:
prepare: build:
name: Build ${{ matrix.target }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: permissions:
version: ${{ steps.meta.outputs.version }} contents: read
prerelease: ${{ steps.meta.outputs.prerelease }}
release_enabled: ${{ steps.meta.outputs.release_enabled }}
steps:
- id: meta
run: |
set -euo pipefail
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
RELEASE_ENABLED=true
else
VERSION="manual-${GITHUB_SHA::7}"
RELEASE_ENABLED=false
fi
if [[ "$VERSION" == *"-alpha"* || "$VERSION" == *"-beta"* || "$VERSION" == *"-rc"* ]]; then
PRERELEASE=true
else
PRERELEASE=false
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
echo "release_enabled=$RELEASE_ENABLED" >> "$GITHUB_OUTPUT"
checks:
runs-on: ubuntu-latest
container:
image: debian:trixie
steps:
- run: |
apt-get update
apt-get install -y build-essential clang llvm pkg-config curl git
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: actions/cache@v4
with:
path: |
/github/home/.cargo/registry
/github/home/.cargo/git
target
key: checks-${{ hashFiles('**/Cargo.lock') }}
- run: cargo fetch --locked
- run: cargo fmt --all -- --check
- run: cargo clippy
- run: cargo test
build-binaries:
needs: [prepare, checks]
runs-on: ubuntu-latest
container:
image: debian:trixie
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- rust_target: x86_64-unknown-linux-gnu - target: x86_64-unknown-linux-gnu
zig_target: x86_64-unknown-linux-gnu.2.28 artifact_name: telemt
asset_name: telemt-x86_64-linux-gnu asset_name: telemt-x86_64-linux-gnu
- rust_target: aarch64-unknown-linux-gnu - target: aarch64-unknown-linux-gnu
zig_target: aarch64-unknown-linux-gnu.2.28 artifact_name: telemt
asset_name: telemt-aarch64-linux-gnu asset_name: telemt-aarch64-linux-gnu
- rust_target: x86_64-unknown-linux-musl - target: x86_64-unknown-linux-musl
zig_target: x86_64-unknown-linux-musl artifact_name: telemt
asset_name: telemt-x86_64-linux-musl asset_name: telemt-x86_64-linux-musl
- rust_target: aarch64-unknown-linux-musl - target: aarch64-unknown-linux-musl
zig_target: aarch64-unknown-linux-musl artifact_name: telemt
asset_name: telemt-aarch64-linux-musl asset_name: telemt-aarch64-linux-musl
steps: steps:
- run: |
apt-get update
apt-get install -y clang llvm pkg-config curl git python3 python3-pip file tar xz-utils
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@v1
with: with:
targets: ${{ matrix.rust_target }} toolchain: stable
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- uses: actions/cache@v4 - uses: actions/cache@v4
with: with:
path: | path: |
/github/home/.cargo/registry ~/.cargo/registry
/github/home/.cargo/git ~/.cargo/git
target target
key: build-${{ matrix.zig_target }}-${{ hashFiles('**/Cargo.lock') }} key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-
- run: | - name: Install cross
python3 -m pip install --user --break-system-packages cargo-zigbuild run: cargo install cross --git https://github.com/cross-rs/cross
echo "/github/home/.local/bin" >> "$GITHUB_PATH"
- run: cargo fetch --locked - name: Build Release
env:
RUSTFLAGS: ${{ contains(matrix.target, 'musl') && '-C target-feature=+crt-static' || '' }}
run: cross build --release --target ${{ matrix.target }}
- run: | - name: Package binary
cargo zigbuild --release --locked --target "${{ matrix.zig_target }}" run: |
cd target/${{ matrix.target }}/release
- run: | tar -czvf ${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
BIN="target/${{ matrix.rust_target }}/release/${BINARY_NAME}" sha256sum ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.sha256
llvm-strip "$BIN" || true
- run: |
BIN="target/${{ matrix.rust_target }}/release/${BINARY_NAME}"
OUT="$RUNNER_TEMP/${{ matrix.asset_name }}"
mkdir -p "$OUT"
install -m755 "$BIN" "$OUT/${BINARY_NAME}"
tar -C "$RUNNER_TEMP" -czf "${{ matrix.asset_name }}.tar.gz" "${{ matrix.asset_name }}"
sha256sum "${{ matrix.asset_name }}.tar.gz" > "${{ matrix.asset_name }}.sha256"
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.asset_name }} name: ${{ matrix.asset_name }}
path: | path: |
${{ matrix.asset_name }}.tar.gz target/${{ matrix.target }}/release/${{ matrix.asset_name }}.tar.gz
${{ matrix.asset_name }}.sha256 target/${{ matrix.target }}/release/${{ matrix.asset_name }}.sha256
docker-image: build-docker-image:
name: Docker ${{ matrix.platform }} needs: build
needs: [prepare, build-binaries]
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
strategy: contents: read
matrix: packages: write
include:
- platform: linux/amd64
artifact: telemt-x86_64-linux-gnu
- platform: linux/arm64
artifact: telemt-aarch64-linux-gnu
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/download-artifact@v4 - uses: docker/setup-qemu-action@v3
with:
name: ${{ matrix.artifact }}
path: dist
- run: |
mkdir docker-build
tar -xzf dist/*.tar.gz -C docker-build --strip-components=1
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@v3
- name: Login - name: Login to GHCR
if: ${{ needs.prepare.outputs.release_enabled == 'true' }}
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6 - name: Extract version
id: vars
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
with: with:
context: ./docker-build context: .
platforms: ${{ matrix.platform }} push: true
push: ${{ needs.prepare.outputs.release_enabled == 'true' }} tags: |
tags: ghcr.io/${{ github.repository }}:${{ needs.prepare.outputs.version }} ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.VERSION }}
cache-from: type=gha,scope=telemt-${{ matrix.platform }} ghcr.io/${{ github.repository }}:latest
cache-to: type=gha,mode=max,scope=telemt-${{ matrix.platform }}
provenance: false
sbom: false
release: release:
if: ${{ needs.prepare.outputs.release_enabled == 'true' }} name: Create Release
needs: [prepare, build-binaries] needs: build
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: write
steps: steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
path: release-artifacts path: artifacts
pattern: telemt-*
- run: | - name: Create Release
mkdir upload uses: softprops/action-gh-release@v2
find release-artifacts -type f \( -name '*.tar.gz' -o -name '*.sha256' \) -exec cp {} upload/ \;
- uses: softprops/action-gh-release@v2
with: with:
files: upload/* files: artifacts/**/*
generate_release_notes: true generate_release_notes: true
prerelease: ${{ needs.prepare.outputs.prerelease == 'true' }} draft: false
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }}