Files
sudo/.gitea/workflows/testing.yaml
T
DragonSlayer_14 a66baf1dc6
TruffleHog Secret Scan / TruffleHog (push) Successful in 18s
Code Quality (Auto-Format & Clippy-Fix) / Formatierung & Clippy automatisch beheben (push) Successful in 30s
Security Scans / Trivy & OSV-Scanner (push) Successful in 34s
TruffleHog Secret Scan / TruffleHog (pull_request) Successful in 17s
Security Scans / Trivy & OSV-Scanner (pull_request) Successful in 26s
Unit-Tests / Unit-Tests (pull_request) Successful in 29s
Feat: Fügt CI/CD-Workflows, Sicherheitsprüfungen und Abhängigkeitsmanagement hinzu.
2026-09-13 00:48:03 +02:00

119 lines
4.5 KiB
YAML

name: Testing Build, Check & Preview Release
on:
push:
branches:
- testing
jobs:
build-and-preview:
name: Build, Check & Create Preview Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v7
- name: Install Rust Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v2
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: Run Tests
run: |
cargo test
- name: Compiler Check
run: |
cargo check --all-targets
- name: Package Crate
run: |
cargo package
- 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} Crate ${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/package/*.crate; 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