forked from voideditor/void-builder
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_repo.sh
More file actions
executable file
·165 lines (135 loc) · 5.17 KB
/
get_repo.sh
File metadata and controls
executable file
·165 lines (135 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
# shellcheck disable=SC2129
set -e
# Echo all environment variables used by this script
echo "----------- get_repo -----------"
echo "Environment variables:"
echo "CI_BUILD=${CI_BUILD}"
echo "GITHUB_REPOSITORY=${GITHUB_REPOSITORY}"
echo "RELEASE_VERSION=${RELEASE_VERSION}"
echo "VSCODE_LATEST=${VSCODE_LATEST}"
echo "VSCODE_QUALITY=${VSCODE_QUALITY}"
echo "GITHUB_ENV=${GITHUB_ENV}"
echo "SHOULD_DEPLOY=${SHOULD_DEPLOY}"
echo "SHOULD_BUILD=${SHOULD_BUILD}"
echo "-------------------------"
# git workaround
if [[ "${CI_BUILD}" != "no" ]]; then
git config --global --add safe.directory "/__w/$( echo "${GITHUB_REPOSITORY}" | awk '{print tolower($0)}' )"
fi
# Check if local CortexIDE repo exists
CORTEXIDE_REPO="../cortexide"
if [[ -d "${CORTEXIDE_REPO}" && -f "${CORTEXIDE_REPO}/package.json" ]]; then
echo "Using local CortexIDE repository at ${CORTEXIDE_REPO}..."
# Remove existing vscode directory if it exists
rm -rf vscode
# Copy the local CortexIDE repo to vscode directory (exclude heavy/temp files)
echo "Copying CortexIDE repository to vscode directory..."
mkdir -p vscode
rsync -a --delete \
--exclude ".git" \
--exclude "node_modules" \
--exclude "out" \
--exclude ".build" \
--exclude ".vscode" \
--exclude "**/.vscode" \
--exclude "**/node_modules" \
"${CORTEXIDE_REPO}/" "vscode/"
cd vscode || { echo "'vscode' dir not found"; exit 1; }
# Get version info from local repo
MS_TAG=$( jq -r '.version' "package.json" )
MS_COMMIT=$( git rev-parse HEAD 2>/dev/null || echo "local" )
# Check for CortexIDE version fields (cortexVersion/cortexRelease) or fallback to voidVersion/voidRelease
if jq -e '.cortexVersion' product.json > /dev/null 2>&1; then
CORTEX_VERSION=$( jq -r '.cortexVersion' "product.json" )
CORTEX_RELEASE=$( jq -r '.cortexRelease' "product.json" )
elif jq -e '.voidVersion' product.json > /dev/null 2>&1; then
CORTEX_VERSION=$( jq -r '.voidVersion' "product.json" )
CORTEX_RELEASE=$( jq -r '.voidRelease' "product.json" )
else
CORTEX_VERSION="${MS_TAG}"
CORTEX_RELEASE="0000"
fi
# Allow override via environment variable
if [[ -n "${CORTEXIDE_RELEASE}" ]]; then
CORTEX_RELEASE="${CORTEXIDE_RELEASE}"
fi
if [[ -n "${CORTEX_RELEASE}" ]]; then
RELEASE_VERSION="${MS_TAG}${CORTEX_RELEASE}"
else
RELEASE_VERSION="${MS_TAG}0000"
fi
else
# Fallback to cloning from GitHub (for CI or if local repo not found)
CORTEXIDE_BRANCH="main"
echo "Local CortexIDE repo not found, cloning from GitHub ${CORTEXIDE_BRANCH}..."
# Remove existing vscode directory if it exists
rm -rf vscode
mkdir -p vscode
cd vscode || { echo "'vscode' dir not found"; exit 1; }
git init -q
# Use GITHUB_TOKEN if available for authentication (GitHub Actions provides this automatically)
# Otherwise use the public URL
if [[ -n "${GITHUB_TOKEN}" ]]; then
echo "Using GITHUB_TOKEN for authentication"
git remote add origin "https://${GITHUB_TOKEN}@github.com/OpenCortexIDE/cortexide.git"
else
git remote add origin https://github.com/OpenCortexIDE/cortexide.git
fi
# Allow callers to specify a particular commit to checkout via the
# environment variable CORTEXIDE_COMMIT. We still default to the tip of the
# ${CORTEXIDE_BRANCH} branch when the variable is not provided.
if [[ -n "${CORTEXIDE_COMMIT}" ]]; then
echo "Using explicit commit ${CORTEXIDE_COMMIT}"
# Fetch just that commit to keep the clone shallow.
git fetch --depth 1 origin "${CORTEXIDE_COMMIT}"
git checkout "${CORTEXIDE_COMMIT}"
else
git fetch --depth 1 origin "${CORTEXIDE_BRANCH}"
git checkout FETCH_HEAD
fi
MS_TAG=$( jq -r '.version' "package.json" )
MS_COMMIT=$CORTEXIDE_BRANCH
# Check for CortexIDE version fields or fallback
if jq -e '.cortexVersion' product.json > /dev/null 2>&1; then
CORTEX_VERSION=$( jq -r '.cortexVersion' "product.json" )
CORTEX_RELEASE=$( jq -r '.cortexRelease' "product.json" )
elif jq -e '.voidVersion' product.json > /dev/null 2>&1; then
CORTEX_VERSION=$( jq -r '.voidVersion' "product.json" )
CORTEX_RELEASE=$( jq -r '.voidRelease' "product.json" )
else
CORTEX_VERSION="${MS_TAG}"
CORTEX_RELEASE="0000"
fi
# Allow override via environment variable
if [[ -n "${CORTEXIDE_RELEASE}" ]]; then
CORTEX_RELEASE="${CORTEXIDE_RELEASE}"
fi
if [[ -n "${CORTEX_RELEASE}" ]]; then
RELEASE_VERSION="${MS_TAG}${CORTEX_RELEASE}"
else
RELEASE_VERSION="${MS_TAG}0000"
fi
fi
echo "RELEASE_VERSION=\"${RELEASE_VERSION}\""
echo "MS_COMMIT=\"${MS_COMMIT}\""
echo "MS_TAG=\"${MS_TAG}\""
echo "CORTEX_VERSION=\"${CORTEX_VERSION}\""
cd ..
# for GH actions
if [[ "${GITHUB_ENV}" ]]; then
echo "MS_TAG=${MS_TAG}" >> "${GITHUB_ENV}"
echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
echo "CORTEX_VERSION=${CORTEX_VERSION}" >> "${GITHUB_ENV}"
fi
echo "----------- get_repo exports -----------"
echo "MS_TAG ${MS_TAG}"
echo "MS_COMMIT ${MS_COMMIT}"
echo "RELEASE_VERSION ${RELEASE_VERSION}"
echo "CORTEX_VERSION ${CORTEX_VERSION}"
echo "----------------------"
export MS_TAG
export MS_COMMIT
export RELEASE_VERSION
export CORTEX_VERSION