From 05f3514f2fc3bc8a4ff4ed48c3f82d2b98e3ae1d Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 27 Nov 2020 17:30:03 +0100 Subject: [PATCH] fetch-configlet_v3: Support repo rename This commit means that a local copy of this script will keep working even after this repo is renamed from `configlet-v3` to `configlet`. Changes: - Add the `--location` flag to the curl command so that we follow redirects during the API request. - No longer hard-code the filename of the asset. Decisions: - Don't use `jq` to parse the JSON. We shouldn't assume that the end-user has it installed. Let's use it only in the `exercism/github-actions` version of this script. - Use `grep`, rather than `sed`, `awk` or pure bash. We try to maximise readability for the average maintainer. - Try to maximise portability. For example, we avoid using grep's `-P, --perl-regexp` flag, which isn't available in e.g. OpenBSD's grep (see https://man.openbsd.org/grep). --- scripts/fetch-configlet_v3 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/fetch-configlet_v3 b/scripts/fetch-configlet_v3 index 13705a36..eae103fb 100755 --- a/scripts/fetch-configlet_v3 +++ b/scripts/fetch-configlet_v3 @@ -32,12 +32,12 @@ else HEADER="authorization: Bearer ${GITHUB_TOKEN}" fi -FILENAME="configlet_v3-${OS}-${ARCH}.${EXT}" +SUFFIX="${OS}-${ARCH}.${EXT}" get_url () { - curl --header "$HEADER" -s "$LATEST" | - awk -v filename=$FILENAME '$1 ~ /browser_download_url/ && $2 ~ filename { print $2 }' | - tr -d '"' + curl --header "$HEADER" -s --location "$LATEST" | + grep "\"browser_download_url\": \".*/download/.*/configlet.*${SUFFIX}\"$" | + cut -d'"' -f4 } URL=$(get_url)