From 50b9684d16a1f5fa5d7dc67d14165af81c2fd601 Mon Sep 17 00:00:00 2001 From: datadunia Date: Sat, 30 May 2026 03:20:50 +0700 Subject: [PATCH] chore: CI workflows centralized to superproject .gitea/ --- .gitea/workflows/beta.yaml | 15 +++ .gitea/workflows/deploy_call.yaml | 195 ++++++++++++++++++++++++++++++ .gitea/workflows/release.yaml | 14 +++ apps/dashboard-ui | 2 +- apps/device-agent | 2 +- apps/server-core | 2 +- 6 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/beta.yaml create mode 100644 .gitea/workflows/deploy_call.yaml create mode 100644 .gitea/workflows/release.yaml diff --git a/.gitea/workflows/beta.yaml b/.gitea/workflows/beta.yaml new file mode 100644 index 0000000..37e1fc3 --- /dev/null +++ b/.gitea/workflows/beta.yaml @@ -0,0 +1,15 @@ +name: Beta Release + +on: + push: + tags: + - 'v*-beta*' + - 'v*-test*' + +jobs: + deploy: + if: "contains(gitea.ref_name, 'beta') || contains(gitea.ref_name, 'test')" + uses: ./.gitea/workflows/deploy_call.yaml + with: + prerelease: true + secrets: inherit \ No newline at end of file diff --git a/.gitea/workflows/deploy_call.yaml b/.gitea/workflows/deploy_call.yaml new file mode 100644 index 0000000..47f1575 --- /dev/null +++ b/.gitea/workflows/deploy_call.yaml @@ -0,0 +1,195 @@ +name: Deploy + +on: + workflow_call: + inputs: + prerelease: + description: 'Mark as prerelease' + required: false + type: boolean + default: false + +permissions: + contents: write + +jobs: + build-and-release: + runs-on: ubuntu-latest + steps: + - name: Clone repository with submodules + run: | + git config --global --remove-section http || true + git config --global --unset-all core.askPass || true + TOKEN="${{ secrets.BUILD_TOKEN }}" + git clone --recurse-submodules \ + -c credential.helper="" \ + https://token:$TOKEN@git.datadunia.com/nexusguard/Nexus-Guard-Suite.git . + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.25' + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + + - name: Build Server Core + run: | + cd apps/server-core + go build -o bin/server-core . + + - name: Build Device Agent Cross-platform + run: | + cd apps/device-agent + # Linux amd64 + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/nexus-device-agent-linux-amd64 . + # Linux arm64 + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/nexus-device-agent-linux-arm64 . + # Windows amd64 + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/nexus-device-agent-windows-amd64.exe . + + - name: Build Dashboard UI + run: | + cd apps/dashboard-ui + npm ci || npm install + npm run build + + - name: Generate latest.json + run: | + VERSION="${{ gitea.ref_name }}" + RELEASE_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + REPO="${{ gitea.repository }}" + SERVER="${{ gitea.server_url }}" + cat > latest.json << ENDJSON + { + "version": "$VERSION", + "release_date": "$RELEASE_DATE", + "download_urls": { + "server-core": "${SERVER}/${REPO}/releases/download/${VERSION}/server-core-linux-amd64", + "device-agent-linux-amd64": "${SERVER}/${REPO}/releases/download/${VERSION}/nexus-device-agent-linux-amd64", + "device-agent-linux-arm64": "${SERVER}/${REPO}/releases/download/${VERSION}/nexus-device-agent-linux-arm64", + "device-agent-windows-amd64": "${SERVER}/${REPO}/releases/download/${VERSION}/nexus-device-agent-windows-amd64.exe", + "dashboard-ui": "${SERVER}/${REPO}/releases/download/${VERSION}/dashboard-ui-dist.zip" + } + } + ENDJSON + + - name: Create Release and upload assets + env: + TOKEN: ${{ secrets.BUILD_TOKEN }} + run: | + if [ -z "$TOKEN" ]; then + echo "Value: [EMPTY]" + exit 1 + else + echo "Length: ${#TOKEN} characters" + fi + + REPO="${{ gitea.repository }}" + TAG="${{ gitea.ref_name }}" + API="${{ gitea.server_url }}/api/v1" + + # 0. Check & Delete Existing Release + echo "=== 0. Check & Delete Existing Release ===" + EXISTING_RESP=$(curl -s -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/tags/$TAG") + EXISTING_ID=$(echo "$EXISTING_RESP" | grep -o '"id":[0-9]*' | head -n 1 | cut -d':' -f2 || true) + + if [ -n "$EXISTING_ID" ] && [ "$EXISTING_ID" != "null" ]; then + echo "⚠️ Found existing release for tag $TAG with ID: $EXISTING_ID. Deleting..." + DELETE_RESP=$(curl -s -w "\n%{http_code}" -X DELETE -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/$EXISTING_ID") + echo "✅ Delete response: $DELETE_RESP" + else + echo "No existing release found for $TAG. Proceeding..." + fi + + # 1. Create Release + echo "=== 1. Create New Release ===" + JSON_BODY=$(printf '{"tag_name":"%s","name":"%s","body":"Release %s","draft":false,"prerelease":%s}' "$TAG" "$TAG" "$TAG" "${{ inputs.prerelease }}") + + RELEASE_RESP=$(curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$JSON_BODY" \ + "$API/repos/$REPO/releases") + + # Ambil ID dengan lebih teliti + # Tambahkan || true agar grep tidak membuat script crash (karena set -e) jika id tidak ditemukan + RELEASE_ID=$(echo "$RELEASE_RESP" | grep -o '"id":[0-9]*' | head -n 1 | cut -d':' -f2 || true) + + if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then + echo "Gagal membuat release. Response: $RELEASE_RESP" + exit 1 + fi + + echo "Release ID: $RELEASE_ID" + + # 2. Upload Assets + # Server Core + if [ -f "apps/server-core/bin/server-core" ]; then + echo "Uploading server-core-linux-amd64..." + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@apps/server-core/bin/server-core" \ + "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=server-core-linux-amd64" + fi + + # Device Agent Linux amd64 + if [ -f "apps/device-agent/bin/nexus-device-agent-linux-amd64" ]; then + echo "Uploading nexus-device-agent-linux-amd64..." + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@apps/device-agent/bin/nexus-device-agent-linux-amd64" \ + "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=nexus-device-agent-linux-amd64" + fi + + # Device Agent Linux arm64 + if [ -f "apps/device-agent/bin/nexus-device-agent-linux-arm64" ]; then + echo "Uploading nexus-device-agent-linux-arm64..." + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@apps/device-agent/bin/nexus-device-agent-linux-arm64" \ + "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=nexus-device-agent-linux-arm64" + fi + + # Device Agent Windows amd64 + if [ -f "apps/device-agent/bin/nexus-device-agent-windows-amd64.exe" ]; then + echo "Uploading nexus-device-agent-windows-amd64.exe..." + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@apps/device-agent/bin/nexus-device-agent-windows-amd64.exe" \ + "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=nexus-device-agent-windows-amd64.exe" + fi + + # Dashboard UI dist + if [ -d "apps/dashboard-ui/dist" ]; then + echo "Creating dashboard-ui-dist.zip..." + cd apps/dashboard-ui + zip -r ../dashboard-ui-dist.zip dist/ + cd .. + + echo "Uploading dashboard-ui-dist.zip..." + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@dashboard-ui-dist.zip" \ + "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=dashboard-ui-dist.zip" + fi + + # latest.json + if [ -f "latest.json" ]; then + echo "Uploading latest.json..." + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@latest.json" \ + "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=latest.json" + fi + + - name: Cleanup build artifacts + if: always() + run: | + git config --global --remove-section http || true + git config --global --unset-all core.askPass || true + rm -f latest.json dashboard-ui-dist.zip + rm -rf apps/server-core/bin apps/device-agent/bin apps/dashboard-ui/node_modules apps/dashboard-ui/dist + echo "Cleanup done" \ No newline at end of file diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..2dadcc1 --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,14 @@ +name: Release + +on: + push: + tags: + - 'v[0-9]*.[0-9]*.[0-9]' + +jobs: + deploy: + if: "!contains(gitea.ref_name, 'beta') && !contains(gitea.ref_name, 'test')" + uses: ./.gitea/workflows/deploy_call.yaml + with: + prerelease: false + secrets: inherit \ No newline at end of file diff --git a/apps/dashboard-ui b/apps/dashboard-ui index d77e578..131e551 160000 --- a/apps/dashboard-ui +++ b/apps/dashboard-ui @@ -1 +1 @@ -Subproject commit d77e5782c2e6f8af36e7b3d4e0db4dfad2404449 +Subproject commit 131e5515815eb3f83139f1f1db05fb262813c699 diff --git a/apps/device-agent b/apps/device-agent index c143c6f..31406ca 160000 --- a/apps/device-agent +++ b/apps/device-agent @@ -1 +1 @@ -Subproject commit c143c6f64731797b30142d26080c76fe47e72d36 +Subproject commit 31406caf85bc6ab3ebbf349b13e82f4d14948315 diff --git a/apps/server-core b/apps/server-core index 335e27b..86d9f64 160000 --- a/apps/server-core +++ b/apps/server-core @@ -1 +1 @@ -Subproject commit 335e27b0e1d1fe0b24a42f3a44b393f74f7dc1bb +Subproject commit 86d9f64fc9ede46e680d0ed66bb25e7147658e9c