-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Initial code drop for Nexus upload script
Change-Id: Ifb981023af1d727af047f4673d73c03deff0b9ff Signed-off-by: Matthew Watkins <[email protected]>
- Loading branch information
1 parent
519cce0
commit 99e7b1f
Showing
4 changed files
with
303 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,5 @@ | ||
[gerrit] | ||
host=gerrit.linuxfoundation.org | ||
port=29418 | ||
project=releng/nexus-upload.git | ||
defaultbranch=main |
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,162 @@ | ||
--- | ||
ci: | ||
autofix_commit_msg: "Chore: pre-commit autoupdate" | ||
skip: | ||
# pre-commit.ci cannot install WGET, so tomlint must be disabled | ||
- tomllint | ||
|
||
exclude: | | ||
(?x)^( | ||
docs\/conf.py| | ||
dco-signoffs/$ | ||
)$ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: tomllint | ||
name: "Script: scripts/tomllint.sh" | ||
language: script | ||
# pass_filenames: false | ||
files: \^*.toml | ||
types: [file] | ||
entry: scripts/tomllint.sh . | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-ast | ||
- id: check-case-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-json | ||
- id: check-merge-conflict | ||
- id: check-shebang-scripts-are-executable | ||
- id: check-symlinks | ||
- id: check-toml | ||
# - id: detect-aws-credentials | ||
- id: check-xml | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: detect-private-key | ||
- id: end-of-file-fixer | ||
- id: mixed-line-ending | ||
args: ["--fix=lf"] | ||
- id: name-tests-test | ||
args: ["--pytest-test-first"] | ||
- id: no-commit-to-branch | ||
# - id: pretty-format-json | ||
- id: requirements-txt-fixer | ||
- id: trailing-whitespace | ||
|
||
# Autoformat: YAML, JSON, Markdown, etc. | ||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: v4.0.0-alpha.8 | ||
hooks: | ||
- id: prettier | ||
args: ["--no-error-on-unmatched-pattern", "--ignore-unknown"] | ||
|
||
# Lint: Markdown | ||
- repo: https://github.com/igorshubovych/markdownlint-cli | ||
rev: v0.40.0 | ||
hooks: | ||
- id: markdownlint | ||
args: ["--fix"] | ||
|
||
# - repo: https://github.com/psf/black-pre-commit-mirror | ||
# rev: 24.4.2 | ||
# hooks: | ||
# - id: black | ||
# - id: black-jupyter | ||
|
||
# - repo: https://github.com/tomcatling/black-nb | ||
# rev: '0.7' | ||
# hooks: | ||
# - id: black-nb | ||
|
||
- repo: https://github.com/jorisroovers/gitlint | ||
rev: v0.19.1 | ||
hooks: | ||
- id: gitlint | ||
|
||
- repo: https://github.com/openstack/bashate | ||
rev: 2.1.1 | ||
hooks: | ||
- id: bashate | ||
args: ["--ignore=E006,E011"] | ||
|
||
- repo: https://github.com/shellcheck-py/shellcheck-py | ||
rev: v0.10.0.1 | ||
hooks: | ||
- id: shellcheck | ||
|
||
- repo: https://github.com/pycqa/pydocstyle.git | ||
rev: 6.3.0 | ||
hooks: | ||
- id: pydocstyle | ||
additional_dependencies: ["tomli"] | ||
|
||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
args: ["--profile", "black"] | ||
|
||
- repo: https://github.com/Mateusz-Grzelinski/actionlint-py | ||
rev: v1.7.0.14 | ||
hooks: | ||
- id: actionlint | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: "7.0.0" | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: | ||
- pep8-naming | ||
|
||
- repo: https://github.com/adrienverge/yamllint.git | ||
rev: v1.35.1 | ||
hooks: | ||
- id: yamllint | ||
args: | ||
[ | ||
"-d", | ||
"{rules: {line-length: {max: 120}}, ignore-from-file: [.gitignore],}", | ||
] | ||
|
||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: "v1.10.0" | ||
hooks: | ||
- id: mypy | ||
verbose: true | ||
args: ["--show-error-codes", "--install-types", "--non-interactive"] | ||
additional_dependencies: ["pytest", "types-requests"] | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.4.4 | ||
hooks: | ||
- id: ruff | ||
files: ^(scripts|tests|custom_components)/.+\.py$ | ||
args: [--fix, --exit-non-zero-on-fix] | ||
- id: ruff-format | ||
files: ^(scripts|tests|custom_components)/.+\.py$ | ||
|
||
# Check for misspellings in documentation files | ||
# - repo: https://github.com/codespell-project/codespell | ||
# rev: v2.2.2 | ||
# hooks: | ||
# - id: codespell | ||
|
||
# To embrace black styles, even in docs | ||
# - repo: https://github.com/asottile/blacken-docs | ||
# rev: v1.13.0 | ||
# hooks: | ||
# - id: blacken-docs | ||
# additional_dependencies: [black] | ||
|
||
# Automatically upgrade Python syntax for newer versions | ||
# - repo: https://github.com/asottile/pyupgrade | ||
# rev: v3.15.0 | ||
# hooks: | ||
# - id: pyupgrade | ||
# args: ['--py37-plus'] |
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,135 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Uncomment to enable debugging | ||
# set -vx | ||
|
||
# Initialise variables | ||
DIRECTORY="." | ||
FILE_EXTENSION="" | ||
# Count file upload successes/failures | ||
SUCCESSES="0"; FAILURES="0" | ||
|
||
# Shared functions | ||
|
||
show_help() { | ||
# Command usage help | ||
cat << EOF | ||
Usage: ${0##*/} [-h] [-u username] [-p password] [-s upload-url] [-e match file extensions] [-d upload/content folder] | ||
-h display this help and exit | ||
-u username (or export variable NEXUS_USERNAME) | ||
-p password (or export variable NEXUS_PASSWORD) | ||
-s upload URL (or export variable NEXUS_URL) | ||
e.g. https://nexus3.o-ran-sc.org/repository/datasets/ | ||
-e file extensions to match, e.g. csv, txt | ||
-d local directory hosting files/content to be uploaded | ||
EOF | ||
} | ||
|
||
error_help() { | ||
show_help >&2 | ||
exit 1 | ||
} | ||
|
||
transfer_report() { | ||
echo "Successes: $SUCCESSES Failures: $FAILURES" | ||
if [ "$FAILURES" -gt 0 ]; then | ||
exit 1 | ||
else | ||
exit 0 | ||
fi | ||
} | ||
|
||
curl_upload() { | ||
FILE="$1" | ||
echo "Sending: ${FILE}" | ||
# echo "Running: $CURL --fail [CREDENTIALS] --upload-file $FILE $NEXUS_URL" | ||
if ("$CURL" --fail -u "$CREDENTIALS" --upload-file "$FILE" "$NEXUS_URL"); then #> /dev/null 2>&1 | ||
SUCCESSES=$((SUCCESSES+1)) | ||
else | ||
FAILURES=$((FAILURES+1)) | ||
fi | ||
} | ||
|
||
process_files() { | ||
for FILE in "${UPLOAD_FILES_ARRAY[@]}"; do | ||
curl_upload "$FILE" | ||
done | ||
} | ||
|
||
# Validate/check arguments and variables | ||
|
||
CURL=$(which curl) | ||
if [ ! -x "$CURL" ];then | ||
echo "CURL was not found in your PATH"; exit 1 | ||
fi | ||
|
||
while getopts hu:p:s:d:e: opt; do | ||
case $opt in | ||
u) NEXUS_USERNAME="$OPTARG" | ||
;; | ||
p) NEXUS_PASSWORD="$OPTARG" | ||
;; | ||
s) NEXUS_URL="$OPTARG" | ||
;; | ||
e) FILE_EXTENSION="$OPTARG" | ||
;; | ||
d) DIRECTORY="$OPTARG" | ||
if [ ! -d "$DIRECTORY" ]; then | ||
echo "Error: specified directory invalid"; exit 1 | ||
fi | ||
;; | ||
h|?) | ||
show_help | ||
exit 0 | ||
;; | ||
*) | ||
error_help | ||
esac | ||
done | ||
shift "$((OPTIND -1))" # Discard the options | ||
|
||
# Gather location of files to upload (in an array) | ||
mapfile -t UPLOAD_FILES_ARRAY < <(find "$DIRECTORY" -name "*$FILE_EXTENSION" -type f -print ) | ||
|
||
if [ "${#UPLOAD_FILES_ARRAY[@]}" -ne 0 ]; then | ||
echo "Files found to upload: ${#UPLOAD_FILES_ARRAY[@]}" | ||
# echo "Files matching pattern:" # Uncomment for debugging | ||
# echo "${UPLOAD_FILES_ARRAY[@]}" # Uncomment for debugging | ||
else | ||
echo "Error: no files found to process matching pattern" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$NEXUS_URL" ]; then | ||
echo "ERROR: Specifying the upload/repository URL is mandatory"; exit 1 | ||
else | ||
if [[ ! "$NEXUS_URL" == "http://"* ]] && \ | ||
[[ ! "$NEXUS_URL" == "https://"* ]]; then | ||
echo "Error: Nexus server must be specified as a URL"; exit 1 | ||
fi | ||
fi | ||
|
||
# Prompt for credentials if not specified explicitly or present in the shell environment | ||
if [ -z "$NEXUS_USERNAME" ]; then | ||
echo -n "Enter username: " | ||
read -r NEXUS_USERNAME | ||
if [[ -z "$NEXUS_USERNAME" ]]; then | ||
echo "ERROR: Username cannot be empty"; exit 1 | ||
fi | ||
fi | ||
if [ -z "$NEXUS_PASSWORD" ]; then | ||
echo -n "Enter password: " | ||
read -s -r NEXUS_PASSWORD # Does not echo to terminal/console | ||
echo "" | ||
if [[ -z "$NEXUS_PASSWORD" ]]; then | ||
echo "ERROR: Password cannot be empty"; exit 1 | ||
fi | ||
fi | ||
|
||
CREDENTIALS="$NEXUS_USERNAME:$NEXUS_PASSWORD" | ||
|
||
# Main script entry point | ||
|
||
echo "Uploading to: $NEXUS_URL" | ||
process_files | ||
transfer_report |