-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rationalise DCR's env checking scripts #9400
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a9e7bdb
move `log` script to the repo root
sndrs ef59071
move `check-node-versions` to DCR project
sndrs b431233
move `check-deps` and `check-files` to `lint-project`
sndrs ebf6b6d
run `check-env` when running `lint-project`
sndrs 6c16801
convert `check-node` to bash and move to repo root
sndrs 7bae50a
move `check-yarn` to repo root
sndrs dd355bd
make sure `log` emits legible messages outside terminals
sndrs 6456f8d
use `colourise` in `check-yarn`
sndrs 4282e6a
add links to ansi colour codes
sndrs b108b2e
Merge branch 'main' into sndrs/repo-scripts
sndrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Check whether the current node version matches the .nvmrc version, and offer some help if not. | ||
|
||
in_terminal() { test -t 1; } | ||
|
||
strip_colors() { | ||
local text="$1" | ||
echo "$text" | sed -e $'s/\x1b\[[0-9;]*m//g' | ||
} | ||
|
||
log_with_color() { | ||
local text="$1" | ||
|
||
# Check if output is a terminal and supports color | ||
if in_terminal && [[ $(tput colors) -ge 8 ]]; then | ||
# Terminal supports color, print the text as it is | ||
echo -e "$text" | ||
else | ||
# Terminal does not support color, strip color codes and print | ||
echo "$(strip_colors "$text")" | ||
fi | ||
} | ||
|
||
blue='\033[0;34m' | ||
red='\033[0;31m' | ||
dim='\033[2m' | ||
bold='\033[1m' | ||
reset='\033[0m' | ||
|
||
# get the node version from .nvmrc | ||
nvmrc_contents=$(cat .nvmrc) | ||
|
||
# check that it's a valid version (matches x.y.z) | ||
nvmrc_version_pattern="^[0-9]+\.[0-9]+\.[0-9]+$" | ||
if [[ $nvmrc_contents =~ $nvmrc_version_pattern ]]; then | ||
nvmrc_version=${BASH_REMATCH[0]} | ||
else | ||
log_with_color "${red}The Node version in .nvmrc is invalid${reset}" | ||
log_with_color "${dim}It should match the pattern 'x.y.z'.${reset}" | ||
# exit with failure | ||
exit 1 | ||
fi | ||
|
||
# Now we can check if the current version of Node matches the .nvmrc version | ||
|
||
# is _any_ node available? | ||
if [[ -x "$(command -v node)" ]]; then | ||
node_version=$(node -v) | ||
node_version=${node_version:1} # remove the "v" in "v1.2.3" | ||
fi | ||
|
||
# check the version we're using | ||
# note that `node_version` will be empty if node wan't available above | ||
if [ "$node_version" == "$nvmrc_version" ]; then | ||
# we're using the correct version of node | ||
log_with_color "${dim}Using Node ${blue}$node_version${reset}" | ||
|
||
# we're done, exit with success | ||
exit 0 | ||
fi | ||
|
||
# If we got here, we're using the wrong version of node, or There Is No Node. | ||
# Try to help people load the correct version: | ||
if in_terminal; then | ||
log_with_color "${red}This project requires Node v$nvmrc_version${reset}" | ||
if [[ -x "$(command -v fnm)" ]]; then | ||
log_with_color "${dim}Run ${blue}fnm use${reset}${dim} to switch to the correct version.${reset}" | ||
log_with_color "${dim}See ${blue}${dim}https://github.com/Schniz/fnm#shell-setup${reset}${dim} to automate this.${reset}" | ||
elif [[ -x "$(command -v asdf)" ]]; then | ||
log_with_color "${dim}Run ${blue}asdf install${reset}${dim} to switch to the correct version.${reset}" | ||
elif [[ -x "$(which nvm)" ]]; then | ||
log_with_color "${dim}Run ${blue}nvm install${reset}${dim} to switch to the correct version.${reset}" | ||
else | ||
log_with_color "${dim}Consider using ${bold}fnm${reset}${dim} to manage Node versions:${reset} ${blue}https://github.com/Schniz/fnm#installation${reset}${dim}.${reset}" | ||
fi | ||
else | ||
# not in a terminal, so v possible we're running a husky script in a git gui | ||
echo "Could not find Node v$nvmrc_version." | ||
echo "You may need to load your Node version manager in a ~/.huskyrc file." | ||
echo "See https://typicode.github.io/husky/troubleshooting.html#command-not-found." | ||
fi | ||
|
||
# exit with failure | ||
exit 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Check that yarn is available. If not, ask the user to run `corepack enable` | ||
* which will provide it. | ||
* | ||
* Note that any yarn@>1 will do, since it will defer to | ||
* the copy in that lives in .yarn/releases (which is the version we want to | ||
* use). | ||
*/ | ||
|
||
// no external deps can be used here, because this runs before deps are installed | ||
const { execSync } = require('child_process'); | ||
const { stdout } = require('process'); | ||
const { colourise, log, warn } = require('../log'); | ||
|
||
// we can't use chalk, because this runs before deps are installed | ||
// https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 | ||
const reset = '\x1b[0m'; | ||
const blue = '\x1b[34m'; | ||
|
||
try { | ||
const yarnVersion = execSync('yarn -v', { encoding: 'utf-8' }); | ||
log(`Using yarn ${colourise(reset, colourise(blue, yarnVersion.trim()))}`); | ||
} catch (e) { | ||
warn(`Could not find yarn. Please run 'corepack enable'.`); | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure this should live inside
dotcom-rendering
as it’s looking for files in both workspaces and in the root.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a DCR concern though right? it's looking in the root for the root version, and making sure that DCR-related files (which AR files are, really, i think?) are in sync with the repo more generally.
should it be the responsibility of the root to ensure that apps in the workspace stay in sync with the root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind the root is a good place for scripts that span all workspaces, but I agree that it should be a workspace concern to stay in sync with the root.
I’ll defer to anyone in @guardian/dotcom-platform with a stronger or better articulated view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged, but if anyone prefers to move it, please do