107 lines
4.1 KiB
YAML
107 lines
4.1 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@v1
|
|
with:
|
|
toolchain: stable
|
|
cache: false
|
|
|
|
- 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 }}
|
|
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 config 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
|