diff options
Diffstat (limited to 'pkgs/tools/admin/pulumi/update.sh')
-rwxr-xr-x | pkgs/tools/admin/pulumi/update.sh | 143 |
1 files changed, 87 insertions, 56 deletions
diff --git a/pkgs/tools/admin/pulumi/update.sh b/pkgs/tools/admin/pulumi/update.sh index 9a185646a7c85..c2b0818e5b9fe 100755 --- a/pkgs/tools/admin/pulumi/update.sh +++ b/pkgs/tools/admin/pulumi/update.sh @@ -1,86 +1,117 @@ -#!/usr/bin/env bash +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p gh +# shellcheck shell=bash # Bash 3 compatible for Darwin -# For getting the latest version of plugins automatically -API_URL="https://api.github.com/repos/pulumi" +if [ -z "${GITHUB_TOKEN}" ]; then + echo >&2 "usage: GITHUB_TOKEN=… ./update.sh" + exit 1 +fi # Version of Pulumi from # https://www.pulumi.com/docs/get-started/install/versions/ -VERSION="3.21.0" +VERSION="3.22.1" # An array of plugin names. The respective repository inside Pulumi's # Github organization is called pulumi-$name by convention. +declare -a pulumi_repos pulumi_repos=( - "auth0" - "aws" - "azure" - "cloudflare" - "consul" - "datadog" - "digitalocean" - "docker" - "equinix-metal" - "gcp" - "github" - "gitlab" - "hcloud" - "kubernetes" - "linode" - "mailgun" - "mysql" - "openstack" - "packet" - "postgresql" - "random" - "vault" - "vsphere" + "auth0" + "aws" + "azure" + "cloudflare" + "consul" + "datadog" + "digitalocean" + "docker" + "equinix-metal" + "gcp" + "github" + "gitlab" + "hcloud" + "kubernetes" + "linode" + "mailgun" + "mysql" + "openstack" + "packet" + "postgresql" + "random" + "vault" + "vsphere" ) # Contains latest release ${VERSION} from # https://github.com/pulumi/pulumi-${NAME}/releases -# Dynamically builds the plugin array, using the API for getting the +# Dynamically builds the plugin array, using the GitHub API for getting the # latest version. +plugin_num=1 plugins=() for key in "${pulumi_repos[@]}"; do - repo="pulumi-${key}" - plugins+=("${key}=$(curl -s ${API_URL}/${repo}/releases/latest | jq -M -r .tag_name | sed 's/v//g')") - sleep 1 + plugin="${key}=$(gh api "repos/pulumi/pulumi-${key}/releases/latest" --jq '.tag_name | sub("^v"; "")')" + printf "%20s: %s of %s\r" "${plugin}" "${plugin_num}" "${#pulumi_repos[@]}" + plugins+=("${plugin}") + sleep 1 + ((++plugin_num)) done +printf "\n" function genMainSrc() { - local url="https://get.pulumi.com/releases/sdk/pulumi-v${VERSION}-${1}-${2}.tar.gz" - local sha256 - sha256=$(nix-prefetch-url "$url") - echo " {" - echo " url = \"${url}\";" - echo " sha256 = \"$sha256\";" - echo " }" + local url="https://get.pulumi.com/releases/sdk/pulumi-v${VERSION}-${1}-${2}.tar.gz" + local sha256 + sha256=$(nix-prefetch-url "$url") + echo " {" + echo " url = \"${url}\";" + echo " sha256 = \"$sha256\";" + echo " }" +} + +function genSrc() { + local url="${1}" + local plug="${2}" + local tmpdir="${3}" + + local sha256 + sha256=$(nix-prefetch-url "$url") + + { + if [ -n "$sha256" ]; then # file exists + echo " {" + echo " url = \"${url}\";" + echo " sha256 = \"$sha256\";" + echo " }" + else + echo " # pulumi-resource-${plug} skipped (does not exist on remote)" + fi + } > "${tmpdir}/${plug}.nix" } function genSrcs() { - for plugVers in "${plugins[@]}"; do - local plug=${plugVers%=*} - local version=${plugVers#*=} - # url as defined here - # https://github.com/pulumi/pulumi/blob/06d4dde8898b2a0de2c3c7ff8e45f97495b89d82/pkg/workspace/plugins.go#L197 - local url="https://api.pulumi.com/releases/plugins/pulumi-resource-${plug}-v${version}-${1}-${2}.tar.gz" - local sha256 - sha256=$(nix-prefetch-url "$url") - if [ "$sha256" ]; then # file exists - echo " {" - echo " url = \"${url}\";" - echo " sha256 = \"$sha256\";" - echo " }" - else - echo " # pulumi-resource-${plug} skipped (does not exist on remote)" - fi - done + local tmpdir + tmpdir="$(mktemp -d)" + + local i=0 + + for plugVers in "${plugins[@]}"; do + local plug=${plugVers%=*} + local version=${plugVers#*=} + # url as defined here + # https://github.com/pulumi/pulumi/blob/06d4dde8898b2a0de2c3c7ff8e45f97495b89d82/pkg/workspace/plugins.go#L197 + local url="https://api.pulumi.com/releases/plugins/pulumi-resource-${plug}-v${version}-${1}-${2}.tar.gz" + genSrc "${url}" "${plug}" "${tmpdir}" & + ((++i)) + done + + wait + + find "${tmpdir}" -name '*.nix' -print0 | sort -z | xargs -r0 cat + rm -r "${tmpdir}" } { - cat <<EOF + cat << EOF # DO NOT EDIT! This file is generated automatically by update.sh { }: { |