Skip to content

Commit 0dce056

Browse files
authored
Tidy some of the bash scripts; require modern bash (>=4.4) (#183)
* Use perl to edit files. * Require bash 4.4 or newer. * Use modern bash features.
1 parent d102a29 commit 0dce056

3 files changed

Lines changed: 46 additions & 11 deletions

File tree

bin/benchmark-in-docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ required_tool docker
2626
required_tool hyperfine
2727

2828
# Pre-build the Docker image
29-
if [ -z "${SKIP_DOCKER_BUILD}" ]; then
29+
if [[ -z "${SKIP_DOCKER_BUILD}" ]]; then
3030
docker build --rm -t exercism/replace-this-with-the-track-slug-test-runner .
3131
else
3232
echo "Skipping docker build because SKIP_DOCKER_BUILD is set."
3333
fi
3434

3535
hyperfine \
36-
--parameter-list slug $(find tests -maxdepth 1 -mindepth 1 -type d -printf $'%f\n' | paste -sd ",") \
36+
--parameter-list slug "$(find tests -maxdepth 1 -mindepth 1 -type d -printf $'%f\n' | paste -sd ",")" \
3737
--prepare 'git clean -xdfq tests/{slug}' \
3838
'SKIP_DOCKER_BUILD=true bin/run-in-docker.sh {slug} tests/{slug} tests/{slug}'

bin/benchmark.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ required_tool() {
2222
required_tool hyperfine
2323

2424
hyperfine \
25-
--parameter-list slug $(find tests -maxdepth 1 -mindepth 1 -type d -printf $'%f\n' | paste -sd ",") \
25+
--parameter-list slug "$(find tests -maxdepth 1 -mindepth 1 -type d -printf $'%f\n' | paste -sd ",")" \
2626
--prepare 'git clean -xdfq tests/{slug}' \
2727
'bin/run.sh {slug} tests/{slug} tests/{slug}'

bin/bootstrap.sh

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ required_tool() {
2323
die "$1 is required but not installed. Please install it and make sure it's in your PATH."
2424
}
2525

26+
if (( "${BASH_VERSINFO[0]}${BASH_VERSINFO[1]}" < 44 )); then
27+
echo "This script requires bash version 4.4 at minimum." >&2
28+
echo "You can install a modern bash from Homebrew: brew install bash" >&2
29+
exit 1
30+
fi
31+
2632
# If any required arguments is missing, print the usage and exit
27-
if [ -z "${LANGUAGE}" ] || [ -z "${SLUG}" ]; then
33+
if [[ -z "${LANGUAGE}" || -z "${SLUG}" ]]; then
2834
help_and_exit
2935
fi
3036

@@ -39,13 +45,11 @@ REPO_DIR=$(mktemp -d)
3945
cp -a . "${REPO_DIR}"
4046
cd "${REPO_DIR}" || die "Failed to cd to ${REPO_DIR}"
4147

42-
for file in $(git grep --files-with-matches replace-this-with-the-track-slug); do
43-
sed -i "s/replace-this-with-the-track-slug/${SLUG}/g" "${file}"
44-
done
48+
mapfile -t files < <(git grep --files-with-matches replace-this-with-the-track-slug)
49+
perl -pi -e "s/replace-this-with-the-track-slug/${SLUG}/g" "${files[@]}"
4550

46-
for file in $(git grep --files-with-matches replace-this-with-the-track-name); do
47-
sed -i "s/replace-this-with-the-track-name/${LANGUAGE}/g" "${file}"
48-
done
51+
mapfile -t files < <(git grep --files-with-matches replace-this-with-the-track-name)
52+
perl -pi -e "s/replace-this-with-the-track-name/${LANGUAGE}/g" "${files[@]}"
4953

5054
rm -f bin/bootstrap.sh
5155
rm -rf .git
@@ -71,7 +75,38 @@ gh api --method PUT "/orgs/${ORG}/actions/secrets/DOCKERHUB_PASSWORD/repositorie
7175
gh api --method PUT "/orgs/${ORG}/actions/secrets/DOCKERHUB_USERNAME/repositories/${REPO_ID}"
7276

7377
# Create ruleset for default branch
74-
jq -n '{name: "Default branch", target: "branch", enforcement: "active", conditions: {ref_name: {include: ["~DEFAULT_BRANCH"], exclude:[]}}, rules:[{type: "pull_request", parameters: {dismiss_stale_reviews_on_push: false, require_code_owner_review: true,require_last_push_approval: false, required_approving_review_count: 0, required_review_thread_resolution: false}}], "bypass_actors":[{"actor_id": 1, "actor_type": "OrganizationAdmin", "bypass_mode": "always"}]}' | gh api --method POST "/repos/${REPO}/rulesets" --input -
78+
ruleset=$(jq -cn '
79+
{
80+
name: "Default branch",
81+
target: "branch",
82+
enforcement: "active",
83+
conditions: {
84+
ref_name: {
85+
include: ["~DEFAULT_BRANCH"],
86+
exclude:[]
87+
}
88+
},
89+
rules: [
90+
{
91+
type: "pull_request",
92+
parameters: {
93+
dismiss_stale_reviews_on_push: false,
94+
require_code_owner_review: true,
95+
require_last_push_approval: false,
96+
required_approving_review_count: 0,
97+
required_review_thread_resolution: false
98+
}
99+
}
100+
],
101+
"bypass_actors": [
102+
{
103+
"actor_id": 1,
104+
"actor_type": "OrganizationAdmin",
105+
"bypass_mode": "always"
106+
}
107+
]
108+
}')
109+
gh api --method POST "/repos/${REPO}/rulesets" --input - <<< "$ruleset"
75110

76111
# Add topics
77112
gh api --method PUT "/repos/${REPO}/topics" -f "names[]=exercism-test-runner" -f "names[]=exercism-tooling"

0 commit comments

Comments
 (0)