2020-02-19 01:06:35 +01:00
|
|
|
#!/usr/bin/env bash
|
2020-12-17 22:16:04 +01:00
|
|
|
set -euo pipefail
|
2020-02-19 01:06:35 +01:00
|
|
|
|
2020-04-30 13:52:54 +02:00
|
|
|
pushd() {
|
2021-03-15 23:36:31 +01:00
|
|
|
builtin pushd "$@" >/dev/null
|
2020-04-30 13:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
popd() {
|
2021-03-15 23:36:31 +01:00
|
|
|
builtin popd >/dev/null
|
2020-04-30 13:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_json_version() {
|
|
|
|
jq -r .version package.json
|
|
|
|
}
|
|
|
|
|
2020-05-11 23:08:22 +02:00
|
|
|
vscode_version() {
|
|
|
|
jq -r .version lib/vscode/package.json
|
|
|
|
}
|
|
|
|
|
2020-04-30 13:52:54 +02:00
|
|
|
os() {
|
|
|
|
local os
|
|
|
|
os=$(uname | tr '[:upper:]' '[:lower:]')
|
|
|
|
if [[ $os == "linux" ]]; then
|
|
|
|
# Alpine's ldd doesn't have a version flag but if you use an invalid flag
|
|
|
|
# (like --version) it outputs the version to stderr and exits with 1.
|
|
|
|
local ldd_output
|
|
|
|
ldd_output=$(ldd --version 2>&1 || true)
|
|
|
|
if echo "$ldd_output" | grep -iq musl; then
|
|
|
|
os="alpine"
|
|
|
|
fi
|
2020-05-14 11:47:11 +02:00
|
|
|
elif [[ $os == "darwin" ]]; then
|
|
|
|
os="macos"
|
2020-02-19 01:06:35 +01:00
|
|
|
fi
|
2020-04-30 13:52:54 +02:00
|
|
|
echo "$os"
|
|
|
|
}
|
|
|
|
|
|
|
|
arch() {
|
|
|
|
case "$(uname -m)" in
|
|
|
|
aarch64)
|
|
|
|
echo arm64
|
|
|
|
;;
|
2020-12-15 00:24:59 +01:00
|
|
|
x86_64 | amd64)
|
2020-04-30 13:52:54 +02:00
|
|
|
echo amd64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown architecture $(uname -a)"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2020-02-19 01:06:35 +01:00
|
|
|
}
|
2020-05-11 23:08:22 +02:00
|
|
|
|
|
|
|
curl() {
|
|
|
|
command curl -H "Authorization: token $GITHUB_TOKEN" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Grabs the most recent ci.yaml github workflow run that was successful and triggered from the same commit being pushd.
|
|
|
|
# This will contain the artifacts we want.
|
|
|
|
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
|
|
|
|
get_artifacts_url() {
|
2021-03-25 22:27:46 +01:00
|
|
|
local head_sha
|
|
|
|
local artifacts_url
|
|
|
|
head_sha=$(git rev-parse HEAD)
|
|
|
|
artifacts_url=$(curl -fsSL 'https://api.github.com/repos/cdr/code-server/actions/workflows/ci.yaml/runs?status=success&event=pull_request' | jq -r ".workflow_runs[] | select(.head_sha == \"$head_sha\") | .artifacts_url" | head -n 1)
|
|
|
|
if [[ -z "$artifacts_url" ]]; then
|
|
|
|
echo >&2 "ERROR: artifacts_url came back empty"
|
|
|
|
echo >&2 "Check the get_artifacts_url function"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$artifacts_url"
|
2020-05-11 23:08:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Grabs the artifact's download url.
|
|
|
|
# https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
|
|
|
|
get_artifact_url() {
|
|
|
|
local artifact_name="$1"
|
2020-05-20 10:50:16 +02:00
|
|
|
curl -fsSL "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
|
2020-05-11 23:08:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Uses the above two functions to download a artifact into a directory.
|
|
|
|
download_artifact() {
|
|
|
|
local artifact_name="$1"
|
|
|
|
local dst="$2"
|
|
|
|
|
|
|
|
local tmp_file
|
|
|
|
tmp_file="$(mktemp)"
|
|
|
|
|
2021-03-15 23:36:31 +01:00
|
|
|
curl -fsSL "$(get_artifact_url "$artifact_name")" >"$tmp_file"
|
2020-05-16 16:55:46 +02:00
|
|
|
unzip -q -o "$tmp_file" -d "$dst"
|
2020-05-11 23:08:22 +02:00
|
|
|
rm "$tmp_file"
|
|
|
|
}
|
2020-05-16 16:55:46 +02:00
|
|
|
|
|
|
|
rsync() {
|
|
|
|
command rsync -a --del "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
VERSION="$(pkg_json_version)"
|
|
|
|
export VERSION
|
|
|
|
ARCH="$(arch)"
|
|
|
|
export ARCH
|
|
|
|
OS=$(os)
|
|
|
|
export OS
|
|
|
|
|
|
|
|
# RELEASE_PATH is the destination directory for the release from the root.
|
|
|
|
# Defaults to release
|
|
|
|
RELEASE_PATH="${RELEASE_PATH-release}"
|
2020-12-17 22:16:04 +01:00
|
|
|
|
2020-12-18 17:59:15 +01:00
|
|
|
# VS Code bundles some modules into an asar which is an archive format that
|
|
|
|
# works like tar. It then seems to get unpacked into node_modules.asar.
|
|
|
|
#
|
|
|
|
# I don't know why they do this but all the dependencies they bundle already
|
|
|
|
# exist in node_modules so just symlink it. We have to do this since not only VS
|
|
|
|
# Code itself but also extensions will look specifically in this directory for
|
|
|
|
# files (like the ripgrep binary or the oniguruma wasm).
|
2020-12-17 22:16:04 +01:00
|
|
|
symlink_asar() {
|
2021-01-05 22:28:42 +01:00
|
|
|
if [ ! -L node_modules.asar ]; then
|
2020-12-17 22:16:04 +01:00
|
|
|
if [ "${WINDIR-}" ]; then
|
|
|
|
# mklink takes the link name first.
|
|
|
|
mklink /J node_modules.asar node_modules
|
|
|
|
else
|
|
|
|
# ln takes the link name second.
|
|
|
|
ln -s node_modules node_modules.asar
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|