microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/transparency-note

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.github/skills/installer/hve-core-installer/scripts/agent-copy.sh

85lines · modecode

1#!/usr/bin/env bash
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4# Copies selected HVE-Core agents to the target repository.
5# Creates .github/agents/, copies agent files, computes SHA256 hashes,
6# and writes .hve-tracking.json manifest for upgrade tracking.
7# Usage: agent-copy.sh <hve_core_base_path> <collection_id> <file1> [file2...]
8# Files are paths relative to the agents/ directory.
9set -euo pipefail
10
11hve_core_base_path="${1:?Usage: $0 <hve_core_base_path> <collection_id> <file1> [file2...]}"
12collection_id="${2:?Usage: $0 <hve_core_base_path> <collection_id> <file1> [file2...]}"
13shift 2
14
15source_base="$hve_core_base_path/.github/agents"
16target_dir=".github/agents"
17manifest_path=".hve-tracking.json"
18keep_existing="${KEEP_EXISTING:-false}"
19collisions_file="${COLLISIONS_FILE:-}"
20has_jq=false
21command -v jq >/dev/null 2>&1 && has_jq=true
22
23# Load collision list when keep_existing is enabled
24declare -A collision_set
25if [ "$keep_existing" = "true" ] && [ -n "$collisions_file" ] && [ -f "$collisions_file" ]; then
26 while IFS= read -r line; do
27 [ -n "$line" ] && collision_set["$line"]=1
28 done < "$collisions_file"
29fi
30
31# Create target directory
32mkdir -p "$target_dir"
33
34# Get version from package.json
35if [ "$has_jq" = true ]; then
36 version=$(jq -r '.version' "$hve_core_base_path/package.json")
37else
38 version=$(grep -o '"version": *"[^"]*"' "$hve_core_base_path/package.json" | head -1 | sed 's/.*"\([^"]*\)"/\1/')
39fi
40
41# Initialize manifest JSON
42installed=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
43files_json="{}"
44
45# Copy files (source paths are relative to agents/, target is flat)
46for file in "$@"; do
47 filename=$(basename "$file")
48 source_path="$source_base/$file"
49 target_path="$target_dir/$filename"
50 rel_path=".github/agents/$filename"
51
52 # Skip files the user chose to keep during collision resolution
53 if [ "$keep_existing" = "true" ] && [ -n "${collision_set[$target_path]+x}" ]; then
54 echo "⏭️ Kept existing: $filename"
55 continue
56 fi
57
58 cp "$source_path" "$target_path"
59 hash=$(sha256sum "$target_path" | cut -d' ' -f1)
60 if [ "$has_jq" = true ]; then
61 files_json=$(echo "$files_json" | jq --arg path "$rel_path" --arg ver "$version" --arg sha "$hash" \
62 '. + {($path): {"version": $ver, "sha256": $sha, "status": "managed"}}')
63 else
64 # Build JSON entries without jq
65 if [ "$files_json" = "{}" ]; then
66 files_json="{\"$rel_path\": {\"version\": \"$version\", \"sha256\": \"$hash\", \"status\": \"managed\"}}"
67 else
68 files_json="${files_json%\}}, \"$rel_path\": {\"version\": \"$version\", \"sha256\": \"$hash\", \"status\": \"managed\"}}"
69 fi
70 fi
71 echo "✅ Copied $filename"
72done
73
74# Write manifest
75if [ "$has_jq" = true ]; then
76 jq -n --arg src "microsoft/hve-core" --arg ver "$version" --arg inst "$installed" \
77 --arg col "$collection_id" --argjson files "$files_json" \
78 '{source: $src, version: $ver, installed: $inst, collection: $col, files: $files}' \
79 > "$manifest_path"
80else
81 cat > "$manifest_path" <<EOF
82{"source": "microsoft/hve-core", "version": "$version", "installed": "$installed", "collection": "$collection_id", "files": $files_json}
83EOF
84fi
85echo "✅ Created $manifest_path"
86