Skip to content

Commit 6bf8406

Browse files
committed
use "scripts to rule them all" pattern -> https://github.blog/engineering/scripts-to-rule-them-all/
1 parent 1342444 commit 6bf8406

File tree

10 files changed

+93
-16
lines changed

10 files changed

+93
-16
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,4 @@ jobs:
3030
bundler-cache: true
3131

3232
- name: build
33-
run: |
34-
GEM_NAME=$(ls | grep gemspec | cut -d. -f1)
35-
echo "Attempting to build gem $GEM_NAME..."
36-
gem build $GEM_NAME
37-
if [ $? -eq 0 ]; then
38-
echo "Gem built successfully!"
39-
else
40-
echo "Gem build failed!"
41-
exit 1
42-
fi
33+
run: script/build

.github/workflows/lint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ jobs:
2222
with:
2323
bundler-cache: true
2424

25+
- name: bootstrap
26+
run: script/bootstrap
27+
2528
- name: lint
26-
run: bundle exec rubocop -c .rubocop.yml lib/ test/
29+
run: script/lint

.github/workflows/release.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ jobs:
2424
with:
2525
bundler-cache: true
2626

27+
- name: bootstrap
28+
run: script/bootstrap
29+
2730
- name: lint
28-
run: bundle exec rubocop -c .rubocop.yml lib/ test/
31+
run: script/lint
2932

3033
- name: test
31-
run: bundle exec rake
34+
run: script/test
3235

3336
- name: set GEM_NAME from gemspec
3437
run: echo "GEM_NAME=$(ls | grep gemspec | cut -d. -f1)" >> $GITHUB_ENV
3538

36-
# builds the gem and saves the version to GITHUB_ENV
39+
# builds the gem and saves the version to GITHUB_ENV
3740
- name: build
3841
run: echo "GEM_VERSION=$(gem build ${{ env.GEM_NAME }}.gemspec 2>&1 | grep Version | cut -d':' -f 2 | tr -d " \t\n\r")" >> $GITHUB_ENV
3942

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ jobs:
2323
- name: Update .ruby-version with matrix value
2424
run: echo "${{ matrix.ruby_version }}" >| .ruby-version
2525

26-
- name: Set up Ruby
27-
uses: ruby/setup-ruby@32110d4e311bd8996b2a82bf2a43b714ccc91777 # [email protected]
26+
- uses: ruby/setup-ruby@32110d4e311bd8996b2a82bf2a43b714ccc91777 # [email protected]
2827
with:
2928
bundler-cache: true
3029

30+
- name: bootstrap
31+
run: script/bootstrap
32+
3133
- name: Run tests
3234
run: bundle exec rake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ spec/reports
1111
test/tmp
1212
test/version_tmp
1313
tmp
14+
bin/
1415

1516
# YARD artifacts
1617
.yardoc

script/bootstrap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/env bash
2+
3+
set -e # prevent any kind of script failures
4+
5+
source script/env "$@"
6+
7+
# bootstrap gem dependencies
8+
if [ "$BUNDLE_WITHOUT" == "" ]; then
9+
echo -e "${BLUE}Installing Gems for ${PURPLE}development${BLUE}...${OFF}"
10+
else
11+
echo -e "${BLUE}Installing Gems for ${GREEN}production${BLUE}...${OFF}"
12+
fi
13+
14+
# what gets installed is set via the BUNDLE_WITHOUT env var in the script/env file
15+
bundle install --local
16+
bundle binstubs --all

script/build

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
source script/env "$@"
6+
7+
GEM_NAME=$(ls | grep gemspec | cut -d. -f1)
8+
echo "Attempting to build gem $GEM_NAME..."
9+
gem build $GEM_NAME
10+
if [ $? -eq 0 ]; then
11+
echo "Gem built successfully!"
12+
else
13+
echo "Gem build failed!"
14+
exit 1
15+
fi

script/env

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /usr/bin/env bash
2+
3+
set -e # prevent any kind of script failures
4+
5+
# COLORS
6+
export OFF='\033[0m'
7+
export RED='\033[0;31m'
8+
export GREEN='\033[0;32m'
9+
export BLUE='\033[0;34m'
10+
export PURPLE='\033[0;35m'
11+
12+
# set RUBY_ENV to development (as a default) if not set
13+
: "${RUBY_ENV:=development}"
14+
15+
export RUBY_ENV
16+
17+
# set the working directory to the root of the project
18+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
19+
export DIR
20+
21+
# set the ruby version to the one specified in the .ruby-version file
22+
[ -z "$RBENV_VERSION" ] && RBENV_VERSION=$(cat "$DIR/.ruby-version")
23+
export RBENV_VERSION
24+
25+
# set the path to include the rbenv shims if they exist
26+
[ -d "/usr/share/rbenv/shims" ] && export PATH=/usr/share/rbenv/shims:$PATH
27+
28+
shopt -s nocasematch # enable case-insensitive matching
29+
if [[ "$RUBY_ENV" == "production" ]]; then
30+
export BUNDLE_WITHOUT="development"
31+
fi
32+
shopt -u nocasematch # disable case-insensitive matching

script/lint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
source script/env "$@"
6+
7+
bundle exec rake rubocop

script/test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
source script/env "$@"
6+
7+
bundle exec rake test

0 commit comments

Comments
 (0)