Skip to content

Commit

Permalink
Add pre-commit linting, version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
cnunciato committed May 20, 2024
1 parent 86bf071 commit 812a4f3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make lint
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ lint:

.PHONY: format
format:
yarn prettier --write .
./scripts/format.sh
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"license": "Apache-2.0",
"scripts": {
"minify-css": "node scripts/minify-css.js"
"minify-css": "node scripts/minify-css.js",
"prepare": "husky"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.427.0",
Expand Down Expand Up @@ -34,6 +35,7 @@
"typescript": "^4.9.5"
},
"devDependencies": {
"husky": "^9.0.11",
"prettier": "^2.6.2"
}
}
31 changes: 23 additions & 8 deletions scripts/ensure.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
#!/bin/bash

# Make sure the Node version matches what's in .nvmrc (and in our GitHub Actions workflows).
current_version="$(node -v)"
required_version="$(cat .nvmrc)"
set -o errexit -o pipefail

if [ ! $(echo ${current_version} | grep ${required_version}) ]; then
printf "\nIt looks like you're running Node %s, but this project uses Node %s.\n" ${current_version} ${required_version}
printf "If you're using nvm, try running nvm use.\n\n"
exit 1
fi
check_version() {
tool_name="$1"
executable="$2"
version_string="$(eval $3)"
required_version="$4"
details="See the README at https://github.com/pulumi/docs for a list of required tools and versions."

if ! command -v "$executable" &> /dev/null; then
echo "This project requires $1, but the '$2' executable doesn't seem to be installed and on your PATH."
echo $details
exit 1
fi

if [ ! $(echo ${version_string} | grep ${required_version}) ]; then
printf "It looks like you're running %s %s, but this project uses version %s.\n" ${tool_name} ${version_string} ${required_version}
echo $details
exit 1
fi
}
check_version "Node.js" "node" "node -v | sed 's/v\([0-9\.]*\).*$/\1/'" "18"
check_version "Hugo" "hugo" "hugo version | sed 's/hugo v\([0-9\.]*\).*$/\1/'" "0.111.0"
check_version "Yarn" "yarn" "yarn -v | sed 's/v\([0-9\.]*\).*$/\1/'" "1.22"

# Install the Node dependencies for the website and the infrastructure.
yarn install
Expand Down
5 changes: 5 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -o errexit -o pipefail

yarn prettier --write .
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2894,6 +2894,11 @@ humanize-duration@^3.9.1:
resolved "https://registry.yarnpkg.com/humanize-duration/-/humanize-duration-3.27.3.tgz#db654e72ebf5ccfe232c7f56bc58aa3a6fe4df88"
integrity sha512-iimHkHPfIAQ8zCDQLgn08pRqSVioyWvnGfaQ8gond2wf7Jq2jJ+24ykmnRyiz3fIldcn4oUuQXpjqKLhSVR7lw==

husky@^9.0.11:
version "9.0.11"
resolved "https://registry.yarnpkg.com/husky/-/husky-9.0.11.tgz#fc91df4c756050de41b3e478b2158b87c1e79af9"
integrity sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==

[email protected]:
version "0.6.3"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501"
Expand Down

0 comments on commit 812a4f3

Please sign in to comment.