@@ -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
2935fi
3036
@@ -39,13 +45,11 @@ REPO_DIR=$(mktemp -d)
3945cp -a . " ${REPO_DIR} "
4046cd " ${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
5054rm -f bin/bootstrap.sh
5155rm -rf .git
@@ -71,7 +75,38 @@ gh api --method PUT "/orgs/${ORG}/actions/secrets/DOCKERHUB_PASSWORD/repositorie
7175gh 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
77112gh api --method PUT " /repos/${REPO} /topics" -f " names[]=exercism-test-runner" -f " names[]=exercism-tooling"
0 commit comments