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-06-28 18:36:55 +02:00
|
|
|
builtin pushd "$@" > /dev/null
|
2020-04-30 13:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
popd() {
|
2021-06-28 18:36:55 +02: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() {
|
2022-03-15 03:37:29 +01:00
|
|
|
jq -r .version lib/vscode/package.json
|
2020-05-11 23:08:22 +02:00
|
|
|
}
|
|
|
|
|
2020-04-30 13:52:54 +02:00
|
|
|
os() {
|
2022-08-04 18:03:28 +02:00
|
|
|
osname=$(uname | tr '[:upper:]' '[:lower:]')
|
|
|
|
case $osname in
|
|
|
|
linux)
|
|
|
|
# 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.
|
|
|
|
# TODO: Better to check /etc/os-release; see ../install.sh.
|
|
|
|
ldd_output=$(ldd --version 2>&1 || true)
|
|
|
|
if echo "$ldd_output" | grep -iq musl; then
|
|
|
|
osname="alpine"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
darwin) osname="macos" ;;
|
|
|
|
cygwin* | mingw*) osname="windows" ;;
|
|
|
|
esac
|
|
|
|
echo "$osname"
|
2020-04-30 13:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
arch() {
|
2021-06-17 19:28:54 +02:00
|
|
|
cpu="$(uname -m)"
|
|
|
|
case "$cpu" in
|
2022-08-04 18:03:28 +02:00
|
|
|
aarch64) cpu=arm64 ;;
|
|
|
|
x86_64) cpu=amd64 ;;
|
2020-04-30 13:52:54 +02:00
|
|
|
esac
|
2022-08-04 18:03:28 +02:00
|
|
|
echo "$cpu"
|
2020-02-19 01:06:35 +01:00
|
|
|
}
|
2020-05-11 23:08:22 +02:00
|
|
|
|
2021-05-17 21:59:41 +02:00
|
|
|
# Grabs the most recent ci.yaml github workflow run that was triggered from the
|
|
|
|
# pull request of the release branch for this version (regardless of whether
|
|
|
|
# that run succeeded or failed). The release branch name must be in semver
|
|
|
|
# format with a v prepended.
|
2020-05-11 23:08:22 +02:00
|
|
|
# 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 artifacts_url
|
2022-07-20 01:25:53 +02:00
|
|
|
local version_branch="release/v$VERSION"
|
2021-07-30 20:32:22 +02:00
|
|
|
local workflow_runs_url="repos/:owner/:repo/actions/workflows/ci.yaml/runs?event=pull_request&branch=$version_branch"
|
2021-04-19 22:51:33 +02:00
|
|
|
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1)
|
2021-03-25 22:27:46 +01:00
|
|
|
if [[ -z "$artifacts_url" ]]; then
|
|
|
|
echo >&2 "ERROR: artifacts_url came back empty"
|
2021-07-17 00:37:26 +02:00
|
|
|
echo >&2 "We looked for a successful run triggered by a pull_request with for code-server version: $VERSION and a branch named $version_branch"
|
2021-04-19 22:51:33 +02:00
|
|
|
echo >&2 "URL used for gh API call: $workflow_runs_url"
|
2021-03-25 22:27:46 +01:00
|
|
|
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"
|
2021-04-19 22:51:33 +02:00
|
|
|
gh api "$(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-06-28 18:36:55 +02:00
|
|
|
gh api "$(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}"
|