Skip to content

Commit c0393da

Browse files
committed
modernize script/test and script/bootstrap and also update ci workflows to match
1 parent f4e46be commit c0393da

File tree

8 files changed

+155
-58
lines changed

8 files changed

+155
-58
lines changed

.github/workflows/acceptance.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
has_change: ${{ steps.diff.outputs.has_change}}
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121

2222
- id: fetch-base
2323
if: github.event_name == 'pull_request'
@@ -50,10 +50,10 @@ jobs:
5050
if: github.event_name == 'push'
5151
run: echo "::set-output name=has_change::true"
5252

53-
acceptance-suite:
53+
acceptance:
5454
needs: changes
5555
runs-on: ubuntu-latest-xl
56-
name: runner / acceptance-tests
56+
name: acceptance
5757
permissions:
5858
contents: read
5959

@@ -67,7 +67,7 @@ jobs:
6767
6868
- name: checkout
6969
if: ${{ needs.changes.outputs.has_change == 'true' }}
70-
uses: actions/checkout@v3
70+
uses: actions/checkout@v4
7171

7272
# Use Docker layer caching for 'docker build' and 'docker-compose build' commands.
7373
# https://github.com/satackey/action-docker-layer-caching/releases/tag/v0.0.11

.github/workflows/build.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ permissions:
1515
jobs:
1616
build:
1717
name: build
18-
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
os: [ubuntu-latest, macos-latest]
22+
runs-on: ${{ matrix.os }}
1923

2024
steps:
2125
- name: checkout
22-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2327

24-
- uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # pin@v1.152.0
28+
- uses: ruby/setup-ruby@5f19ec79cedfadb78ab837f95b87734d0003c899 # pin@v1.173.0
2529
with:
2630
bundler-cache: true
2731

.github/workflows/gem.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818

1919
steps:
2020
- name: checkout
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

23-
- uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # pin@v1.152.0
23+
- uses: ruby/setup-ruby@5f19ec79cedfadb78ab837f95b87734d0003c899 # pin@v1.173.0
2424
with:
2525
bundler-cache: true
2626

@@ -31,7 +31,7 @@ jobs:
3131
run: bundle exec rubocop -c .rubocop.yml lib/ spec/
3232

3333
- name: test
34-
run: script/test
34+
run: script/test -d -k
3535

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

.github/workflows/lint.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ on:
66
- main
77
pull_request:
88

9+
permissions:
10+
contents: read
11+
912
jobs:
10-
rubocop:
11-
name: runner / rubocop
13+
lint:
14+
name: lint
1215
runs-on: ubuntu-latest
13-
permissions:
14-
contents: read
1516

1617
steps:
1718
- name: checkout
18-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1920

20-
- uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # pin@v1.152.0
21+
- uses: ruby/setup-ruby@5f19ec79cedfadb78ab837f95b87734d0003c899 # pin@v1.173.0
2122
with:
2223
bundler-cache: true
2324

25+
- name: bootstrap
26+
run: script/bootstrap
27+
2428
- name: rubocop
2529
run: bundle exec rubocop -c .rubocop.yml lib/ spec/

.github/workflows/test.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,29 @@ on:
66
- main
77
pull_request:
88

9+
permissions:
10+
contents: read
11+
912
jobs:
10-
rubocop:
11-
name: runner / rspec
13+
test:
14+
name: test
1215
runs-on: ubuntu-latest
13-
permissions:
14-
contents: read
16+
17+
strategy:
18+
matrix:
19+
ruby: [ '3.1.2', '3.1.4', '3.2.2', '3.2.3', '3.3.0' ]
1520

1621
steps:
1722
- name: checkout
18-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
1924

20-
- uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # pin@v1.152.0
25+
- uses: ruby/setup-ruby@5f19ec79cedfadb78ab837f95b87734d0003c899 # pin@v1.173.0
2126
with:
2227
bundler-cache: true
28+
ruby-version: ${{ matrix.ruby }}
29+
30+
- name: bootstrap
31+
run: script/bootstrap
2332

2433
- name: rspec tests
25-
run: script/test -d
34+
run: script/test -d -k

script/bootstrap

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
1-
#!/bin/bash
1+
#! /usr/bin/env bash
22

3-
set -e
4-
set -x
3+
# COLORS
4+
OFF='\033[0m'
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
BLUE='\033[0;34m'
8+
PURPLE='\033[0;35m'
9+
10+
set -e # Prevent any kind of script failures
11+
12+
# if any of the following env vars are set, use them for the APP_ENV value
13+
if [ -n "$APP_ENV" ]; then
14+
export APP_ENV="$APP_ENV"
15+
elif [ -n "$ENV" ]; then
16+
export APP_ENV="$ENV"
17+
elif [ -n "$ENVIRONMENT" ]; then
18+
export APP_ENV="$ENVIRONMENT"
19+
elif [ -n "$RAILS_ENV" ]; then
20+
export APP_ENV="$RAILS_ENV"
21+
elif [ -n "$RACK_ENV" ]; then
22+
export APP_ENV="$RACK_ENV"
23+
fi
24+
25+
# set the working directory to the root of the project
526
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
6-
cd "$DIR"
727

8-
export PATH=/usr/share/rbenv/shims:$PATH
9-
export RBENV_VERSION="$(cat .ruby-version)"
10-
rm -rf "${DIR}/.bundle"
28+
# set the ruby version to the one specified in the .ruby-version file
29+
[ -z "$RBENV_VERSION" ] && export RBENV_VERSION=$(cat "$DIR/.ruby-version")
30+
31+
# set the app environment to development if it's not set
32+
[ -z "$APP_ENV" ] && export APP_ENV="development"
33+
34+
# set the path to include the rbenv shims if they exist
35+
[ -d "/usr/share/rbenv/shims" ] && export PATH=/usr/share/rbenv/shims:$PATH
1136

12-
# Using Deprecated Flags to avoid pulling from upstream
13-
bundle install --path vendor/gems --local --clean
37+
TRASHDIR=$(mktemp -d /tmp/bootstrap.XXXXXXXXXXXXXXXXX)
38+
cleanup() {
39+
rm -rf "$TRASHDIR"
40+
# Remove empty directory
41+
rmdir "$DIR/vendor/cache" 2>/dev/null || true
42+
}
43+
trap cleanup EXIT
1444

15-
bundle binstubs rake rspec-core rubocop
45+
# Bootstrap gem dependencies.
46+
if [ "$APP_ENV" == "production" ]; then
47+
echo -e "💎 ${BLUE}Installing Gems for ${GREEN}production${BLUE}...${OFF}"
48+
BUNDLE_WITHOUT=development bundle install --local
49+
BUNDLE_WITHOUT=development bundle binstubs --all
50+
else
51+
echo -e "💎 ${BLUE}Installing Gems for ${PURPLE}development${BLUE}...${OFF}"
52+
bundle install --local
53+
bundle binstubs --all
54+
fi

script/test

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
#!/bin/bash
1+
#! /usr/bin/env bash
22

33
# run script/test -h for help
44

5+
# COLORS
6+
OFF='\033[0m'
7+
RED='\033[0;31m'
8+
GREEN='\033[0;32m'
9+
BLUE='\033[0;34m'
10+
511
set -e
612

713
function usage()
814
{
915
echo -e "\t ================== script/test usage =================="
1016
echo -e "\t-h --help : displays help message"
17+
echo -e "\t-k --no-linter : disables linting tests"
1118
echo -e "\t-d --disable-bootstrap : disables bootstrap"
12-
echo -e "\n\t Suggested flags for development: script/test -d"
19+
echo -e "\n\t Suggested flags for development: script/test -d -s"
1320
}
1421

1522
while [ "$1" != "" ]; do
@@ -35,42 +42,64 @@ while [ "$1" != "" ]; do
3542
shift
3643
done
3744

38-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
39-
40-
export PATH=/usr/share/rbenv/shims:$PATH
41-
export RBENV_VERSION="$(cat "${DIR}/.ruby-version")"
42-
43-
TRASHDIR=$(mktemp -d /tmp/cibuild.XXXXXXXXXXXXXXXXXX)
44-
cleanup() {
45-
rm -rf "$TRASHDIR"
46-
}
47-
trap cleanup EXIT
48-
49-
cd "$DIR"
50-
. "${DIR}/script/lib/fold.sh"
45+
# setup
46+
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
47+
[ -z "$RBENV_VERSION" ] && export RBENV_VERSION=$(cat "$DIR/.ruby-version")
5148

5249
if [[ -z $no_bootstrap ]]; then
5350
# bootstrap
54-
begin_fold "Bootstrapping"
55-
./script/bootstrap
56-
end_fold
51+
echo -e "\n🥾 ${BLUE}Bootstrapping: $(date "+%H:%M:%S")${OFF}\n"
52+
echo "%%%FOLD {bootstrap}%%%"
53+
cd "$DIR"
54+
script/bootstrap
55+
echo "%%%END FOLD%%%"
5756
else
58-
echo -e "\nBypass Bootstrap"
57+
echo -e "\n⏩ ${BLUE}Skipping Bootstrap${OFF}"
5958
fi
6059

61-
bundle exec rspec spec/unit && rspec_exit=$? || rspec_exit=$?
60+
# Run Rubocop
61+
if [[ -z $no_linter ]]; then
62+
echo -e "\n🤖 ${BLUE}Running Rubocop: $(date "+%H:%M:%S")${OFF}\n"
63+
bundle exec bin/rubocop
64+
else
65+
echo -e "\n⏩ ${BLUE}Skipping Rubocop${OFF}"
66+
fi
67+
68+
# run tests
69+
echo -e "\n🧪 ${BLUE}Running tests: $(date "+%H:%M:%S")${OFF}\n"
70+
cd "$(dirname $0)/.."
6271

63-
cat "$DIR/coverage/coverage.txt"
64-
grep -q "You're all set, friend" "$DIR/coverage/coverage.txt" && cov_exit=0 || cov_exit=1
72+
bundle exec bin/rspec spec/unit && rspec_exit=$? || rspec_exit=$?
73+
74+
total_coverage=$(cat "$DIR/coverage/total-coverage.txt")
75+
76+
if grep -q "100.0" "$DIR/coverage/total-coverage.txt"; then
77+
cov_exit=0
78+
echo -e "\n✅ Total Coverage: ${GREEN}$total_coverage${OFF}"
79+
else
80+
cov_exit=1
81+
echo -e "\n❌ Total Coverage: ${RED}$total_coverage${OFF}"
82+
fi
6583

6684
echo ""
6785
echo "---------------------------------------"
68-
echo "Summary Results"
86+
echo "📊 Summary Results"
6987
echo "---------------------------------------"
7088
echo ""
71-
echo "rspec: exitcode=${rspec_exit}"
72-
echo "coverage: exitcode=${cov_exit}"
89+
90+
if [[ $rspec_exit == 0 ]]; then
91+
echo -e "${GREEN}rspec: exitcode=${rspec_exit}${OFF}"
92+
else
93+
echo -e "${RED}rspec: exitcode=${rspec_exit}${OFF}"
94+
fi
95+
96+
if [[ $cov_exit == 0 ]]; then
97+
echo -e "✅ \033[0;32mcoverage: exitcode=${cov_exit}\033[0m"
98+
else
99+
echo -e "❌ \033[0;31mcoverage: exitcode=${cov_exit}\033[0m"
100+
fi
73101

74102
[ $rspec_exit -gt 0 ] && exit 1
75103
[ $cov_exit -gt 0 ] && exit 1
104+
76105
exit 0

spec/unit/spec_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@
66
require "simplecov"
77
require "simplecov-erb"
88

9+
COV_DIR = File.expand_path("../../coverage", File.dirname(__FILE__))
10+
11+
SimpleCov.root File.expand_path("..", File.dirname(__FILE__))
12+
SimpleCov.coverage_dir COV_DIR
13+
914
SimpleCov.formatters = [
1015
SimpleCov::Formatter::HTMLFormatter,
1116
SimpleCov::Formatter::ERBFormatter
1217
]
18+
19+
SimpleCov.minimum_coverage 100
20+
21+
SimpleCov.at_exit do
22+
File.write("#{COV_DIR}/total-coverage.txt", SimpleCov.result.covered_percent)
23+
SimpleCov.result.format!
24+
end
1325
SimpleCov.start do
1426
# don't show specs as missing coverage for themselves
1527
add_filter "/spec/"

0 commit comments

Comments
 (0)