Skip to content

Commit

Permalink
refactor: passing linter for root bash scripts (#1569)
Browse files Browse the repository at this point in the history
  • Loading branch information
zpiatt authored Jul 20, 2023
1 parent d6b7880 commit b4318d7
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 73 deletions.
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC1091

set -ex

if [ -f "./remote-dependencies.tar" ]; then
if [[ -f "./remote-dependencies.tar" ]]; then
tar -xf ./remote-dependencies.tar ./vscode/remote/node_modules
fi

Expand Down
9 changes: 5 additions & 4 deletions check_cron_or_pr.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC2129

set -e

Expand All @@ -22,9 +23,9 @@ else
export SHOULD_DEPLOY="yes"
fi

if [[ "${GITHUB_ENV}" ]]; then
if [[ "${GITHUB_ENV}" ]]; then
echo "GITHUB_BRANCH=${GITHUB_BRANCH}" >> "${GITHUB_ENV}"
echo "SHOULD_BUILD=${SHOULD_BUILD}" >> "${GITHUB_ENV}"
echo "SHOULD_DEPLOY=${SHOULD_DEPLOY}" >> "${GITHUB_ENV}"
echo "SHOULD_BUILD=${SHOULD_BUILD}" >> "${GITHUB_ENV}"
echo "SHOULD_DEPLOY=${SHOULD_DEPLOY}" >> "${GITHUB_ENV}"
echo "VSCODE_QUALITY=${VSCODE_QUALITY}" >> "${GITHUB_ENV}"
fi
10 changes: 6 additions & 4 deletions check_tags.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC2129

set -e

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

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

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

if [ "${ASSETS}" != "null" ]; then
if [[ "${ASSETS}" != "null" ]]; then
# macos
if [[ "${OS_NAME}" == "osx" ]]; then
if [[ "${VSCODE_ARCH}" == "arm64" ]]; then
Expand Down Expand Up @@ -366,6 +367,7 @@ else
export SHOULD_BUILD="yes"
fi


echo "SHOULD_BUILD=${SHOULD_BUILD}" >> "${GITHUB_ENV}"
echo "SHOULD_BUILD_APPIMAGE=${SHOULD_BUILD_APPIMAGE}" >> "${GITHUB_ENV}"
echo "SHOULD_BUILD_DEB=${SHOULD_BUILD_DEB}" >> "${GITHUB_ENV}"
Expand Down
33 changes: 19 additions & 14 deletions get_repo.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC2129

set -e

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

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

if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
export MS_TAG="${MS_TAG/\-insider/}"
MS_TAG="${MS_TAG/\-insider/}"
fi
fi

date=$( date +%Y%j )

if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
export RELEASE_VERSION="${MS_TAG}.${date: -5}-insider"
RELEASE_VERSION="${MS_TAG}.${date: -5}-insider"
else
export RELEASE_VERSION="${MS_TAG}.${date: -5}"
RELEASE_VERSION="${MS_TAG}.${date: -5}"
fi
else
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
Expand All @@ -45,8 +46,8 @@ else
exit 1
fi

if [[ "${MS_TAG}" == "$(jq -r '.tag' insider.json)" ]]; then
export MS_COMMIT=$(jq -r '.commit' insider.json)
if [[ "${MS_TAG}" == "$( jq -r '.tag' insider.json )" ]]; then
MS_COMMIT=$( jq -r '.commit' insider.json )
else
echo "Error: No MS_COMMIT for ${RELEASE_VERSION}"
exit 1
Expand Down Expand Up @@ -77,17 +78,17 @@ if [[ -z "${MS_TAG}" ]]; then
else
UPDATE_INFO=$( curl --silent --fail https://update.code.visualstudio.com/api/update/darwin/stable/0000000000000000000000000000000000000000 )
fi
export MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
export MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
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
export MS_COMMIT="${BASH_REMATCH[1]}"
export MS_TAG="${BASH_REMATCH[2]}"
MS_COMMIT="${BASH_REMATCH[1]}"
MS_TAG="${BASH_REMATCH[2]}"
else
echo "Error: The following reference can't be parsed: ${REFERENCE}"
exit 1
Expand All @@ -108,3 +109,7 @@ if [[ "${GITHUB_ENV}" ]]; then
echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
fi

export MS_TAG
export MS_COMMIT
export RELEASE_VERSION
4 changes: 2 additions & 2 deletions install_gh.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash

set -ex

GH_ARCH="amd64"

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-`
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- )

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"

Expand Down
2 changes: 1 addition & 1 deletion install_remote_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
4 changes: 2 additions & 2 deletions patch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

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

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

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

git restore .vscode/settings.json

Expand Down
5 changes: 3 additions & 2 deletions prepare_assets.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC1091

set -e

Expand Down Expand Up @@ -29,7 +30,7 @@ if [[ "${OS_NAME}" == "osx" ]]; then
security create-keychain -p mysecretpassword "${KEYCHAIN}"
security set-keychain-settings -lut 21600 "${KEYCHAIN}"
security unlock-keychain -p mysecretpassword "${KEYCHAIN}"
security list-keychains -s `security list-keychains | xargs` "${KEYCHAIN}"
security list-keychains -s "$(security list-keychains | xargs)" "${KEYCHAIN}"
# security list-keychains -d user
# security show-keychain-info ${KEYCHAIN}

Expand Down
39 changes: 22 additions & 17 deletions prepare_vscode.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC1091,2154

set -e

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

for file in ../patches/*.patch; do
if [ -f "${file}" ]; then
if [[ -f "${file}" ]]; then
echo applying patch: "${file}";
git apply --ignore-whitespace "${file}"
if [ $? -ne 0 ]; then
if ! git apply --ignore-whitespace "${file}"; then
echo failed to apply patch "${file}" 1>&2
fi
fi
done

if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
for file in ../patches/insider/*.patch; do
if [ -f "${file}" ]; then
if [[ -f "${file}" ]]; then
echo applying patch: "${file}";
git apply --ignore-whitespace "${file}"
if [ $? -ne 0 ]; then
if ! git apply --ignore-whitespace "${file}"; then
echo failed to apply patch "${file}" 1>&2
fi
fi
done
fi

for file in ../patches/user/*.patch; do
if [ -f "${file}" ]; then
if [[ -f "${file}" ]]; then
echo applying user patch: "${file}";
git apply --ignore-whitespace "${file}"
if [ $? -ne 0 ]; then
if ! git apply --ignore-whitespace "${file}"; then
echo failed to apply patch "${file}" 1>&2
fi
fi
Expand Down Expand Up @@ -75,7 +73,8 @@ else
git checkout 102b347da0c92c29f9c67df22e864e70249cf086
npm install

export npm_config_node_gyp=`pwd`
npm_config_node_gyp=$( pwd )
export npm_config_node_gyp

cd ../..
fi
Expand All @@ -84,14 +83,18 @@ else
fi

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

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

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

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

cat product.json

# package.json
cp package.json package.json.bak

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

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

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

../undo_telemetry.sh

Expand Down
4 changes: 2 additions & 2 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

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

Expand Down
9 changes: 5 additions & 4 deletions undo_telemetry.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC1091,SC2016

set -ex

Expand All @@ -25,7 +26,7 @@ else
fi
export -f replace_with_debug

d1=`date +%s`
d1=$( date +%s )

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

d2=`date +%s`
d2=$( date +%s )

echo "undo_telemetry: $( echo $((${d2} - ${d1})) )s"
echo "undo_telemetry: $((d2 - d1))s"
7 changes: 4 additions & 3 deletions update_insider.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

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

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

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

CHANGES=$( git status --porcelain )

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

if ! git push origin insider --quiet; then
Expand Down
4 changes: 3 additions & 1 deletion update_settings.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck disable=SC1091,2148

DEFAULT_TRUE="'default': true"
DEFAULT_FALSE="'default': false"
DEFAULT_ON="'default': TelemetryConfiguration.ON"
Expand All @@ -21,7 +23,7 @@ update_setting () {
local SETTING="${1}"
local LINE_NUM=0
while read -r line; do
local LINE_NUM=$(( $LINE_NUM + 1 ))
local LINE_NUM=$(( LINE_NUM + 1 ))
if [[ "${line}" == *"${SETTING}"* ]]; then
local IN_SETTING=1
fi
Expand Down
Loading

0 comments on commit b4318d7

Please sign in to comment.