diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..4264680 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,30 @@ +# +# This code is Copyright (C) The Cambridge Crystallographic Data Centre +# (CCDC) of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. +# This code may not be used, reproduced, translated, modified, disassembled or +# copied, except in accordance with a valid licence agreement with CCDC and may +# not be disclosed or redistributed in any form, either in whole or in part, to +# any third party. All copies of this code made in accordance with a valid +# licence agreement as referred to above must contain this copyright notice. +# +# No representations, warranties, or liabilities are expressed or implied in the +# supply of this code by CCDC, its servants or agents, except where such +# exclusion or limitation is prohibited, void or unenforceable under governing +# law. +# +- id: ccdc-copywrite-check + name: CCDC Copywrite header check + entry: main/hooks/copywrite_check.sh + language: python + pass_filenames: false + additional_dependencies: + - copywrite==1.1.3 + +- id: ccdc-copywrite-fix + name: CCDC Copywrite header fix + entry: main/hooks/copywrite_fix.sh + language: python + pass_filenames: false + stages: [manual] + additional_dependencies: + - copywrite==1.1.3 \ No newline at end of file diff --git a/action.yml b/action.yml index 3d7bbd1..3014725 100644 --- a/action.yml +++ b/action.yml @@ -1,3 +1,17 @@ +# +# This code is Copyright (C) 2026 The Cambridge Crystallographic Data Centre +# (CCDC) of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. +# This code may not be used, reproduced, translated, modified, disassembled or +# copied, except in accordance with a valid licence agreement with CCDC and may +# not be disclosed or redistributed in any form, either in whole or in part, to +# any third party. All copies of this code made in accordance with a valid +# licence agreement as referred to above must contain this copyright notice. +# +# No representations, warranties, or liabilities are expressed or implied in the +# supply of this code by CCDC, its servants or agents, except where such +# exclusion or limitation is prohibited, void or unenforceable under governing +# law. +# name: CCDC File Checks author: CCDC description: Check changed files for compliance @@ -8,10 +22,18 @@ inputs: runs: using: "composite" steps: - - run: python3 $GITHUB_ACTION_PATH/main.py + - name: Install copywrite + uses: hashicorp/setup-copywrite@v1.1.3 + + - name: Validate Header Compliance + run: copywrite headers --config "$GITHUB_ACTION_PATH/main/copywrite/.copywrite.hcl" --plan + shell: bash + + - name: Run file compliance check + run: python3 $GITHUB_ACTION_PATH/main.py shell: bash env: INPUT_COMMITMESSAGE: ${{ inputs.commitMessage }} branding: icon: 'check-square' - color: 'green' + color: 'green' \ No newline at end of file diff --git a/main.py b/main.py index ba28722..e7791db 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,18 @@ #!/usr/bin/env python3 +# +# This code is Copyright (C) 2026 The Cambridge Crystallographic Data Centre +# (CCDC) of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. +# This code may not be used, reproduced, translated, modified, disassembled or +# copied, except in accordance with a valid licence agreement with CCDC and may +# not be disclosed or redistributed in any form, either in whole or in part, to +# any third party. All copies of this code made in accordance with a valid +# licence agreement as referred to above must contain this copyright notice. +# +# No representations, warranties, or liabilities are expressed or implied in the +# supply of this code by CCDC, its servants or agents, except where such +# exclusion or limitation is prohibited, void or unenforceable under governing +# law. +# ''' This is a github action entry point. diff --git a/main/copywrite/.copywrite.hcl b/main/copywrite/.copywrite.hcl new file mode 100644 index 0000000..8ecea19 --- /dev/null +++ b/main/copywrite/.copywrite.hcl @@ -0,0 +1,34 @@ +schema_version = 1 + +project { + copyright_holder = "The Cambridge Crystallographic Data Centre (CCDC)" + + header_ignore = [ + ".git/**", + ".github/**", + "**/bin/**", + "**/obj/**", + "**/packages/**", + "**/node_modules/**", + "**/dist/**", + "**/build/**", + "**/.venv/**", + "**/venv/**", + "**/__pycache__/**", + "**/*.Designer.cs", + "**/*.g.cs", + "**/*.generated.*", + "**/*.min.js", + "**/*.lock", + ] +} + +rule { + paths = ["**/*.py", "**/*.sh", "**/*.bash", "**/*.yaml", "**/*.yml"] + license_header = "${COPYWRITE_HOOK_ROOT}/main/copywrite/headers/ccdc_hash.tmpl" +} + +rule { + paths = ["**/*.js", "**/*.ts", "**/*.cs", "**/*.cpp", "**/*.cxx", "**/*.cc", "**/*.h", "**/*.hpp"] + license_header = "${COPYWRITE_HOOK_ROOT}/main/copywrite/headers/ccdc_slash.tmpl" +} \ No newline at end of file diff --git a/main/copywrite/headers/ccdc_hash.tmpl b/main/copywrite/headers/ccdc_hash.tmpl new file mode 100644 index 0000000..b30619e --- /dev/null +++ b/main/copywrite/headers/ccdc_hash.tmpl @@ -0,0 +1,15 @@ +# START_LICENSE_TEXT +# This code is Copyright (C) {{ .Year }} The Cambridge Crystallographic Data Centre (CCDC) +# of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. This +# code may not be used, reproduced, translated, modified, disassembled or +# copied, except in accordance with a valid licence agreement with CCDC and +# may NOT be disclosed or redistributed in any form, either in whole or in +# part, to any third party. All copies of this code made in accordance with a +# valid licence agreement as referred to above must contain this copyright +# notice. +# +# No representations, warranties, or liabilities are expressed or implied in +# the supply of this code by CCDC, its servants or agents, except where such +# exclusion or limitation is prohibited, void or unenforceable under governing +# law. +# END_LICENSE_TEXT diff --git a/main/copywrite/headers/ccdc_slash.tmpl b/main/copywrite/headers/ccdc_slash.tmpl new file mode 100644 index 0000000..3671665 --- /dev/null +++ b/main/copywrite/headers/ccdc_slash.tmpl @@ -0,0 +1,15 @@ +// START_LICENSE_TEXT +// This code is Copyright (C) {{ .Year }} The Cambridge Crystallographic Data Centre (CCDC) +// of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. This +// code may not be used, reproduced, translated, modified, disassembled or +// copied, except in accordance with a valid licence agreement with CCDC and +// may NOT be disclosed or redistributed in any form, either in whole or in +// part, to any third party. All copies of this code made in accordance with a +// valid licence agreement as referred to above must contain this copyright +// notice. +// +// No representations, warranties, or liabilities are expressed or implied in +// the supply of this code by CCDC, its servants or agents, except where such +// exclusion or limitation is prohibited, void or unenforceable under governing +// law. +// END_LICENSE_TEXT diff --git a/main/hooks/copywrite_check.sh b/main/hooks/copywrite_check.sh new file mode 100644 index 0000000..15389bf --- /dev/null +++ b/main/hooks/copywrite_check.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# This code is Copyright (C) 2026 The Cambridge Crystallographic Data Centre +# (CCDC) of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. +# This code may not be used, reproduced, translated, modified, disassembled or +# copied, except in accordance with a valid licence agreement with CCDC and may +# not be disclosed or redistributed in any form, either in whole or in part, to +# any third party. All copies of this code made in accordance with a valid +# licence agreement as referred to above must contain this copyright notice. +# +# No representations, warranties, or liabilities are expressed or implied in the +# supply of this code by CCDC, its servants or agents, except where such +# exclusion or limitation is prohibited, void or unenforceable under governing +# law. +# +set -euo pipefail +command -v copywrite >/dev/null 2>&1 || { echo "copywrite not found on PATH"; exit 1; } + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +HOOK_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +CONFIG_PATH="${HOOK_ROOT}/main/copywrite/.copywrite.hcl" + +export COPYWRITE_HOOK_ROOT="${HOOK_ROOT}" +copywrite headers --config="${CONFIG_PATH}" --plan \ No newline at end of file diff --git a/main/hooks/copywrite_fix.sh b/main/hooks/copywrite_fix.sh new file mode 100644 index 0000000..6a76d81 --- /dev/null +++ b/main/hooks/copywrite_fix.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# This code is Copyright (C) 2026 The Cambridge Crystallographic Data Centre +# (CCDC) of 12 Union Road, Cambridge CB2 1EZ, UK and a proprietary work of CCDC. +# This code may not be used, reproduced, translated, modified, disassembled or +# copied, except in accordance with a valid licence agreement with CCDC and may +# not be disclosed or redistributed in any form, either in whole or in part, to +# any third party. All copies of this code made in accordance with a valid +# licence agreement as referred to above must contain this copyright notice. +# +# No representations, warranties, or liabilities are expressed or implied in the +# supply of this code by CCDC, its servants or agents, except where such +# exclusion or limitation is prohibited, void or unenforceable under governing +# law. +# +set -euo pipefail +command -v copywrite >/dev/null 2>&1 || { echo "copywrite not found on PATH"; exit 1; } + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +HOOK_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +CONFIG_PATH="${HOOK_ROOT}/main/copywrite/.copywrite.hcl" + +export COPYWRITE_HOOK_ROOT="${HOOK_ROOT}" +copywrite headers --config="${CONFIG_PATH}"