Skip to content

Commit b4318d7

Browse files
authored
refactor: passing linter for root bash scripts (#1569)
1 parent d6b7880 commit b4318d7

16 files changed

+96
-73
lines changed

build.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091
23

34
set -ex
45

5-
if [ -f "./remote-dependencies.tar" ]; then
6+
if [[ -f "./remote-dependencies.tar" ]]; then
67
tar -xf ./remote-dependencies.tar ./vscode/remote/node_modules
78
fi
89

check_cron_or_pr.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2129
23

34
set -e
45

@@ -22,9 +23,9 @@ else
2223
export SHOULD_DEPLOY="yes"
2324
fi
2425

25-
if [[ "${GITHUB_ENV}" ]]; then
26+
if [[ "${GITHUB_ENV}" ]]; then
2627
echo "GITHUB_BRANCH=${GITHUB_BRANCH}" >> "${GITHUB_ENV}"
27-
echo "SHOULD_BUILD=${SHOULD_BUILD}" >> "${GITHUB_ENV}"
28-
echo "SHOULD_DEPLOY=${SHOULD_DEPLOY}" >> "${GITHUB_ENV}"
28+
echo "SHOULD_BUILD=${SHOULD_BUILD}" >> "${GITHUB_ENV}"
29+
echo "SHOULD_DEPLOY=${SHOULD_DEPLOY}" >> "${GITHUB_ENV}"
2930
echo "VSCODE_QUALITY=${VSCODE_QUALITY}" >> "${GITHUB_ENV}"
3031
fi

check_tags.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2129
23

34
set -e
45

@@ -12,7 +13,7 @@ GITHUB_RESPONSE=$( curl -s -H "Authorization: token ${GITHUB_TOKEN}" "https://ap
1213
LATEST_VERSION=$( echo "${GITHUB_RESPONSE}" | jq -c -r '.tag_name' )
1314

1415
if [[ "${LATEST_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+) ]]; then
15-
if [ "${MS_TAG}" != "${BASH_REMATCH[1]}" ]; then
16+
if [[ "${MS_TAG}" != "${BASH_REMATCH[1]}" ]]; then
1617
echo "New VSCode version, new build"
1718
export SHOULD_BUILD="yes"
1819
elif [[ "${NEW_RELEASE}" == "true" ]]; then
@@ -22,7 +23,7 @@ if [[ "${LATEST_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+) ]]; then
2223
BODY=$( echo "${GITHUB_RESPONSE}" | jq -c -r '.body' )
2324

2425
if [[ "${BODY}" =~ \[([a-z0-9]+)\] ]]; then
25-
if [ "${MS_COMMIT}" != "${BASH_REMATCH[1]}" ]; then
26+
if [[ "${MS_COMMIT}" != "${BASH_REMATCH[1]}" ]]; then
2627
echo "New VSCode Insiders version, new build"
2728
export SHOULD_BUILD="yes"
2829
fi
@@ -46,7 +47,7 @@ contains() {
4647
echo "${ASSETS}" | grep "${1}\""
4748
}
4849

49-
if [ "${ASSETS}" != "null" ]; then
50+
if [[ "${ASSETS}" != "null" ]]; then
5051
# macos
5152
if [[ "${OS_NAME}" == "osx" ]]; then
5253
if [[ "${VSCODE_ARCH}" == "arm64" ]]; then
@@ -366,6 +367,7 @@ else
366367
export SHOULD_BUILD="yes"
367368
fi
368369

370+
369371
echo "SHOULD_BUILD=${SHOULD_BUILD}" >> "${GITHUB_ENV}"
370372
echo "SHOULD_BUILD_APPIMAGE=${SHOULD_BUILD_APPIMAGE}" >> "${GITHUB_ENV}"
371373
echo "SHOULD_BUILD_DEB=${SHOULD_BUILD_DEB}" >> "${GITHUB_ENV}"

get_repo.sh

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2129
23

34
set -e
45

@@ -12,28 +13,28 @@ if [[ -z "${RELEASE_VERSION}" ]]; then
1213
if [[ "${VSCODE_LATEST}" == "yes" ]] || [[ ! -f "insider.json" ]]; then
1314
UPDATE_INFO=$( curl --silent --fail https://update.code.visualstudio.com/api/update/darwin/insider/0000000000000000000000000000000000000000 )
1415
else
15-
export MS_COMMIT=$(jq -r '.commit' insider.json)
16-
export MS_TAG=$(jq -r '.tag' insider.json)
16+
MS_COMMIT=$( jq -r '.commit' insider.json )
17+
MS_TAG=$( jq -r '.tag' insider.json )
1718
fi
1819
else
1920
UPDATE_INFO=$( curl --silent --fail https://update.code.visualstudio.com/api/update/darwin/stable/0000000000000000000000000000000000000000 )
2021
fi
2122

2223
if [[ -z "${MS_COMMIT}" ]]; then
23-
export MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
24-
export MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
24+
MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
25+
MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
2526

2627
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
27-
export MS_TAG="${MS_TAG/\-insider/}"
28+
MS_TAG="${MS_TAG/\-insider/}"
2829
fi
2930
fi
3031

3132
date=$( date +%Y%j )
3233

3334
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
34-
export RELEASE_VERSION="${MS_TAG}.${date: -5}-insider"
35+
RELEASE_VERSION="${MS_TAG}.${date: -5}-insider"
3536
else
36-
export RELEASE_VERSION="${MS_TAG}.${date: -5}"
37+
RELEASE_VERSION="${MS_TAG}.${date: -5}"
3738
fi
3839
else
3940
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
@@ -45,8 +46,8 @@ else
4546
exit 1
4647
fi
4748

48-
if [[ "${MS_TAG}" == "$(jq -r '.tag' insider.json)" ]]; then
49-
export MS_COMMIT=$(jq -r '.commit' insider.json)
49+
if [[ "${MS_TAG}" == "$( jq -r '.tag' insider.json )" ]]; then
50+
MS_COMMIT=$( jq -r '.commit' insider.json )
5051
else
5152
echo "Error: No MS_COMMIT for ${RELEASE_VERSION}"
5253
exit 1
@@ -77,17 +78,17 @@ if [[ -z "${MS_TAG}" ]]; then
7778
else
7879
UPDATE_INFO=$( curl --silent --fail https://update.code.visualstudio.com/api/update/darwin/stable/0000000000000000000000000000000000000000 )
7980
fi
80-
export MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
81-
export MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
81+
MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
82+
MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
8283
elif [[ -z "${MS_COMMIT}" ]]; then
8384
REFERENCE=$( git ls-remote --tags | grep -x ".*refs\/tags\/${MS_TAG}" | head -1 )
8485

8586
if [[ -z "${REFERENCE}" ]]; then
8687
echo "Error: The following tag can't be found: ${MS_TAG}"
8788
exit 1
8889
elif [[ "${REFERENCE}" =~ ^([[:alnum:]]+)[[:space:]]+refs\/tags\/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
89-
export MS_COMMIT="${BASH_REMATCH[1]}"
90-
export MS_TAG="${BASH_REMATCH[2]}"
90+
MS_COMMIT="${BASH_REMATCH[1]}"
91+
MS_TAG="${BASH_REMATCH[2]}"
9192
else
9293
echo "Error: The following reference can't be parsed: ${REFERENCE}"
9394
exit 1
@@ -108,3 +109,7 @@ if [[ "${GITHUB_ENV}" ]]; then
108109
echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
109110
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
110111
fi
112+
113+
export MS_TAG
114+
export MS_COMMIT
115+
export RELEASE_VERSION

install_gh.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -ex
44

55
GH_ARCH="amd64"
66

7-
VERSION=`curl --retry 12 --retry-delay 30 "https://api.github.com/repos/cli/cli/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c2-`
7+
VERSION=$( curl --retry 12 --retry-delay 30 "https://api.github.com/repos/cli/cli/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c2- )
88

99
curl --retry 12 --retry-delay 120 -sSL "https://github.com/cli/cli/releases/download/v${VERSION}/gh_${VERSION}_linux_${GH_ARCH}.tar.gz" -o "gh_${VERSION}_linux_${GH_ARCH}.tar.gz"
1010

install_remote_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

patch.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
if [[ "${1}" == *patch ]]; then
44
FILE="../patches/${1}"
@@ -17,7 +17,7 @@ fi
1717

1818
git apply --reject "../patches/helper/settings.patch"
1919

20-
read -p "Press any key when the conflict have been resolved..." -n1 -s
20+
read -rp "Press any key when the conflict have been resolved..." -n1 -s
2121

2222
git restore .vscode/settings.json
2323

prepare_assets.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091
23

34
set -e
45

@@ -29,7 +30,7 @@ if [[ "${OS_NAME}" == "osx" ]]; then
2930
security create-keychain -p mysecretpassword "${KEYCHAIN}"
3031
security set-keychain-settings -lut 21600 "${KEYCHAIN}"
3132
security unlock-keychain -p mysecretpassword "${KEYCHAIN}"
32-
security list-keychains -s `security list-keychains | xargs` "${KEYCHAIN}"
33+
security list-keychains -s "$(security list-keychains | xargs)" "${KEYCHAIN}"
3334
# security list-keychains -d user
3435
# security show-keychain-info ${KEYCHAIN}
3536

prepare_vscode.sh

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091,2154
23

34
set -e
45

@@ -21,32 +22,29 @@ cd vscode || { echo "'vscode' dir not found"; exit 1; }
2122
{ set +x; } 2>/dev/null
2223

2324
for file in ../patches/*.patch; do
24-
if [ -f "${file}" ]; then
25+
if [[ -f "${file}" ]]; then
2526
echo applying patch: "${file}";
26-
git apply --ignore-whitespace "${file}"
27-
if [ $? -ne 0 ]; then
27+
if ! git apply --ignore-whitespace "${file}"; then
2828
echo failed to apply patch "${file}" 1>&2
2929
fi
3030
fi
3131
done
3232

3333
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
3434
for file in ../patches/insider/*.patch; do
35-
if [ -f "${file}" ]; then
35+
if [[ -f "${file}" ]]; then
3636
echo applying patch: "${file}";
37-
git apply --ignore-whitespace "${file}"
38-
if [ $? -ne 0 ]; then
37+
if ! git apply --ignore-whitespace "${file}"; then
3938
echo failed to apply patch "${file}" 1>&2
4039
fi
4140
fi
4241
done
4342
fi
4443

4544
for file in ../patches/user/*.patch; do
46-
if [ -f "${file}" ]; then
45+
if [[ -f "${file}" ]]; then
4746
echo applying user patch: "${file}";
48-
git apply --ignore-whitespace "${file}"
49-
if [ $? -ne 0 ]; then
47+
if ! git apply --ignore-whitespace "${file}"; then
5048
echo failed to apply patch "${file}" 1>&2
5149
fi
5250
fi
@@ -75,7 +73,8 @@ else
7573
git checkout 102b347da0c92c29f9c67df22e864e70249cf086
7674
npm install
7775

78-
export npm_config_node_gyp=`pwd`
76+
npm_config_node_gyp=$( pwd )
77+
export npm_config_node_gyp
7978

8079
cd ../..
8180
fi
@@ -84,14 +83,18 @@ else
8483
fi
8584

8685
setpath() {
86+
local jsonTmp
8787
{ set +x; } 2>/dev/null
88-
echo "$( cat "${1}.json" | jq --arg 'path' "${2}" --arg 'value' "${3}" 'setpath([$path]; $value)' )" > "${1}.json"
88+
jsonTmp=$( jq --arg 'path' "${2}" --arg 'value' "${3}" 'setpath([$path]; $value)' "${1}.json" )
89+
echo "${jsonTmp}" > "${1}.json"
8990
set -x
9091
}
9192

9293
setpath_json() {
94+
local jsonTmp
9395
{ set +x; } 2>/dev/null
94-
echo "$( cat "${1}.json" | jq --arg 'path' "${2}" --argjson 'value' "${3}" 'setpath([$path]; $value)' )" > "${1}.json"
96+
jsonTmp=$( jq --arg 'path' "${2}" --argjson 'value' "${3}" 'setpath([$path]; $value)' "${1}.json" )
97+
echo "${jsonTmp}" > "${1}.json"
9598
set -x
9699
}
97100

@@ -165,20 +168,22 @@ else
165168
setpath "product" "win32arm64UserAppId" "{{57FD70A5-1B8D-4875-9F40-C5553F094828}"
166169
fi
167170

168-
echo "$( jq -s '.[0] * .[1]' product.json ../product.json )" > product.json
171+
jsonTmp=$( jq -s '.[0] * .[1]' product.json ../product.json )
172+
echo "${jsonTmp}" > ../product.json
173+
unset jsonTmp
169174

170175
cat product.json
171176

172177
# package.json
173178
cp package.json package.json.bak
174179

175-
setpath "package" "version" $( echo "${RELEASE_VERSION}" | sed -n -E "s/^(.*)\.([0-9]+)(-insider)?$/\1/p" )
176-
setpath "package" "release" $( echo "${RELEASE_VERSION}" | sed -n -E "s/^(.*)\.([0-9]+)(-insider)?$/\2/p" )
180+
setpath "package" "version" "$( echo "${RELEASE_VERSION}" | sed -n -E "s/^(.*)\.([0-9]+)(-insider)?$/\1/p" )"
181+
setpath "package" "release" "$( echo "${RELEASE_VERSION}" | sed -n -E "s/^(.*)\.([0-9]+)(-insider)?$/\2/p" )"
177182

178183
replace 's|Microsoft Corporation|VSCodium|' package.json
179184

180185
# announcements
181-
replace "s|\\[\\/\\* BUILTIN_ANNOUNCEMENTS \\*\\/\\]|$( cat ../announcements-builtin.json | tr -d '\n' )|" src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts
186+
replace "s|\\[\\/\\* BUILTIN_ANNOUNCEMENTS \\*\\/\\]|$( tr -d '\n' < ../announcements-builtin.json )|" src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts
182187

183188
../undo_telemetry.sh
184189

release.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

@@ -19,7 +19,7 @@ if [[ $( gh release view --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" 2>&1
1919
NOTES="update vscode to [${MS_COMMIT}](https://github.com/microsoft/vscode/tree/${MS_COMMIT})"
2020
CREATE_OPTIONS=""
2121
else
22-
NOTES="update vscode to [${MS_TAG}](https://code.visualstudio.com/updates/v$( echo ${MS_TAG//./_} | cut -d'_' -f 1,2 ))"
22+
NOTES="update vscode to [${MS_TAG}](https://code.visualstudio.com/updates/v$( echo "${MS_TAG//./_}" | cut -d'_' -f 1,2 ))"
2323
CREATE_OPTIONS="--generate-notes"
2424
fi
2525

undo_telemetry.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091,SC2016
23

34
set -ex
45

@@ -25,7 +26,7 @@ else
2526
fi
2627
export -f replace_with_debug
2728

28-
d1=`date +%s`
29+
d1=$( date +%s )
2930

3031
if [[ "${OS_NAME}" == "linux" ]]; then
3132
if [[ ${VSCODE_ARCH} == "x64" ]]; then
@@ -39,6 +40,6 @@ else
3940
./node_modules/@vscode/ripgrep/bin/rg --no-ignore --path-separator=// -l "${SEARCH}" . | xargs -I {} bash -c 'replace_with_debug "${1}" "{}"' _ "${REPLACEMENT}"
4041
fi
4142

42-
d2=`date +%s`
43+
d2=$( date +%s )
4344

44-
echo "undo_telemetry: $( echo $((${d2} - ${d1})) )s"
45+
echo "undo_telemetry: $((d2 - d1))s"

update_insider.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

@@ -12,15 +12,16 @@ if [[ -z "${GITHUB_TOKEN}" ]]; then
1212
exit
1313
fi
1414

15-
echo "$( cat "insider.json" | jq --arg 'tag' "${MS_TAG/\-insider/}" --arg 'commit' "${MS_COMMIT}" '. | .tag=$tag | .commit=$commit' )" > "insider.json"
15+
jsonTmp=$( jq --arg 'tag' "${MS_TAG/\-insider/}" --arg 'commit' "${MS_COMMIT}" '. "insider.json" | .tag=$tag | .commit=$commit' )
16+
echo "${jsonTmp}" > "insider.json" && unset jsonTmp
1617

1718
git config user.email "$( echo "${GITHUB_USERNAME}" | awk '{print tolower($0)}' )[email protected]"
1819
git config user.name "${GITHUB_USERNAME} CI"
1920
git add .
2021

2122
CHANGES=$( git status --porcelain )
2223

23-
if [[ ! -z "${CHANGES}" ]]; then
24+
if [[ -n "${CHANGES}" ]]; then
2425
git commit -m "build(insider): update to commit ${MS_COMMIT:0:7}"
2526

2627
if ! git push origin insider --quiet; then

update_settings.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# shellcheck disable=SC1091,2148
2+
13
DEFAULT_TRUE="'default': true"
24
DEFAULT_FALSE="'default': false"
35
DEFAULT_ON="'default': TelemetryConfiguration.ON"
@@ -21,7 +23,7 @@ update_setting () {
2123
local SETTING="${1}"
2224
local LINE_NUM=0
2325
while read -r line; do
24-
local LINE_NUM=$(( $LINE_NUM + 1 ))
26+
local LINE_NUM=$(( LINE_NUM + 1 ))
2527
if [[ "${line}" == *"${SETTING}"* ]]; then
2628
local IN_SETTING=1
2729
fi

0 commit comments

Comments
 (0)