Skip to content

Commit

Permalink
Merge pull request #189 from dxw/chore/add-scripts-to-rule-them-all
Browse files Browse the repository at this point in the history
Chore/add scripts to rule them all
  • Loading branch information
snim2 authored Nov 2, 2022
2 parents 49d4309 + 1a61709 commit c47589b
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 15 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
run:
runs-on: ubuntu-20.04
strategy:
matrix:
matrix:
php-versions: ['7.2', '7.3', '7.4']
fail-fast: false
name: PHP ${{ matrix.php-versions }}
Expand All @@ -29,17 +29,9 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-interaction
- name: git config (required for PluginsTest)
run: git config --global user.email you@example.com && git config --global user.name you

- name: PHPUnit tests
run: vendor/bin/phpunit

- name: Linting
run: vendor/bin/php-cs-fixer fix --dry-run -v --diff


- name: Run lints and tests
run: ./script/test
29 changes: 29 additions & 0 deletions .shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

trap "exit 1" USR1
PROC="$$"

fatal(){
echo "$@" >&2
kill -10 $PROC
}

# Exclude bin/ here because it contains PHP scripts. However, we check bin/
# in the block below just in case it has anything with a #!/bin/sh shebang.
# Although this isn't a perfect check, the likelihood of a shell script with
# the "wrong" shebang being placed in bin/ is very small.
grep -rl '\(^#!\/bin\/.\+sh\)\|\(^#!\/usr\/bin\)' . --exclude=vendor.phar --exclude-dir=bin --exclude-dir=vendor --exclude-dir=node_modules --exclude-dir=local --exclude-dir=.git | while IFS= read -r file
do
fatal "Error in ${file}: please only use #!/bin/sh shebang"
done

grep -rl '^#!\/bin\/sh' . --exclude-dir=vendor --exclude-dir=node_modules --exclude-dir=local --exclude-dir=.git | while IFS= read -r file
do
echo "Checking ${file}"
if ! shellcheck "$file"; then
fatal "Shellcheck error in ${file}"
exit 1
fi
done

echo OK
3 changes: 3 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
brew "php@7.4"
brew "composer"
brew "shellcheck"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Added setup and test scripts following the "scripts to rule them all pattern".

## [2.2.4] - 2022-06-29
### Changed
- Require 6.5.8 as minimum version of `guzzlehttp/guzzle` in `composer.json` as well as `composer.lock`
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ brew install dxw/tap/whippet

#### From source

To install Whippet from source, clone this directory and install its dependencies:
Whippet implements the [scripts to rule them all](https://github.com/github/scripts-to-rule-them-all)
pattern. To install Whippet from source, clone this repository:

```
```shell
$ git clone https://github.com/dxw/whippet.git
$ composer install
```

You might also want to symlink whippet to somewhere in your path:
Then run the relevant script to setup your environment and install dependencies:

```shell
./script/setup
```

You might also want to symlink whippet to somewhere in your path:

```shell
sudo ln -s $PWD/bin/whippet /usr/local/bin/whippet
```

Expand Down
22 changes: 22 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# script/bootstrap: Resolve all dependencies that the application requires to
# run.

set -e

cd "$(dirname "$0")/.."

if [ -z "$CI" ]; then
if [ -f Brewfile ] && [ "$(uname -s)" = "Darwin" ]; then
if ! brew bundle check >/dev/null 2>&1; then
echo "==> Installing Homebrew dependencies..."
brew bundle install --verbose
fi
fi
fi

if [ -f composer.json ]; then
echo "==> Installing PHP dependencies using Composer..."
composer install
fi
16 changes: 16 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# script/setup: Set up the application for the first time after cloning, or set
# it back to the initial unused state.

set -e

cd "$(dirname "$0")/.."

if [ -f Gemfile ] && [ -d vendor ]; then
echo "==> Cleaning installed PHP dependencies..."
git clean -x --force -- vendor
fi

echo "==> Bootstrapping..."
script/bootstrap
31 changes: 31 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# script/test: Run the test suite for the application. Optionally pass in a path
# to an individual test file to run a single test.

set -e

cd "$(dirname "$0")/.."

if [ -n "$DEBUG" ]; then
set -x
fi

echo "==> Updating..."
script/update

TEST_FILE=$1

if [ -n "$TEST_FILE" ]; then
echo "==> Running the tests matching '$TEST_FILE'..."
./vendor/bin/phpunit "$TEST_FILE"
else
echo "==> Running ShellCheck..."
./.shellcheck.sh

echo "==> Running php-cs-fixer..."
./vendor/bin/php-cs-fixer fix --dry-run -v --diff

echo "==> Running the tests..."
./vendor/bin/phpunit
fi
10 changes: 10 additions & 0 deletions script/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# script/update: Update the application to run for its current checkout.

set -e

cd "$(dirname "$0")/.."

echo "==> Bootstrapping..."
script/bootstrap

0 comments on commit c47589b

Please sign in to comment.