pulumi/scripts/get-language-providers.sh

86 lines
2.4 KiB
Bash
Raw Normal View History

2022-09-02 05:40:13 +00:00
#!/usr/bin/env bash
2022-05-03 17:58:27 +00:00
set -eo pipefail
set -x
LOCAL="${1:-"false"}"
get_version() {
2022-09-02 05:40:13 +00:00
local repo="$1"
(
cd pkg
GOWORK=off go list -m all | grep "${repo}" | cut -d" " -f2
)
}
2022-09-02 05:40:13 +00:00
# Use github credentials for a higher rate limit when possible.
USE_GH=false
if command -v gh >/dev/null && gh auth status >/dev/null 2>&1; then
USE_GH=true
fi
download_release() {
local lang="$1"
local tag="$2"
local filename="$3"
if "${USE_GH}"; then
gh release download "${tag}" --repo "pulumi/pulumi-${lang}" -p "${filename}"
else
curl -OL --fail "https://github.com/pulumi/pulumi-${lang}/releases/download/${tag}/${filename}"
fi
}
2022-05-03 17:58:27 +00:00
# shellcheck disable=SC2043
for i in "github.com/pulumi/pulumi-java java" "github.com/pulumi/pulumi-yaml yaml" "github.com/pulumi/pulumi-dotnet dotnet v3.64.0"; do
2022-05-03 17:58:27 +00:00
set -- $i # treat strings in loop as args
REPO="$1"
PULUMI_LANG="$2"
2022-12-13 10:51:55 +00:00
TAG="$3" # only dotnet sets this because we don't currently have a go dependency on dotnet (and quite possibly never will)
if [ -z "$TAG" ]; then
TAG=$(get_version "${REPO}")
fi
2022-05-03 17:58:27 +00:00
2022-09-02 05:40:13 +00:00
LANG_DIST="$(pwd)/bin"
mkdir -p "${LANG_DIST}"
(
# Run in a subshell to ensure we don't alter current working directory.
2022-09-02 05:40:13 +00:00
cd "$(mktemp -d)"
# Currently avoiding a dependency on GH CLI in favor of curl, so
# that this script works in the context of the Brew formula:
#
# https://github.com/Homebrew/homebrew-core/blob/master/Formula/pulumi.rb
#
# Formerly:
#
# gh release download "${TAG}" --repo "pulumi/pulumi-${PULUMI_LANG}"
2022-05-03 17:58:27 +00:00
2022-09-02 05:40:13 +00:00
for j in "darwin" "linux" "windows .exe"; do
set -- $j # treat strings in loop as args
DIST_OS="$1"
DIST_EXT="${2:-""}"
for k in "amd64 x64" "arm64 arm64"; do
set -- $k # treat strings in loop as args
DIST_ARCH="$1"
RENAMED_ARCH="$2" # goreleaser in pulumi/pulumi renames amd64 to x64
# if TARGET is set and DIST_OS-DIST_ARCH does not match, skip
if [ "${LOCAL}" = "local" ] && [ "$(go env GOOS)-$(go env GOARCH)" != "${DIST_OS}-${DIST_ARCH}" ]; then
continue
fi
ARCHIVE="pulumi-language-${PULUMI_LANG}-${TAG}-${DIST_OS}-${DIST_ARCH}"
2022-09-02 05:40:13 +00:00
OUTDIR="${LANG_DIST}/$DIST_OS-$RENAMED_ARCH"
2022-09-02 05:40:13 +00:00
mkdir -p "${OUTDIR}"
2022-12-15 16:26:41 +00:00
download_release "${PULUMI_LANG}" "${TAG}" "${ARCHIVE}.tar.gz"
tar -xzvf "${ARCHIVE}.tar.gz" -C "${OUTDIR}" "pulumi-language-${PULUMI_LANG}${DIST_EXT}"
done
2022-05-03 17:58:27 +00:00
done
)
2022-05-03 17:58:27 +00:00
done