Skip to content

Commit b762426

Browse files
committed
Move prettier check to bin file and extract when not present
1 parent eec1e67 commit b762426

5 files changed

Lines changed: 49 additions & 49 deletions

File tree

.github/workflows/action-format.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ jobs:
6262
6363
- name: 'Format code'
6464
run: ./bin/format.sh
65-
env:
66-
EXERCISM_PRETTIER_VERSION: '2.3.2'
6765

6866
- name: 'Commit formatted code'
6967
run: |

.github/workflows/verify-code-formatting.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ jobs:
1414

1515
- name: 'Verify formatting of all files'
1616
run: ./bin/check-formatting.sh
17-
env:
18-
EXERCISM_PRETTIER_VERSION: '2.3.2'

bin/check-formatting.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
#!/bin/bash
22

3+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4+
echo "Pulling prettier version from package.json"
5+
EXERCISM_PRETTIER_VERSION=$(npm list prettier | grep -Po '.*\sprettier@\K.*')
6+
fi
7+
8+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
9+
echo "---------------------------------------------------"
10+
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
11+
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
12+
echo "---------------------------------------------------"
13+
echo "This is what npm list reports:"
14+
echo "$(npm list prettier)"
15+
echo ""
16+
echo "This is the version that can be extracted:"
17+
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
18+
echo ""
19+
echo "These files are found in the repo root:"
20+
echo "$(ls -p | grep -v /)"
21+
echo "---------------------------------------------------"
22+
exit 1
23+
else
24+
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
25+
fi
26+
327
npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/format.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
#!/usr/bin/env bash
22

33
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4-
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
5-
echo "Please see https://github.com/exercism/v3/blob/master/docs/maintainers/style-guide.md for guidance."
6-
exit 1
4+
echo "Pulling prettier version from package.json"
5+
EXERCISM_PRETTIER_VERSION=$(npm list prettier | grep -Po '.*\sprettier@\K.*')
6+
fi
7+
8+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
9+
echo "---------------------------------------------------"
10+
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
11+
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
12+
echo "---------------------------------------------------"
13+
echo "This is what npm list reports:"
14+
echo "$(npm list prettier)"
15+
echo ""
16+
echo "This is the version that can be extracted:"
17+
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
18+
echo ""
19+
echo "These files are found in the repo root:"
20+
echo "$(ls -p | grep -v /)"
21+
echo "---------------------------------------------------"
22+
exit 1
23+
else
24+
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
725
fi
826

927
npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

scripts/pr-check

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
* 1. Find the exercises at all the paths provided
1010
* 2. Check stub existence for those exercises
1111
* 3. Check integrity of configuration for those exercises
12-
* 4. Check prettier package.json version and ENV matches
13-
* 5. Run eslint for those exercises to check code-style
12+
* 4. Run eslint for those exercises to check code-style
1413
*/
1514

1615
const {
@@ -23,7 +22,6 @@ const {
2322
assignments,
2423
} = require('./helpers');
2524

26-
const fn = require('fn');
2725
const shell = require('shelljs');
2826
const path = require('path');
2927
const files = process.argv.slice(2);
@@ -139,43 +137,6 @@ if (!envIsThruthy('SKIP_INTEGRITY', false)) {
139137
// Cleanup tmp directory if any exists
140138
cleanUp();
141139

142-
/**
143-
* Check if prettier version of package.json is the same than ENV in workflow
144-
*/
145-
const packageFile = shell.cat('package.json').toString();
146-
let package = JSON.parse(packageFile);
147-
const packageVersion = package['devDependencies']['prettier'].replace(/[^0-9a-zA-Z.]/g, '');
148-
let actionFormat = () => {
149-
try {
150-
return fs.readFileSync('./.github/workflows/action-format.yml', 'utf8');
151-
} catch(err) {
152-
return err;
153-
}
154-
155-
}
156-
let verifyCodeFormatting = () => {
157-
try {
158-
return fs.readFileSync('./.github/workflows/verify-code-formatting.yml', 'utf8');
159-
} catch(err) {
160-
return err;
161-
}
162-
163-
}
164-
165-
let notMatchingFiles = [];
166-
167-
if ( !actionFormat().includes(`EXERCISM_PRETTIER_VERSION: '${packageVersion}'`)){
168-
notMatchingFiles.push('action-format.yml')
169-
}
170-
if ( !verifyCodeFormatting().includes(`EXERCISM_PRETTIER_VERSION: '${packageVersion}'`)){
171-
notMatchingFiles.push('verify-code-formatting.yml')
172-
}
173-
174-
if (notMatchingFiles.length > 0){
175-
throw new Error(`Workflow EXERCISM_PRETTIER_VERSION in file(s): ${notMatchingFiles.join(', ')} does not match pacakge.json prettier version ${packageVersion}`)
176-
}
177-
178-
179140
/**
180141
* Moves all example and test files to single directory - tmp_exercises
181142
* This allows running the test command together for all files
@@ -192,8 +153,9 @@ exercises.forEach(prepare);
192153

193154
shell.env['CLEANUP'] = true;
194155

195-
const checkResult = shell.exec(`npx babel-node ${path.join('scripts', 'lint')}`)
196-
.code;
156+
const checkResult = shell.exec(
157+
`npx babel-node ${path.join('scripts', 'lint')}`
158+
).code;
197159
if (checkResult !== 0) {
198160
shell.echo(`scripts/lint returned a non-zero exit code: ${checkResult}`);
199161
shell.exit(checkResult);

0 commit comments

Comments
 (0)