diff options
Diffstat (limited to 'nixpkgs/pkgs/tools/admin/pulumi/update.sh')
-rwxr-xr-x | nixpkgs/pkgs/tools/admin/pulumi/update.sh | 151 |
1 files changed, 91 insertions, 60 deletions
diff --git a/nixpkgs/pkgs/tools/admin/pulumi/update.sh b/nixpkgs/pkgs/tools/admin/pulumi/update.sh index 051cf4c90b00..c2b0818e5b9f 100755 --- a/nixpkgs/pkgs/tools/admin/pulumi/update.sh +++ b/nixpkgs/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.19.0" +VERSION="3.22.1" -# A hashmap containing a plugin's name and it's respective repository inside -# Pulumi's Github organization +# An array of plugin names. The respective repository inside Pulumi's +# Github organization is called pulumi-$name by convention. -declare -A pulumi_repos +declare -a pulumi_repos pulumi_repos=( - ["auth0"]="pulumi-auth0" - ["aws"]="pulumi-aws" - ["azure"]="pulumi-azure" - ["cloudflare"]="pulumi-cloudflare" - ["consul"]="pulumi-consul" - ["datadog"]="pulumi-datadog" - ["digitalocean"]="pulumi-digitalocean" - ["docker"]="pulumi-docker" - ["equinix-metal"]="pulumi-equinix-metal" - ["gcp"]="pulumi-gcp" - ["github"]="pulumi-github" - ["gitlab"]="pulumi-gitlab" - ["hcloud"]="pulumi-hcloud" - ["kubernetes"]="pulumi-kubernetes" - ["linode"]="pulumi-linode" - ["mailgun"]="pulumi-mailgun" - ["mysql"]="pulumi-mysql" - ["openstack"]="pulumi-openstack" - ["packet"]="pulumi-packet" - ["postgresql"]="pulumi-postgresql" - ["random"]="pulumi-random" - ["vault"]="pulumi-vault" - ["vsphere"]="pulumi-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 hashmap's key/values and the -# API for getting the latest version. +# Dynamically builds the plugin array, using the GitHub API for getting the +# latest version. +plugin_num=1 plugins=() -for key in "${!pulumi_repos[@]}"; do - plugins+=("${key}=$(curl -s ${API_URL}/${pulumi_repos[${key}]}/releases/latest | jq -M -r .tag_name | sed 's/v//g')") - sleep 1 +for key in "${pulumi_repos[@]}"; do + 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 { }: { |