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 ba6ff45
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "Running pre-commit checks..."
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ See also:

We build the Pulumi website with Hugo, manage our dependencies with Node.js and Yarn, and write our documentation in Markdown. Below is a list of the tools you'll need if you'd like to work on the website (e.g., to contribute docs content, a blog post, etc.):

* [Hugo](https://gohugo.io) (>= 0.111.0)
* [Hugo](https://gohugo.io/installation/) (>= 0.111.0)
* Hugo 0.111.0 is highly recommended. This is the version we use in our deployment pipelines.
* [Node.js](https://nodejs.org/en/) (>= 18)
* [Yarn](https://classic.yarnpkg.com/en/) (1.x)
* [Node.js](https://nodejs.org/en/download/package-manager) (>= 18)
* [Yarn](https://classic.yarnpkg.com/lang/en/docs/install) (1.x)

Additionally, to build the SDK and CLI documentation, you'll also need:

Expand Down Expand Up @@ -125,7 +125,7 @@ pulumi gen-markdown ./content/docs/cli/commands # Generate Pulumi CLI documen
esc gen-docs ./content/docs/esc-cli/commands # Generate Pulumi ESC CLI documentation.
```

Generated docs reflect the functionality of the currently installed CLI, so make sure you've installed the latest public version of each one ([`pulumi`](https://github.com/pulumi/pulumi/releases), [`esc`](https://github.com/pulumi/esc/releases)) before running these commands and submitting your PR.
Generated docs reflect the functionality of the currently installed CLI, so make sure you've installed the latest public version of each one ([`pulumi`](https://github.com/pulumi/pulumi/releases), [`esc`](https://github.com/pulumi/esc/releases)) before running these commands and submitting your PR.

### Viewing rendered SDK and CLI docs locally

Expand Down
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"
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 ba6ff45

Please sign in to comment.