Skip to content

Commit

Permalink
fetch-configlet_v3: Support repo rename
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ee7 committed Dec 15, 2020
1 parent 6747588 commit 05f3514
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scripts/fetch-configlet_v3
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 05f3514

Please sign in to comment.