forked from VSCodium/vscodium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_repo.sh
executable file
·118 lines (98 loc) · 3.53 KB
/
get_repo.sh
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
#!/usr/bin/env bash
# shellcheck disable=SC2129
set -e
# git workaround
if [[ "${CI_BUILD}" != "no" ]]; then
git config --global --add safe.directory "/__w/$( echo "${GITHUB_REPOSITORY}" | awk '{print tolower($0)}' )"
fi
if [[ -n "${PULL_REQUEST_ID}" ]]; then
BRANCH_NAME=$( git rev-parse --abbrev-ref HEAD )
git config --global user.email "$( echo "${GITHUB_USERNAME}" | awk '{print tolower($0)}' )[email protected]"
git config --global user.name "${GITHUB_USERNAME} CI"
git fetch --unshallow
git fetch origin "pull/${PULL_REQUEST_ID}/head"
git checkout FETCH_HEAD
git merge --no-edit "origin/${BRANCH_NAME}"
fi
if [[ -z "${RELEASE_VERSION}" ]]; then
if [[ "${VSCODE_LATEST}" == "yes" ]] || [[ ! -f "${VSCODE_QUALITY}.json" ]]; then
UPDATE_INFO=$( curl --silent --fail "https://update.code.visualstudio.com/api/update/darwin/${VSCODE_QUALITY}/0000000000000000000000000000000000000000" )
else
MS_COMMIT=$( jq -r '.commit' "${VSCODE_QUALITY}.json" )
MS_TAG=$( jq -r '.tag' "${VSCODE_QUALITY}.json" )
fi
if [[ -z "${MS_COMMIT}" ]]; then
MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
MS_TAG="${MS_TAG/\-insider/}"
fi
fi
date=$( date +%Y%j )
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
RELEASE_VERSION="${MS_TAG}.${date: -5}-insider"
else
RELEASE_VERSION="${MS_TAG}.${date: -5}"
fi
else
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
if [[ "${RELEASE_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+-insider$ ]];
then
MS_TAG="${BASH_REMATCH[1]}"
else
echo "Error: Bad RELEASE_VERSION: ${RELEASE_VERSION}"
exit 1
fi
else
if [[ "${RELEASE_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$ ]];
then
MS_TAG="${BASH_REMATCH[1]}"
else
echo "Error: Bad RELEASE_VERSION: ${RELEASE_VERSION}"
exit 1
fi
fi
if [[ "${MS_TAG}" == "$( jq -r '.tag' "${VSCODE_QUALITY}".json )" ]]; then
MS_COMMIT=$( jq -r '.commit' "${VSCODE_QUALITY}".json )
else
echo "Error: No MS_COMMIT for ${RELEASE_VERSION}"
exit 1
fi
fi
echo "RELEASE_VERSION=\"${RELEASE_VERSION}\""
mkdir -p vscode
cd vscode || { echo "'vscode' dir not found"; exit 1; }
git init -q
git remote add origin https://github.com/Microsoft/vscode.git
# figure out latest tag by calling MS update API
if [[ -z "${MS_TAG}" ]]; then
UPDATE_INFO=$( curl --silent --fail "https://update.code.visualstudio.com/api/update/darwin/${VSCODE_QUALITY}/0000000000000000000000000000000000000000" )
MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
elif [[ -z "${MS_COMMIT}" ]]; then
REFERENCE=$( git ls-remote --tags | grep -x ".*refs\/tags\/${MS_TAG}" | head -1 )
if [[ -z "${REFERENCE}" ]]; then
echo "Error: The following tag can't be found: ${MS_TAG}"
exit 1
elif [[ "${REFERENCE}" =~ ^([[:alnum:]]+)[[:space:]]+refs\/tags\/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
MS_COMMIT="${BASH_REMATCH[1]}"
MS_TAG="${BASH_REMATCH[2]}"
else
echo "Error: The following reference can't be parsed: ${REFERENCE}"
exit 1
fi
fi
echo "MS_TAG=\"${MS_TAG}\""
echo "MS_COMMIT=\"${MS_COMMIT}\""
git fetch --depth 1 origin "${MS_COMMIT}"
git checkout FETCH_HEAD
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}"
fi
export MS_TAG
export MS_COMMIT
export RELEASE_VERSION