name: Release on: workflow_call: inputs: prerelease: description: 'Mark as prerelease' required: false type: boolean default: false draft: description: 'Mark as draft' required: false type: boolean default: false permissions: contents: write jobs: release: runs-on: ubuntu-latest steps: - name: Configure git auth for submodules run: git config --global url."https://x-access-token:${{ secrets.BUILD_TOKEN }}@git.datadunia.com/".insteadOf "https://git.datadunia.com/" - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.BUILD_TOKEN }} persist-credentials: true - name: Download all artifacts uses: actions/download-artifact@v3 with: path: ./artifacts - 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.tar.gz", "android-agent": "${SERVER}/${REPO}/releases/download/${VERSION}/nexusguard-android.apk" } } ENDJSON - name: Create Release and upload assets env: TOKEN: ${{ secrets.BUILD_TOKEN }} run: | REPO="${{ gitea.repository }}" TAG="${{ gitea.ref_name }}" API="${{ gitea.server_url }}/api/v1" # Delete existing release if present EXISTING_ID=$(curl -s -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/tags/$TAG" | grep -o '"id":[0-9]*' | head -n 1 | cut -d':' -f2 || true) if [ -n "$EXISTING_ID" ] && [ "$EXISTING_ID" != "null" ]; then echo "Deleting existing release $EXISTING_ID..." curl -s -X DELETE -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/$EXISTING_ID" fi # Create release JSON_BODY=$(printf '{"tag_name":"%s","name":"%s","body":"Release %s","draft":%s,"prerelease":%s}' "$TAG" "$TAG" "$TAG" "${{ inputs.draft }}" "${{ inputs.prerelease }}") RELEASE_RESP=$(curl -s -X POST \ -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "$JSON_BODY" \ "$API/repos/$REPO/releases") 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 "Failed to create release. Response: $RELEASE_RESP" exit 1 fi echo "Release ID: $RELEASE_ID" # Upload assets upload_asset() { local file="$1" local name="$2" if [ -f "$file" ]; then echo "Uploading $name..." curl -s -X POST \ -H "Authorization: token $TOKEN" \ -F "attachment=@$file" \ "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$name" fi } # Server Core upload_asset "artifacts/server-core-linux-amd64/server-core" "server-core-linux-amd64" # Device Agent (all platforms) for platform in linux-amd64 linux-arm64 windows-amd64; do EXT="" if [ "$platform" = "windows-amd64" ]; then EXT=".exe"; fi upload_asset "artifacts/nexus-device-agent-${platform}/nexus-device-agent-${platform}${EXT}" "nexus-device-agent-${platform}${EXT}" done # Dashboard UI tar.gz if [ -d "artifacts/dashboard-ui-dist/dist" ]; then cd artifacts/dashboard-ui-dist tar -czf ../../dashboard-ui-dist.tar.gz dist/ cd ../.. upload_asset "dashboard-ui-dist.tar.gz" "dashboard-ui-dist.tar.gz" fi # Android Agent APK if [ -f "artifacts/nexusguard-android-debug/nexusguard-android-debug.apk" ]; then upload_asset "artifacts/nexusguard-android-debug/nexusguard-android-debug.apk" "nexusguard-android.apk" elif [ -f "artifacts/nexusguard-android-release/nexusguard-android-release.apk" ]; then upload_asset "artifacts/nexusguard-android-release/nexusguard-android-release.apk" "nexusguard-android.apk" fi # Docs tar.gz if [ -d "artifacts/docs-dist" ]; then cd artifacts/docs-dist tar -czf ../../docs-dist.tar.gz ./ cd ../.. upload_asset "docs-dist.tar.gz" "docs-dist.tar.gz" fi # latest.json upload_asset "latest.json" "latest.json" - name: Cleanup if: always() run: rm -rf artifacts/ latest.json dashboard-ui-dist.tar.gz docs-dist.tar.gz