Skip to content

Commit 3dd8a78

Browse files
committed
Pre-commits + license checks + gemfile & dependencies + tool version
1 parent 3a28271 commit 3dd8a78

10 files changed

Lines changed: 434 additions & 8 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* @pennylane-hq/advanced-expenses
2+
/doc/dependency_decisions.yml @pennylane-hq/appsec

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
ruby: ['3.2', '3.3', '3.4']
16+
ruby: ["3.2", "3.3", "3.4"]
1717

1818
name: Ruby ${{ matrix.ruby }}
1919

.github/workflows/pre-commit.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Pre-commits
2+
3+
on: [push]
4+
5+
jobs:
6+
checks:
7+
name: Run pre-commit
8+
runs-on: ubuntu-20.04
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Setup Environment
14+
run: |
15+
echo "NODE_VERSION=18.18.0" >> $GITHUB_ENV
16+
echo "PYTHON_VERSION=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_ENV
17+
echo "RUBY_VERSION=$(cat .tool-versions | grep -Po '(?<=ruby ).*')" >> $GITHUB_ENV
18+
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
19+
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*\/}" >> $GITHUB_ENV
20+
21+
- name: Install Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ env.RUBY_VERSION }}
25+
26+
- name: Install Ruby dependencies
27+
run: bundle install
28+
29+
- name: Install Python
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: ${{ env.PYTHON_VERSION }}
33+
34+
- name: Store python version details for cache
35+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV"
36+
37+
- name: Pre-commit installation cache
38+
uses: actions/cache@v3
39+
with:
40+
path: ~/.cache/pre-commit
41+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
42+
restore-keys: |
43+
pre-commit|${{ env.PY }}|
44+
45+
- name: Install pre-commit
46+
run: |
47+
python -m pip install pre-commit
48+
pre-commit install --install-hooks
49+
50+
- name: Run pre-commit checks
51+
run: |
52+
pre-commit run --all-files
53+
54+
- name: Run license checks
55+
run: |
56+
pre-commit run license_checks --files doc/dependency_decisions.yml

.pre-commit-config.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: check-added-large-files
6+
- id: fix-byte-order-marker
7+
- id: check-merge-conflict
8+
- id: trailing-whitespace
9+
exclude: (?x)(
10+
\.yarn/|
11+
spec/files/)
12+
13+
- repo: https://github.com/tdeo/pre-commit-hooks
14+
rev: v4.0.1
15+
hooks:
16+
- id: end-of-file-fixer
17+
exclude: spec/files/
18+
- repo: https://github.com/shellcheck-py/shellcheck-py
19+
rev: v0.8.0.1
20+
hooks:
21+
- id: shellcheck
22+
23+
- repo: local
24+
hooks:
25+
- id: do_not_commit
26+
name: Break on DO NOT COMMIT comment
27+
language: pygrep
28+
entry: (?i)(NOT.{,3}COMMIT)
29+
exclude: (?x)(
30+
.pre-commit-config.yaml|
31+
README.md)
32+
- id: rubocop
33+
name: Rubocop
34+
language: system
35+
entry: bash -c 'bundle exec rubocop ${RUBOCOP_OPTIONS:---autocorrect} "$@"' --
36+
require_serial: true # for proper cache behavior
37+
files: (?x)(
38+
\.(rb|rake|jbuilder|gemspec)$|
39+
Gemfile$|
40+
Rakefile|
41+
.irbrc$)
42+
args:
43+
- --color
44+
- --server
45+
- --config=.rubocop.yml
46+
- --fail-level=convention
47+
- id: ruboclean
48+
name: Ruboclean
49+
language: system
50+
entry: bundle exec ruboclean
51+
files: ^\.rubocop.*\.yml$
52+
args:
53+
- --silent
54+
- --preserve-comments
55+
- id: ruby
56+
name: Valid ruby syntax
57+
language: system
58+
entry: ruby -c
59+
files: \.rb$
60+
exclude: lib/templates/rspec/
61+
- id: prettier-json
62+
name: Prettier JSON
63+
language: system
64+
entry: npx prettier --parser json --write
65+
files: \.json$
66+
- id: prettier-yaml
67+
name: Prettier YAML
68+
language: system
69+
entry: npx prettier --parser yaml --write
70+
files: \.ya?ml$
71+
exclude: ^\.rubocop\.yml
72+
- id: prettier-mdx
73+
name: Prettier MDX
74+
language: system
75+
entry: npx prettier --parser mdx --write
76+
files: \.mdx?$
77+
- id: whitespaces
78+
name: No non-breaking spaces
79+
language: pygrep
80+
entry: \\u00A0 # Non-breaking space
81+
exclude: (?x)^(
82+
\.yarn/releases/|
83+
\.pre-commit-config\.yaml)
84+
- id: license_checks
85+
name: License checks
86+
language: system
87+
entry: .pre-commit/check_license.sh
88+
files: ^doc/dependency_decisions\.yml$
89+
pass_filenames: false

.pre-commit/check_license.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
[ -z "${CI+1}" ] || exit 0
6+
7+
RESULT=$(bundle exec license_finder)
8+
9+
ERROR=$(cat <<-END
10+
11+
Some licenses are not approved! You need to run "bundle exec license_finder" to determine the missing licenses.
12+
13+
It appears the issues were the following:
14+
15+
"$RESULT"
16+
17+
Please check the licenses and especially commercial use terms, loop back to AppSec/Legal if needed.
18+
19+
Different way to approve a license, you can either accept a license kind:
20+
bundle exec license_finder permitted_licenses add "Zlib"
21+
22+
Or specific packages:
23+
bundle exec license_finder approvals add pako
24+
25+
Finally, please add the proper documentation and explanation in doc/dependency_decisions.yml
26+
27+
END
28+
)
29+
30+
if echo "$RESULT" | grep "All dependencies are approved for use"
31+
then
32+
exit 0
33+
else
34+
echo "$ERROR"
35+
exit 1
36+
fi

.rubocop.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
3+
plugins: rubocop-rspec
4+
5+
AllCops:
6+
NewCops: enable
7+
8+
Layout/LineLength:
9+
Enabled: false
10+
11+
Metrics/AbcSize:
12+
Enabled: false
13+
14+
Metrics/BlockLength:
15+
Enabled: false
16+
17+
Metrics/CyclomaticComplexity:
18+
Enabled: false
19+
20+
Metrics/MethodLength:
21+
Enabled: false
22+
23+
Metrics/PerceivedComplexity:
24+
Enabled: false
25+
26+
Style/Documentation:
27+
Enabled: false
28+
29+
RSpec/DescribeSymbol:
30+
Enabled: false
31+
32+
RSpec/MultipleExpectations:
33+
Enabled: false
34+
35+
RSpec/LeakyConstantDeclaration:
36+
Enabled: false
37+
38+
Lint/ConstantDefinitionInBlock:
39+
Enabled: false

.tool-versions

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ruby 3.2.2
2+
nodejs 24.10.0
3+
python 3.9.12

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
source 'https://rubygems.org'
22
gemspec
3+
4+
gem 'license_finder', group: :development
5+
gem 'rubocop'

0 commit comments

Comments
 (0)