Skip to content

Commit cea5c70

Browse files
authored
chore / CLOUD-25080 / check presence of file headers (#22)
* feat: add github workflow step for linting, and a check-header script for verifying that all code files start with the right header * chore: add linting job to the tests workflow * chore: add headers to all code files * chore: add unit tests to workflow * chore: update build workflow * fix: lint
1 parent ab5efa5 commit cea5c70

32 files changed

+546
-7
lines changed

.github/workflows/_tests.yml

+26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ on:
22
workflow_call:
33

44
jobs:
5+
run_linter:
6+
name: 🧪 Lint files
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: 👓 Checkout repository
10+
uses: actions/checkout@v3
11+
12+
- uses: ./.github/actions/setup
13+
14+
- name: 📝 Execute linter
15+
run: pnpm lint:check:all
16+
517
build:
618
name: 👷 Build
719
runs-on: ubuntu-latest
@@ -12,6 +24,20 @@ jobs:
1224

1325
- run: pnpm build
1426

27+
unit_tests:
28+
name: 🧪 Unit Tests
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v3
33+
34+
- uses: ./.github/actions/setup
35+
with:
36+
run_install: true
37+
38+
- name: 🧪 start unit tests
39+
run: pnpm test:unit
40+
1541
visual_tests:
1642
name: 🎨 Visual Tests
1743
runs-on: ubuntu-latest

.github/workflows/build.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ on:
2121

2222
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
2323
jobs:
24-
# This workflow contains a single job called "build"
24+
run_linter:
25+
name: 🧪 Lint files
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: 👓 Checkout repository
29+
uses: actions/checkout@v3
30+
31+
- uses: ./.github/actions/setup
32+
33+
- name: 📝 Execute linter
34+
run: pnpm lint:check:all
35+
2536
build:
2637
# The type of runner that the job will run on
2738
runs-on: ubuntu-latest

check-headers.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
5+
// Resolve __dirname in ES module
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = path.dirname(__filename)
8+
9+
const regexToIgnore = [
10+
/^\./, // ignore all files and directories starting with '.'
11+
/__image_snapshots__/,
12+
/^(node_modules|public|docs|dist)/, // ignore common directories
13+
/^(LICENSE|HEADER)$/,
14+
/^vite\./,
15+
/^tsconfig\./,
16+
/.*\.(md|yaml|json|html|png|d\.ts|css)$/,
17+
/setup-safetest.js/,
18+
]
19+
20+
// Define the expected header
21+
const expectedHeader = `/*
22+
Copyright 2024-present HiveMQ GmbH
23+
24+
Licensed under the Apache License, Version 2.0 (the "License");
25+
you may not use this file except in compliance with the License.
26+
You may obtain a copy of the License at
27+
28+
http://www.apache.org/licenses/LICENSE-2.0
29+
30+
Unless required by applicable law or agreed to in writing, software
31+
distributed under the License is distributed on an "AS IS" BASIS,
32+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33+
See the License for the specific language governing permissions and
34+
limitations under the License.
35+
*/\n`
36+
37+
// Function to check if a file starts with the expected header
38+
function checkFileHeader(filePath) {
39+
const content = fs.readFileSync(filePath, 'utf8')
40+
if (!content.startsWith(expectedHeader)) {
41+
console.error(`File ${filePath} does not start with the expected header.`)
42+
process.exitCode = 1
43+
}
44+
}
45+
46+
const thisFile = process.argv[1].split('/').slice(-1)[0]
47+
48+
// Recursively check all files in a directory
49+
function checkDirectory(dirPath) {
50+
const files = fs.readdirSync(dirPath)
51+
for (const file of files) {
52+
const filePath = path.join(dirPath, file)
53+
const stat = fs.statSync(filePath)
54+
55+
const ignore = file === thisFile || regexToIgnore.some((regex) => regex.test(file))
56+
57+
console.log(filePath, stat.isDirectory() ? ' (d)' : '', ignore ? ' IGNORE' : '')
58+
if (!ignore) {
59+
if (stat.isDirectory()) {
60+
checkDirectory(filePath)
61+
} else {
62+
checkFileHeader(filePath)
63+
}
64+
}
65+
}
66+
}
67+
68+
// Check files in the current directory or specified directory
69+
const dirToCheck = process.argv[2] || '.'
70+
checkDirectory(path.resolve(__dirname, dirToCheck))

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"test:unit": "pnpm run --recursive --if-present test:unit",
1515
"lint:check": "biome check ./",
1616
"lint:check:write": "biome check --write --unsafe ./",
17+
"lint:headers": "node check-headers.js",
18+
"lint:check:all": "pnpm run lint:check && pnpm run lint:headers",
1719
"lint:format": "biome format ./",
1820
"lint:format:write": "biome format --write ./",
19-
"lint:all": "pnpm run lint:check && pnpm run lint:format"
21+
"lint:all": "pnpm run lint:check && pnpm run lint:headers && pnpm run lint:format"
2022
},
2123
"engines": {
2224
"node": "20",

testing/src/App.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { Box, ChakraBaseProvider, Heading } from '@chakra-ui/react'
218
import { theme } from '../../theme/src/main'
319

testing/src/components/ModePlayground.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import {
218
Accordion,
319
AccordionButton,

testing/src/main.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import App from '@/App'
218
import { ChakraProvider, ColorModeScript } from '@chakra-ui/react'
319
import React from 'react'

testing/src/views/Alerts.safetest.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { ChakraBaseProvider } from '@chakra-ui/react'
218
import { theme } from '@hivemq/ui-theme'
319
import { render } from 'safetest/react'

testing/src/views/Alerts.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import {
218
Alert,
319
AlertDescription,

testing/src/views/Buttons.safetest.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { ChakraBaseProvider } from '@chakra-ui/react'
218
import { theme } from '@hivemq/ui-theme'
319
import { render } from 'safetest/react'

testing/src/views/Buttons.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { Box, Button, HStack, Heading } from '@chakra-ui/react'
218

319
export function Buttons() {

testing/src/views/Colors.safetest.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { ChakraBaseProvider } from '@chakra-ui/react'
218
import { theme } from '@hivemq/ui-theme'
319
import { render } from 'safetest/react'

testing/src/views/Colors.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import * as colors from '@/../../theme/src/foundations/colors'
218
import { chakraTokenToCssVar } from '@/../../theme/src/utils'
319
import { HStack, Heading, Text, VStack } from '@chakra-ui/react'

testing/src/views/Headings.safetest.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { ChakraBaseProvider } from '@chakra-ui/react'
218
import { theme } from '@hivemq/ui-theme'
319
import { render } from 'safetest/react'

testing/src/views/Headings.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { Heading } from '@chakra-ui/react'
218

319
export function Headings() {

testing/src/views/Links.safetest.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024-present HiveMQ GmbH
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
import { ChakraBaseProvider } from '@chakra-ui/react'
218
import { theme } from '@hivemq/ui-theme'
319
import { render } from 'safetest/react'

0 commit comments

Comments
 (0)