- cargo-binstall/cargo-deb/cargo-generate-rpm auf feste Versionen gepinnt (vorher "latest", nicht reproduzierbar) und ~/.cargo/bin versionsbasiert gecacht - rustup target add fuer aarch64/i686 in eigenen Schritt ausgelagert und ~/.rustup/.../lib/rustlib/<target> gecacht, Cache-Key basiert auf der aufgeloesten rustc-Version (nicht auf dem gleitenden "stable"-Label), damit bei einem Rust-Update kein veralteter Cache mit neuerem Compiler gemischt wird - x86_64-unknown-linux-gnu aus rustup target add entfernt (Host- Target, war bereits Teil der stable-Toolchain, No-Op) - drei neue customManagers-Eintraege in renovate.json fuer cargo-binstall (github-releases) sowie cargo-deb/cargo-generate-rpm (crates.io), damit Renovate die gepinnten Versionen aktuell haelt Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kh9v73QApBwJj96w6A8R55
258 lines
12 KiB
YAML
258 lines
12 KiB
YAML
name: Testing Build, Publish & Preview Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- testing
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
name: Build, Publish Packages (Testing) & Create Preview Release
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
CARGO_BINSTALL_VERSION: "1.23.0"
|
|
CARGO_DEB_VERSION: "3.8.0"
|
|
CARGO_GENERATE_RPM_VERSION: "0.21.0"
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v7
|
|
|
|
- name: Install Rust Toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
toolchain: stable
|
|
cache: false
|
|
|
|
- name: Cache Cargo-Abhängigkeiten & Build-Artefakte
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
target
|
|
key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
|
|
restore-keys: |
|
|
cargo-${{ runner.os }}-
|
|
|
|
- name: Install Cross-Compilation Toolchains (apt)
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-i686-linux-gnu
|
|
|
|
- name: Ermittle Rust-Version für Rustup-Target-Cache-Key
|
|
run: echo "RUST_VERSION=$(rustc --version | awk '{print $2}')" >> "$GITHUB_ENV"
|
|
|
|
- name: Cache Rustup Cross-Compilation-Targets
|
|
id: cache-rustup-targets
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu
|
|
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu
|
|
key: rustup-targets-${{ runner.os }}-${{ env.RUST_VERSION }}
|
|
|
|
- name: Add Rust Cross-Compilation Targets
|
|
if: steps.cache-rustup-targets.outputs.cache-hit != 'true'
|
|
run: rustup target add aarch64-unknown-linux-gnu i686-unknown-linux-gnu
|
|
|
|
- name: PATH um Cargo-bin-Verzeichnis ergänzen
|
|
run: |
|
|
mkdir -p ~/.cargo/bin
|
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Cache Packaging-Tools (cargo-binstall, cargo-deb, cargo-generate-rpm)
|
|
id: cache-packaging-tools
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: ~/.cargo/bin
|
|
key: packaging-tools-${{ runner.os }}-${{ env.CARGO_BINSTALL_VERSION }}-${{ env.CARGO_DEB_VERSION }}-${{ env.CARGO_GENERATE_RPM_VERSION }}
|
|
|
|
- name: Install Packaging Tools (Prebuilt Binaries)
|
|
if: steps.cache-packaging-tools.outputs.cache-hit != 'true'
|
|
run: |
|
|
curl -fsSL "https://github.com/cargo-bins/cargo-binstall/releases/download/v${CARGO_BINSTALL_VERSION}/cargo-binstall-x86_64-unknown-linux-musl.tgz" | tar -xz -C ~/.cargo/bin
|
|
~/.cargo/bin/cargo-binstall -y --no-symlinks "cargo-deb@${CARGO_DEB_VERSION}" "cargo-generate-rpm@${CARGO_GENERATE_RPM_VERSION}"
|
|
|
|
- name: Run Tests
|
|
run: |
|
|
cargo test
|
|
|
|
- name: Build Release Binaries
|
|
run: |
|
|
cargo build --release --target x86_64-unknown-linux-gnu
|
|
cargo build --release --target aarch64-unknown-linux-gnu
|
|
cargo build --release --target i686-unknown-linux-gnu
|
|
|
|
- name: Determine Build Number
|
|
id: build_num
|
|
env:
|
|
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
|
REPO: ${{ gitea.repository || github.repository }}
|
|
REPO_OWNER: ${{ gitea.repository_owner || github.repository_owner }}
|
|
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
|
run: |
|
|
BUILD_NUM=$(python3 scripts/get-build-number.py)
|
|
echo "build_number=${BUILD_NUM}" >> $GITHUB_OUTPUT
|
|
echo "BUILD_NUMBER=${BUILD_NUM}" >> $GITHUB_ENV
|
|
echo "Ermittelte Build-Nummer: ${BUILD_NUM}"
|
|
|
|
- name: Build Debian Packages (.deb)
|
|
run: |
|
|
cargo deb --target x86_64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
|
cargo deb --target aarch64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
|
cargo deb --target i686-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
|
|
|
- name: Build Fedora / RPM Packages (.rpm)
|
|
run: |
|
|
mkdir -p target/generate-rpm
|
|
cargo generate-rpm --target x86_64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
|
cargo generate-rpm --target aarch64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
|
cargo generate-rpm --target i686-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
|
|
|
- name: Build Arch Linux Packages (.pkg.tar.zst)
|
|
run: |
|
|
python3 scripts/package-arch.py --target x86_64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
|
python3 scripts/package-arch.py --target aarch64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
|
python3 scripts/package-arch.py --target i686-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
|
|
|
- name: Publish Packages to Gitea Package Registry
|
|
env:
|
|
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
|
REPO_OWNER: ${{ gitea.repository_owner || github.repository_owner }}
|
|
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
|
run: |
|
|
echo "Veröffentliche Debian-Paket (Distribution: testing, Component: main)..."
|
|
for deb in target/debian/*.deb; do
|
|
[ -f "$deb" ] || continue
|
|
curl -f -s -S -X PUT \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
--upload-file "$deb" \
|
|
"${GITEA_URL}/api/packages/${REPO_OWNER}/debian/pool/testing/main/upload"
|
|
done
|
|
|
|
echo "Veröffentliche Fedora/RPM-Paket (Gruppe: testing)..."
|
|
for rpm in target/generate-rpm/*.rpm; do
|
|
[ -f "$rpm" ] || continue
|
|
curl -f -s -S -X PUT \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
--upload-file "$rpm" \
|
|
"${GITEA_URL}/api/packages/${REPO_OWNER}/rpm/testing/upload"
|
|
done
|
|
|
|
echo "Veröffentliche Arch Linux-Paket (Repository: testing)..."
|
|
for pkg in target/arch/*.pkg.tar.zst; do
|
|
[ -f "$pkg" ] || continue
|
|
curl -f -s -S -X PUT \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
--upload-file "$pkg" \
|
|
"${GITEA_URL}/api/packages/${REPO_OWNER}/arch/testing"
|
|
done
|
|
|
|
- name: Create Gitea Pre-Release and Upload Assets
|
|
env:
|
|
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
|
REPO: ${{ gitea.repository || github.repository }}
|
|
REPO_NAME: ${{ gitea.repository_name || github.event.repository.name }}
|
|
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
|
run: |
|
|
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
|
|
TAG_NAME="v${VERSION}-preview"
|
|
RELEASE_TITLE="Preview Release ${TAG_NAME}"
|
|
RELEASE_NOTES="Automatisches Preview-Release für ${REPO_NAME} ${VERSION} (Branch: Testing)."
|
|
|
|
echo "Erstelle oder hole Preview-Release für Tag ${TAG_NAME} in ${REPO}..."
|
|
|
|
GET_RESP=$(curl -s -w "\n%{http_code}" \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG_NAME}")
|
|
HTTP_CODE=$(echo "$GET_RESP" | tail -n1)
|
|
BODY=$(echo "$GET_RESP" | sed '$d')
|
|
|
|
RELEASE_ID=""
|
|
if [ "$HTTP_CODE" -eq 200 ]; then
|
|
RELEASE_ID=$(echo "$BODY" | jq -r '.id // empty' 2>/dev/null || echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
|
echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})."
|
|
else
|
|
echo "Erstelle neues Preview-Release ${TAG_NAME}..."
|
|
CREATE_PAYLOAD=$(cat <<EOF
|
|
{
|
|
"tag_name": "${TAG_NAME}",
|
|
"target_commitish": "testing",
|
|
"name": "${RELEASE_TITLE}",
|
|
"body": "${RELEASE_NOTES}",
|
|
"draft": false,
|
|
"prerelease": true
|
|
}
|
|
EOF
|
|
)
|
|
CREATE_RESP=$(curl -f -s -S -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$CREATE_PAYLOAD" \
|
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases")
|
|
RELEASE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty' 2>/dev/null || echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
|
echo "Neues Preview-Release erstellt (ID: ${RELEASE_ID})."
|
|
fi
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Fehler: Release-ID konnte nicht ermittelt werden!"
|
|
exit 1
|
|
fi
|
|
|
|
EXISTING_ASSETS_JSON=$(curl -s \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" || echo "[]")
|
|
|
|
for file in target/debian/*.deb target/generate-rpm/*.rpm target/arch/*.pkg.tar.zst; do
|
|
[ -f "$file" ] || continue
|
|
filename="$(basename "$file")"
|
|
echo "Lade Release-Asset hoch: $filename"
|
|
|
|
ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | jq -r --arg name "$filename" '.[]? | select(.name == $name) | .id' 2>/dev/null | head -n1 || true)
|
|
if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then
|
|
echo "Lösche altes Asset mit ID ${ASSET_ID}..."
|
|
curl -s -X DELETE \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" || true
|
|
fi
|
|
|
|
curl -f -s -S -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-F "attachment=@${file}" \
|
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${filename}"
|
|
echo "Asset ${filename} erfolgreich hochgeladen."
|
|
done
|
|
|
|
- name: Build and Publish Docker Container Image (Testing)
|
|
env:
|
|
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
|
REPO: ${{ gitea.repository || github.repository }}
|
|
REPO_OWNER: ${{ gitea.repository_owner || github.repository_owner }}
|
|
REPO_NAME: ${{ gitea.repository_name || github.event.repository.name }}
|
|
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
|
run: |
|
|
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
|
|
REGISTRY_HOST=$(echo "${GITEA_URL}" | sed -E 's|^https?://||; s|/.*$||')
|
|
IMAGE_NAME=$(echo "${REGISTRY_HOST}/${REPO_OWNER}/${REPO_NAME}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
echo "Authentifiziere an der Container Registry ${REGISTRY_HOST}..."
|
|
echo "${TOKEN}" | docker login "${REGISTRY_HOST}" -u "${REPO_OWNER}" --password-stdin
|
|
|
|
echo "Baue Docker-Container Image (Testing / Preview)..."
|
|
docker build \
|
|
--build-arg TARGET_BIN=target/x86_64-unknown-linux-gnu/release/mirror-package \
|
|
-t "${IMAGE_NAME}:testing" \
|
|
-t "${IMAGE_NAME}:${VERSION}-preview" \
|
|
-t "${IMAGE_NAME}:${VERSION}-testing" \
|
|
-t "${IMAGE_NAME}:${VERSION}-preview.${BUILD_NUMBER}" \
|
|
-t "${IMAGE_NAME}:testing-${BUILD_NUMBER}" \
|
|
.
|
|
|
|
echo "Veröffentliche Docker-Images nach ${IMAGE_NAME}..."
|
|
docker push "${IMAGE_NAME}:testing"
|
|
docker push "${IMAGE_NAME}:${VERSION}-preview"
|
|
docker push "${IMAGE_NAME}:${VERSION}-testing"
|
|
docker push "${IMAGE_NAME}:${VERSION}-preview.${BUILD_NUMBER}"
|
|
docker push "${IMAGE_NAME}:testing-${BUILD_NUMBER}"
|
|
echo "Docker-Images (Testing) erfolgreich veröffentlicht."
|