Last active
September 2, 2019 14:44
-
-
Save swsnr/3658ee94b9f373fbf223ea1014260169 to your computer and use it in GitHub Desktop.
withYarn SBT Pipeline Step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# The keyring we use to verify the signature of our download | |
keyring_file="$1" | |
# The version of yarn to install | |
version="$2" | |
# The directory install yarn versions to | |
basedir="$HOME/.yarn/versions/" | |
yarndir="$HOME/.yarn/versions/yarn-v$version" | |
# The URL to download yarn from | |
url="https://yarnpkg.com/downloads/$version/yarn-v$version.tar.gz" | |
# Check whether yarn is installed and working | |
actual_version="$("$yarndir/bin/yarn" --version 2>/dev/null || echo '')" | |
# Exit if that is the case; we don't need to install anything | |
[ "$actual_version" == "$version" ] && exit 0 | |
# Working directories for download and installation | |
downloaddir="$(mktemp -d -t "yarn-v$version.tar.gzXXXXXX")" | |
installdir="$(mktemp -d -t "yarn-v${version}XXXXXX")" | |
function cleanup() { | |
rm -rf "$downloaddir" | |
rm -rf "$installdir" | |
} | |
trap cleanup EXIT | |
# Remove potential remains of partial installation | |
rm -rf "$yarndir" | |
# Download tarball and signature | |
tarball="${downloaddir}/yarn-v${version}.tar.gz" | |
signature="${downloaddir}/yarn-v${version}.tar.gz.asc" | |
curl --fail -L -o "$tarball" "$url" | |
curl --fail -L -o "$signature" "$url.asc" | |
# Verify the signature | |
gpgv --keyring "$keyring_file" "$signature" "$tarball" | |
# Extract tarball | |
tar -xzf "$tarball" -C "$installdir" | |
# And move to proper install dir | |
mkdir -p "$basedir" | |
mv -T "$installdir/yarn-v$version" "$yarndir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/groovy | |
/** | |
* Use the given Yarn version in the contained block. | |
* | |
* @param version The version to use | |
* @param block The block to run | |
*/ | |
def call(String version, Closure block) { | |
def install = "${pwd tmp: true}/install.bash" | |
writeFile file: install, text: (libraryResource('com/acme/yarn/install.bash')) | |
def keyring = "${pwd tmp: true}/keyring.gpg" | |
// Use | |
// wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --no-default-keyring --keyring ./keyring.gpg --import | |
// to generate this keyring file used to verify the yarn download. | |
def keyringdata = libraryResource resource: 'com/acme/yarn/keyring.gpg', encoding: "Base64" | |
writeFile file: keyring, text: keyringdata, encoding: "Base64" | |
sh label: 'install-yarn', script: "bash \"${install}\" \"${keyring}\" \"${version}\"" | |
def path = sh label: 'yarn-path', returnStdout: true, | |
script: "echo -n \"\${HOME}/.yarn/versions/yarn-v${version}/bin/:\${PATH}\"" | |
withEnv(["PATH=${path}"], block) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like this in a Jenkins file: